Robot Framework Integrated Development Environment (RIDE)
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 robotide.lib.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  # Cannot use just Random(seed) due to
28  # https://ironpython.codeplex.com/workitem/35155
29  args = (seed,) if seed is not None else ()
30  self._shuffle_shuffle = Random(*args).shuffle
31 
32  def start_suite(self, suite):
33  if not self.randomize_suitesrandomize_suites and not self.randomize_testsrandomize_tests:
34  return False
35  if self.randomize_suitesrandomize_suites:
36  self._shuffle_shuffle(suite.suites)
37  if self.randomize_testsrandomize_tests:
38  self._shuffle_shuffle(suite.tests)
39  if not suite.parent:
40  suite.metadata['Randomized'] = self._get_message_get_message()
41 
42  def _get_message(self):
43  possibilities = {(True, True): 'Suites and tests',
44  (True, False): 'Suites',
45  (False, True): 'Tests'}
46  randomized = (self.randomize_suitesrandomize_suites, self.randomize_testsrandomize_tests)
47  return '%s (seed %s)' % (possibilities[randomized], self.seedseed)
48 
49  def visit_test(self, test):
50  pass
51 
52  def visit_keyword(self, kw):
53  pass
Interface to ease traversing through a test suite structure.
Definition: visitor.py:75
def visit_keyword(self, kw)
Implements traversing through the keyword and its child keywords.
Definition: randomizer.py:52
def __init__(self, randomize_suites=True, randomize_tests=True, seed=None)
Definition: randomizer.py:23
def start_suite(self, suite)
Called when suite starts.
Definition: randomizer.py:32
def visit_test(self, test)
Implements traversing through the test and its keywords.
Definition: randomizer.py:49