Robot Framework
randomizer.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from random import Random
17 
18 from robot.model import SuiteVisitor
19 
20 
22 
23  def __init__(self, randomize_suites=True, randomize_tests=True, seed=None):
24  self.randomize_suitesrandomize_suites = randomize_suites
25  self.randomize_testsrandomize_tests = randomize_tests
26  self.seedseed = seed
27  self._shuffle_shuffle = Random(seed).shuffle
28 
29  def start_suite(self, suite):
30  if not self.randomize_suitesrandomize_suites and not self.randomize_testsrandomize_tests:
31  return False
32  if self.randomize_suitesrandomize_suites:
33  self._shuffle_shuffle(suite.suites)
34  if self.randomize_testsrandomize_tests:
35  self._shuffle_shuffle(suite.tests)
36  if not suite.parent:
37  suite.metadata['Randomized'] = self._get_message_get_message()
38 
39  def _get_message(self):
40  possibilities = {(True, True): 'Suites and tests',
41  (True, False): 'Suites',
42  (False, True): 'Tests'}
43  randomized = (self.randomize_suitesrandomize_suites, self.randomize_testsrandomize_tests)
44  return '%s (seed %s)' % (possibilities[randomized], self.seedseed)
45 
46  def visit_test(self, test):
47  pass
48 
49  def visit_keyword(self, kw):
50  pass
Interface to ease traversing through a test suite structure.
Definition: visitor.py:85
def visit_keyword(self, kw)
Implements traversing through keywords.
Definition: randomizer.py:49
def visit_test(self, test)
Implements traversing through tests.
Definition: randomizer.py:46
def start_suite(self, suite)
Called when a suite starts.
Definition: randomizer.py:29
def __init__(self, randomize_suites=True, randomize_tests=True, seed=None)
Definition: randomizer.py:23