def get_suite(module_list, test_server, test_app_client, server_information): """ This function add the tests to test suite and return modified test suite variable. :param server_information: :param module_list: test module list :type module_list: list :param test_server: server details :type test_server: dict :param test_app_client: test client :type test_app_client: pgadmin app object :return pgadmin_suite: test suite with test cases :rtype: TestSuite """ modules = [] pgadmin_suite = unit_test.TestSuite() # Get the each test module and add into list for key, klass in module_list: gen = klass modules.append(gen) # Set the test client to each module & generate the scenarios for module in modules: obj = module() obj.setApp(app) obj.setTestClient(test_app_client) obj.setTestServer(test_server) obj.setDriver(driver) obj.setServerInformation(server_information) scenario = scenarios.generate_scenarios(obj) pgadmin_suite.addTests(scenario) return pgadmin_suite
def get_suite(module_list, test_server, test_app_client): """ This function add the tests to test suite and return modified test suite variable. :param module_list: test module list :type module_list: list :param test_server: server details :type test_server: dict :param test_app_client: test client :type test_app_client: pgadmin app object :return pgadmin_suite: test suite with test cases :rtype: TestSuite """ modules = [] pgadmin_suite = unit_test.TestSuite() # Get the each test module and add into list for key, klass in module_list: gen = klass modules.append(gen) # Set the test client to each module & generate the scenarios for module in modules: obj = module() obj.setApp(app) obj.setTestClient(test_app_client) obj.setTestServer(test_server) obj.setDriver(driver) scenario = scenarios.generate_scenarios(obj) pgadmin_suite.addTests(scenario) return pgadmin_suite
def debug(self): scenarios = self._get_scenarios() if scenarios: for test in generate_scenarios(self): test.debug() else: return super(WithScenarios, self).debug()
def run(self, result=None): scenarios = self._get_scenarios() if scenarios: for test in generate_scenarios(self): test.run(result) return else: return super(WithScenarios, self).run(result)
def test_generate_scenarios_preserves_normal_test(self): class ReferenceTest(unittest.TestCase): def test_pass(self): pass test = ReferenceTest("test_pass") log = self.hook_apply_scenarios() self.assertEqual([test], list(generate_scenarios(test))) self.assertEqual([], log)
def test_all_scenarios_yielded(self): class ReferenceTest(unittest.TestCase): scenarios = [('1', {}), ('2', {})] def test_pass(self): pass test = ReferenceTest("test_pass") tests = list(generate_scenarios(test)) self.expectThat(tests[0].id(), EndsWith('ReferenceTest.test_pass(1)')) self.expectThat(tests[1].id(), EndsWith('ReferenceTest.test_pass(2)'))
def test_scenarios_attribute_cleared(self): class ReferenceTest(unittest.TestCase): scenarios = [ ('1', {'foo': 1, 'bar': 2}), ('2', {'foo': 2, 'bar': 4})] def test_check_foo(self): pass test = ReferenceTest("test_check_foo") tests = list(generate_scenarios(test)) for adapted in tests: self.assertEqual(None, adapted.scenarios)
def test_all_scenarios_yielded(self): class ReferenceTest(unittest.TestCase): scenarios = [('1', {}), ('2', {})] def test_pass(self): pass test = ReferenceTest("test_pass") tests = list(generate_scenarios(test)) self.expectThat( tests[0].id(), EndsWith('ReferenceTest.test_pass(1)')) self.expectThat( tests[1].id(), EndsWith('ReferenceTest.test_pass(2)'))
def test_tests_with_scenarios_calls_apply_scenarios(self): class ReferenceTest(unittest.TestCase): scenarios = [('demo', {})] def test_pass(self): pass test = ReferenceTest("test_pass") log = self.hook_apply_scenarios() tests = list(generate_scenarios(test)) self.expectThat( tests[0].id(), EndsWith('ReferenceTest.test_pass(demo)')) self.assertEqual([([('demo', {})], test)], log)
def test_tests_with_scenarios_calls_apply_scenarios(self): class ReferenceTest(unittest.TestCase): scenarios = [('demo', {})] def test_pass(self): pass test = ReferenceTest("test_pass") log = self.hook_apply_scenarios() tests = list(generate_scenarios(test)) self.expectThat(tests[0].id(), EndsWith('ReferenceTest.test_pass(demo)')) self.assertEqual([([('demo', {})], test)], log)
def test_all_scenarios_yielded(self): class ReferenceTest(unittest.TestCase): scenarios = [('1', {}), ('2', {})] def test_pass(self): pass test = ReferenceTest("test_pass") tests = list(generate_scenarios(test)) self.assertEqual( 'testscenarios.tests.test_scenarios.ReferenceTest.test_pass(1)', tests[0].id()) self.assertEqual( 'testscenarios.tests.test_scenarios.ReferenceTest.test_pass(2)', tests[1].id())
def test_multiple_tests(self): class Reference1(unittest.TestCase): scenarios = [('1', {}), ('2', {})] def test_something(self): pass class Reference2(unittest.TestCase): scenarios = [('3', {}), ('4', {})] def test_something(self): pass suite = unittest.TestSuite() suite.addTest(Reference1("test_something")) suite.addTest(Reference2("test_something")) tests = list(generate_scenarios(suite)) self.assertEqual(4, len(tests))
def test_scenarios_attribute_cleared(self): class ReferenceTest(unittest.TestCase): scenarios = [('1', { 'foo': 1, 'bar': 2 }), ('2', { 'foo': 2, 'bar': 4 })] def test_check_foo(self): pass test = ReferenceTest("test_check_foo") tests = list(generate_scenarios(test)) for adapted in tests: self.assertEqual(None, adapted.scenarios)
def get_suite(module_list, test_server, test_app_client, server_information, test_db_name, driver_passed, parallel_ui_test): """ This function add the tests to test suite and return modified test suite variable. :param server_information: :param module_list: test module list :type module_list: list :param test_server: server details :type test_server: dict :param test_app_client: test client :type test_app_client: pgadmin app object :return pgadmin_suite: test suite with test cases :rtype: TestSuite :param driver_passed: driver object to run selenium tests :type driver_passed: webdriver object :param parallel_ui_test: whether ui tests to be run in parallel :type parallel_ui_test: boolan :param test_db_name: database name :type test_db_name: string """ modules = [] pgadmin_suite = unittest.TestSuite() # Get the each test module and add into list for key, klass in module_list: # Separate each test class from list of classes and store in modules for item in klass: gen = item modules.append(gen) # Set the test client to each module & generate the scenarios for module in modules: obj = module() obj.setApp(app) obj.setTestClient(test_app_client) obj.setTestServer(test_server) obj.setDriver(driver_passed) obj.setParallelUI_tests(parallel_ui_test) obj.setServerInformation(server_information) obj.setTestDatabaseName(test_db_name) scenario = scenarios.generate_scenarios(obj) pgadmin_suite.addTests(scenario) return pgadmin_suite
def suite(): """ Defining test suite which will execute all the testcases present in tests directory according to set priority.""" pgadmin_suite = unittest.TestSuite() modules = [] for key, klass in TestsGeneratorRegistry.registry.items(): gen = klass modules.insert(gen.priority, gen) for m in modules: obj = m() obj.setTestClient(test_client) scenario = generate_scenarios(obj) pgadmin_suite.addTests(scenario) return pgadmin_suite
configfile = args.pop(0) configwrite = True continue print 'unknown arg: ' + arg usage() sys.exit(False) testargs.append(arg) # All global variables should be set before any test classes are loaded. # That way, verbose printing can be done at the class definition level. wttest.WiredTigerTestCase.globalSetup(preserve, timestamp, gdbSub, verbose) # Without any tests listed as arguments, do discovery if len(testargs) == 0: from discover import defaultTestLoader as loader suites = loader.discover(suitedir) suites = sorted(suites, key=lambda c: str(list(c)[0])) if configfile != None: suites = configApply(suites, configfile, configwrite) tests.addTests(generate_scenarios(suites)) else: for arg in testargs: testsFromArg(tests, loader, arg) if debug: import pdb pdb.set_trace() result = wttest.runsuite(tests) sys.exit(not result.wasSuccessful())
def addScenarioTests(tests, loader, testname): loaded = loader.loadTestsFromName(testname) tests.addTests(generate_scenarios(loaded))
configwrite = True continue print 'unknown arg: ' + arg usage() sys.exit(2) testargs.append(arg) # All global variables should be set before any test classes are loaded. # That way, verbose printing can be done at the class definition level. wttest.WiredTigerTestCase.globalSetup(preserve, timestamp, gdbSub, verbose, dirarg, longtest) # Without any tests listed as arguments, do discovery if len(testargs) == 0: from discover import defaultTestLoader as loader suites = loader.discover(suitedir) suites = sorted(suites, key=lambda c: str(list(c)[0])) if configfile != None: suites = configApply(suites, configfile, configwrite) tests.addTests(generate_scenarios(suites)) else: for arg in testargs: testsFromArg(tests, loader, arg) if debug: import pdb pdb.set_trace() result = wttest.runsuite(tests, parallel) sys.exit(0 if result.wasSuccessful() else 1)
def addScenarioTests(tests, loader, testname, scenario): loaded = loader.loadTestsFromName(testname) tests.addTests(restrictScenario(generate_scenarios(loaded), scenario))
wt_builddir, dirarg, longtest, ignoreStdout, seedw, seedz, hookmgr) # Without any tests listed as arguments, do discovery if len(testargs) == 0: if scenario != '': sys.stderr.write( 'run.py: specifying a scenario requires a test name\n') usage() sys.exit(2) from discover import defaultTestLoader as loader suites = loader.discover(suitedir) suites = sorted(suites, key=lambda c: str(list(c)[0])) if configfile != None: suites = configApply(suites, configfile, configwrite) tests.addTests(restrictScenario(generate_scenarios(suites), '')) else: for arg in testargs: testsFromArg(tests, loader, arg, scenario) tests = hookmgr.filter_tests(tests) # Shuffle the tests and create a new suite containing every Nth test from # the original suite if random_sample > 0: random_sample_tests = [] for test in tests: random_sample_tests.append(test) random.shuffle(random_sample_tests) tests = unittest.TestSuite(random_sample_tests[::random_sample]) if debug: import pdb
testargs.append(arg) # All global variables should be set before any test classes are loaded. # That way, verbose printing can be done at the class definition level. wttest.WiredTigerTestCase.globalSetup(preserve, timestamp, gdbSub, verbose, dirarg, longtest) # Without any tests listed as arguments, do discovery if len(testargs) == 0: if scenario != "": sys.stderr.write("run.py: specifying a scenario requires a test name\n") usage() sys.exit(2) from discover import defaultTestLoader as loader suites = loader.discover(suitedir) suites = sorted(suites, key=lambda c: str(list(c)[0])) if configfile != None: suites = configApply(suites, configfile, configwrite) tests.addTests(restrictScenario(generate_scenarios(suites), "")) else: for arg in testargs: testsFromArg(tests, loader, arg, scenario) if debug: import pdb pdb.set_trace() result = wttest.runsuite(tests, parallel) sys.exit(0 if result.wasSuccessful() else 1)