Exemple #1
0
    def test_suite_construction_with_data_provider(self):
        tinc_test_loader = tinctest.TINCTestLoader()
        test_suite = tinc_test_loader.loadTestsFromName(
            'tinctest.test.test_data_provider.MockTINCTestCaseWithDataProvider'
        )
        #This should have constructed three test methods
        self.assertEquals(len(test_suite._tests), 3)
        for tinc_test in test_suite._tests:
            # The name of the generated methods for the data provider test methods should be
            # <orig_test_method_name>_key
            self.assertTrue(
                tinc_test._testMethodName == 'test_with_no_data_provider'
                or tinc_test._testMethodName == 'test_with_data_provider_type1'
                or tinc_test._testMethodName
                == 'test_with_data_provider_type2')

            if tinc_test._testMethodName == 'test_with_data_provider_type1' or \
                    tinc_test._testMethodName == 'test_with_data_provider':
                self.assertIsNotNone(tinc_test.test_data_dict)
                self.assertEquals(tinc_test._orig_testMethodName,
                                  'test_with_data_provider')

            if tinc_test._testMethodName == 'test_with_data_provider_type1':
                self.assertIsNotNone(tinc_test.test_data_dict)

            if tinc_test._testMethodName == 'test_with_data_provider_type2':
                self.assertIsNotNone(tinc_test.test_data_dict)
Exemple #2
0
 def test_user_defined_transform_metadata(self):
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromTestCase(MockSQLTemplateTestCase)
     test_case = None
     for case in test_suite._tests:
         if case.name == "MockSQLTemplateTestCase.test_user_defined_transform":
             test_case = case
    def test_restart_on_failure(self):
        test_loader = tinctest.TINCTestLoader()
        test_suite = test_loader.loadTestsFromName(
            'mpp.models.regress.mpp_tc.regress_mpp_test_case.MockMPPTestCase.test_restart_on_failure'
        )
        self.assertIsNotNone(test_suite)

        self.assertTrue(len(test_suite._tests), 1)

        for test in test_suite._tests:
            test.__class__.__unittest_skip__ = False

        with closing(_WritelnDecorator(StringIO())) as buffer:
            tinc_test_runner = tinctest.TINCTestRunner(stream=buffer,
                                                       descriptions=True,
                                                       verbosity=1)
            test_result = tinc_test_runner.run(test_suite)
            self.assertEqual(test_result.testsRun, 1)
            self.assertEqual(len(test_result.errors), 0)
            self.assertEqual(len(test_result.skipped), 0)
            self.assertEqual(len(test_result.failures), 1)

        # TODO may be add a check later on to see if we actually restart the cluster.
        expected_log_file = os.path.join(MockMPPTestCase.get_out_dir(),
                                         test._testMethodName + '.logs')
        self.assertTrue(os.path.exists(expected_log_file))
        self.assertTrue(os.path.getsize(expected_log_file) > 0)
Exemple #4
0
    def test_gpdiff_no_ans_file(self):
        """
        Test whether we throw an excpetion when there is no ans file for a sql file and if gpdiff is set to True
        """
        test_loader = tinctest.TINCTestLoader()
        test_suite = test_loader.loadTestsFromTestCase(
            MockSQLTestCaseGpdiffNoAnsFile)

        # Find our desired test case in test_suite.
        # This code is a consequence of us only having implemented
        # loadTestsFromTestCase. An implementation of loadTestsFromNames
        # would likely have allowed us to insolate test_query02 directly.
        test_case = None
        for temp in test_suite._tests:
            if temp.name == "MockSQLTestCaseGpdiffNoAnsFile.test_query_no_ans_file":
                test_case = temp
        self.assertIsNotNone(test_case)

        # As explained above, we want MockSQLTestCase to run if and only if
        # it's being invoked by our unit tests. So, it's skipped if discovered
        # directly by unit2. Here, bearing in mind that SQLTestCaseTests is itself
        # triggered by unit2, we override MockSQLTestCase's skip decorator to allow
        # this explicit construction of MockSQLTestCase to proceed.
        test_case.__class__.__unittest_skip__ = False

        test_result = unittest.TestResult()
        test_case.run(test_result)
        self.assertEqual(test_result.testsRun, 1)
        self.assertEqual(len(test_result.errors), 1)
        self.assertEqual(len(test_result.skipped), 0)
        self.assertEqual(len(test_result.failures), 0)
Exemple #5
0
    def test_run_sql_force_generate_ans_permission_denied(self):
        test_loader = tinctest.TINCTestLoader()
        test_suite = test_loader.loadTestsFromTestCase(
            MockSQLTestCaseForceGenerateAns)

        # Find our desired test case in test_suite.
        # This code is a consequence of us only having implemented
        # loadTestsFromTestCase. An implementation of loadTestsFromNames
        # would likely have allowed us to insolate test_query04 directly.
        test_case = None
        for temp in test_suite._tests:
            if temp.name == "MockSQLTestCaseForceGenerateAns.test_query04":
                # query04.ans wouldn't be checked-out from perforce, so it would have no write operation allowed
                test_case = temp
        self.assertIsNotNone(test_case)

        # As explained above, we want MockSQLTestCase to run if and only if
        # it's being invoked by our unit tests. So, it's skipped if discovered
        # directly by unit2. Here, bearing in mind that SQLTestCaseTests is itself
        # triggered by unit2, we override MockSQLTestCase's skip decorator to allow
        # this explicit construction of MockSQLTestCase to proceed.
        test_case.__class__.__unittest_skip__ = False

        test_result = unittest.TestResult()
        test_case.run(test_result)
        self.assertEqual(test_result.testsRun, 1)
        self.assertEqual(len(test_result.errors), 1)
        self.assertEqual(len(test_result.skipped), 0)
        self.assertEqual(len(test_result.failures), 0)
Exemple #6
0
    def test_run_sql_test_success(self):
        test_loader = tinctest.TINCTestLoader()
        test_suite = test_loader.loadTestsFromTestCase(MockSQLTestCase)

        # Find our desired test case in test_suite.
        # This code is a consequence of us only having implemented
        # loadTestsFromTestCase. An implementation of loadTestsFromNames
        # would likely have allowed us to insolate test_query02 directly.
        test_case = None
        for temp in test_suite._tests:
            if temp.name == "MockSQLTestCase.test_query03":
                test_case = temp
        self.assertIsNotNone(test_case)

        # As explained above, we want MockSQLTestCase to run if and only if
        # it's being invoked by our unit tests. So, it's skipped if discovered
        # directly by unit2. Here, bearing in mind that SQLTestCaseTests is itself
        # triggered by unit2, we override MockSQLTestCase's skip decorator to allow
        # this explicit construction of MockSQLTestCase to proceed.
        test_case.__class__.__unittest_skip__ = False

        test_result = unittest.TestResult()
        test_case.run(test_result)
        self.assertEqual(test_result.testsRun, 1)
        self.assertEqual(len(test_result.errors), 0)
        self.assertEqual(len(test_result.skipped), 0)
        self.assertEqual(len(test_result.failures), 0)
        shutil.rmtree(test_case.get_out_dir())
Exemple #7
0
    def test_suite_construction_with_data_provider_complicated(self):
        tinc_test_loader = tinctest.TINCTestLoader()
        test_suite = tinc_test_loader.loadTestsFromName(
            'tinctest.test.test_data_provider.MockTINCTestCaseWithDataProviderComplicated'
        )
        # There are 3 data providers with these possible values (sorted by data provider name):
        # data_types_provider: type1, type2
        # data_types_provider_dict: type6
        # data_types_provider_string: type3, type4, type5
        # A test case will be created for all combinations of the above keys:
        # type1_type6_type3, type1_type6_type4, type1_type6_type5,
        # type2_type6_type3, type2_type6_type4, type2_type6_type5,
        #This should have constructed 6 test methods
        self.assertEquals(len(test_suite._tests), 6)
        for tinc_test in test_suite._tests:
            # The name of the generated methods for the data provider test methods should be
            # <orig_test_method_name>_key
            # All the keys are sorted by their data_provider name!
            self.assertTrue(
                tinc_test._testMethodName
                == 'test_with_data_provider_complicated_type1_type6_type3'
                or tinc_test._testMethodName
                == 'test_with_data_provider_complicated_type1_type6_type4'
                or tinc_test._testMethodName
                == 'test_with_data_provider_complicated_type1_type6_type5'
                or tinc_test._testMethodName
                == 'test_with_data_provider_complicated_type2_type6_type3'
                or tinc_test._testMethodName
                == 'test_with_data_provider_complicated_type2_type6_type4'
                or tinc_test._testMethodName
                == 'test_with_data_provider_complicated_type2_type6_type5')

            self.assertIsNotNone(tinc_test.test_data_dict)
            self.assertEquals(tinc_test._orig_testMethodName,
                              'test_with_data_provider_complicated')
Exemple #8
0
 def test_matching_maintainer(self):
     loader = tinctest.TINCTestLoader()
     test_suite = loader.loadTestsFromName('tinctest.test.test_core.MockTINCTestCaseForLoaderDiscovery.test_lacking_product_version')
     filtered_test_suite = loader._filter_and_expand(test_suite, TINCDiscoveryQueryHandler(['maintainer=balasr3']))
     self.assertEquals(len(filtered_test_suite._tests), 1)
     filtered_test_suite = loader._filter_and_expand(test_suite, TINCDiscoveryQueryHandler(['maintainer=kumara64']))
     self.assertEquals(len(filtered_test_suite._tests), 0)
Exemple #9
0
 def test_with_data_provider_returning_non_dict(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     tinc_test_suite = None
     with self.assertRaises(TINCException) as cm:
         tinc_test_suite = tinc_test_loader.loadTestsFromName(
             'tinctest.test.test_data_provider.MockTINCTestCaseWithDataProviderFailure.test_with_data_provider_returning_non_dict'
         )
     self.assertIsNone(tinc_test_suite)
Exemple #10
0
    def _construct_scenario_step(self, test_case_list, fail_fast, scenario_steps):
        """
        @type test_case_list: tuple
        @param test_case_list: A tuple of list of test case names to be added to the scenario and a boolean specifying
                               whether or not to run this step serially.

        @type fail_fast: boolean
        @type fail_fast: If set to True, a step with sequential steps will terminate at the first failure
        
        Given a list of test case names, this will construct the actual list of test methods with arguments
        that will be executed concurrently for the scenario step.

        In addition, this will also populate the class level fixtures that should be executed before and after
        the execution the scenario step - namely, the setUpClass and tearDownClass fixtures for all the classes
        added to the scenario step.

        Returns a list of steps that would be constructed for a given test case list. If the test case list happens to contain
        a scenario test case , this will expand the contained scenario test case and add the resulting steps from the contained
        scenario test case
        """
        is_serial = test_case_list[1]
        scenario_step = _ScenarioStep(is_serial=is_serial, fail_fast=fail_fast)
        scenario_steps.append(scenario_step)
        
        # Construct a list of all test methods that will be executed concurrently
        for test_case in test_case_list[0]:

            # Form the test case 3-tuple (name, list of non-keyword args, dict of keyword args)
            test_case = self._construct_test_case_tuple(test_case)

            tincloader = tinctest.TINCTestLoader()
            # Load the test into the scenario
            try:
                test_suite = tincloader.loadTestsFromName(test_case[0])
            except Exception, e:
                raise ScenarioTestCaseException('Exception while loading test into the scenario - %s: %s' %(test_case[0], e))
            
            flat_test_suite = TINCTestSuite()
            self._flatten_test_suite(test_suite, flat_test_suite)
            for test in flat_test_suite:
                if isinstance(test, ScenarioTestCase):
                    # Do not add it to the step if it is a scenario test case
                    # If a contained test case is another ScenarioTestcase, then add the steps of the contained test case
                    # to the current scenario test case
                    test_scenario = self._construct_scenario_for_test(test)
                    for step in test_scenario.steps:
                        scenario_steps.append(step)
                    continue
                
                scenario_step.tests[test.name] = (test, test_case[1], test_case[2])
                # Add setup class / teardown class fixtures that should be executed for this scenario step
                full_class_name = test.__module__ + '.' + test.__class__.__name__
                setUpClass = getattr(test.__class__, 'setUpClass', None)
                tearDownClass = getattr(test.__class__, 'tearDownClass', None)
                if setUpClass and full_class_name not in scenario_step.setup_class_dict:
                    scenario_step.setup_class_dict[full_class_name] = setUpClass
                if tearDownClass and full_class_name not in  scenario_step.teardown_class_dict:
                    scenario_step.teardown_class_dict[full_class_name] = tearDownClass
Exemple #11
0
 def test_discover_multiple_folders(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     pwd = os.path.dirname(inspect.getfile(self.__class__))
     test_dir1 = os.path.join(pwd, 'folder1')
     test_dir2 = os.path.join(pwd, 'folder2')
     tinc_test_suite = tinc_test_loader.discover(start_dirs = [test_dir1, test_dir2],
                                                 patterns = ['test*', 'regress*'],
                                                 top_level_dir = None)
     self.assertEquals(len(tinc_test_suite._tests), 4)
Exemple #12
0
 def test_loading_with_decorator(self):
     """
     Test that loader does not load any tests for a test class if
     the decorator is present
     """
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromTestCase(
         MockTINCTestCaseModelWithDecorator)
     self.assertEquals(0, len(test_suite._tests))
Exemple #13
0
 def test_run_all_without_opt_mode(self):
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromTestCase(MockTestDifferentAnswerFilesWithoutOptMode)
     for tc in test_suite._tests:
         tc.__class__.__unittest_skip__ = False
         test_result = unittest.TestResult()
         tc.run(test_result)
         self.assertEqual(len(test_result.errors), 0, 'test case failed: %s' %tc)
         self.assertEqual(len(test_result.failures), 0, 'test case failed: %s' %tc)
Exemple #14
0
 def test_run_incorrect_generate_ans_file_class_variable(self):
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromTestCase(
         MockSQLTestCaseIncorrectGenerateAns)
     count = 0
     for test in test_suite._tests:
         if 'TINCTestCaseLoadFailure' in str(test):
             count += 1
     self.assertEquals(count, 1)
Exemple #15
0
 def test_loading_without_decorator(self):
     """
     Test that when a parent class has test methods and does not have
     the decorator, we load the method in the base class
     """
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromTestCase(
         MockTINCTestCaseTestsWithoutDecorator)
     self.assertEquals(2, len(test_suite._tests))
Exemple #16
0
    def test_run_sql_test_optimizer_both(self):
        test_loader = tinctest.TINCTestLoader()
        # For data provider test cases, we have to use loadTestsFromName, since loadTestsFromTestCase won't filter and expand
        test_suite = test_loader.loadTestsFromName(
            "mpp.models.regress.sql_related.regress_sql_test_case.regress_sql_test_case.MockSQLTestCaseWithOptimizerBoth"
        )

        # Find our desired test case in test_suite.
        test_case = None
        new_test_suite = tinctest.TINCTestSuite()
        for temp in test_suite._tests:
            if "MockSQLTestCaseWithOptimizerBoth.test_query03" in temp.name:
                new_test_suite.addTest(temp)
                temp.__class__.__unittest_skip__ = False
                test_case = temp

        self.assertIsNotNone(new_test_suite)
        self.assertEquals(new_test_suite.countTestCases(), 2)

        test_result = unittest.TestResult()
        new_test_suite.run(test_result)
        self.assertEqual(test_result.testsRun, 2)
        self.assertEqual(len(test_result.errors), 0)
        self.assertEqual(len(test_result.skipped), 0)
        self.assertEqual(len(test_result.failures), 0)
        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query03_planner.sql')))
        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query03_planner.out')))
        self.assertTrue(
            self._check_str_in_file(
                "SET optimizer=off;",
                os.path.join(temp.get_out_dir(), 'query03_planner.sql')))
        self.assertTrue(
            self._check_str_in_file(
                "SET optimizer=off;",
                os.path.join(test_case.get_out_dir(), 'query03_planner.out')))

        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query03_orca.sql')))
        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query03_orca.out')))
        self.assertTrue(
            self._check_str_in_file(
                "SET optimizer=on;",
                os.path.join(test_case.get_out_dir(), 'query03_orca.sql')))
        self.assertTrue(
            self._check_str_in_file(
                "SET optimizer=on;",
                os.path.join(test_case.get_out_dir(), 'query03_orca.out')))

        shutil.rmtree(test_case.get_out_dir())
Exemple #17
0
 def test_run_test_with_data_provider_no_expand(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     tinc_test_suite = tinc_test_loader.loadTestsFromName(
         'tinctest.test.test_data_provider.MockTINCTestCaseWithDataProvider.test_with_data_provider',
         expand=False)
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         # This should have run one test, since expand is False
         self.assertEquals(tinc_test_result.testsRun, 1)
Exemple #18
0
    def test_sql_test_case_with_discovery_queries(self):
        tinc_test_loader = tinctest.TINCTestLoader()
        pwd = os.path.dirname(inspect.getfile(self.__class__))
        test_dir = os.path.join(pwd, 'sql_pattern')
        tinc_test_suite = tinc_test_loader.discover(
            start_dirs=[test_dir],
            patterns=['sql_pattern.py'],
            top_level_dir=None,
            query_handler=TINCDiscoveryQueryHandler(
                ['method=test_functional_*']))

        test_case = None
        test_result = None

        with closing(_WritelnDecorator(StringIO())) as buffer:
            tinc_test_runner = TINCTestRunner(stream=buffer,
                                              descriptions=True,
                                              verbosity=1)
            test_result = tinc_test_runner.run(tinc_test_suite)
            self.assertEqual(test_result.testsRun, 6)
            self.assertEqual(len(test_result.skipped), 6)

        # Queries using metadata from sql files
        tinc_test_loader = tinctest.TINCTestLoader()
        pwd = os.path.dirname(inspect.getfile(self.__class__))
        test_dir = os.path.join(pwd, 'sql_pattern')
        tinc_test_suite = tinc_test_loader.discover(
            start_dirs=[test_dir],
            patterns=['sql_pattern.py'],
            top_level_dir=None,
            query_handler=TINCDiscoveryQueryHandler(
                ['method=test_functional_* and tags != long']))

        test_case = None
        test_result = None

        with closing(_WritelnDecorator(StringIO())) as buffer:
            tinc_test_runner = TINCTestRunner(stream=buffer,
                                              descriptions=True,
                                              verbosity=1)
            test_result = tinc_test_runner.run(tinc_test_suite)
            self.assertEqual(test_result.testsRun, 3)
            self.assertEqual(len(test_result.skipped), 3)
Exemple #19
0
 def test_run_test_with_data_provider_complicated(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     tinc_test_suite = tinc_test_loader.loadTestsFromName(
         'tinctest.test.test_data_provider.MockTINCTestCaseWithDataProviderComplicated.test_with_data_provider_complicated'
     )
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         # This should have run two tests
         self.assertEquals(tinc_test_result.testsRun, 6)
Exemple #20
0
    def test_run_sql_test_optimizer_minidump_on_failure2(self):
        """
        Test whether we gather minidumps on failures when the test is exeucted with optimizer_mode both.
        """
        test_loader = tinctest.TINCTestLoader()
        test_suite = test_loader.loadTestsFromName('mpp.models.regress.sql_related.regress_sql_test_case.' + \
                                                       'regress_sql_test_case.' + \
                                                       'MockSQLTestCaseWithOptimizerBoth.test_query02')
        self.assertIsNotNone(test_suite)
        new_test_suite = tinctest.TINCTestSuite()

        self.assertEquals(test_suite.countTestCases(), 2)

        test_result = None
        test_case = None

        for test in test_suite._tests:
            if 'test_query02_orca' in test.name:
                test.__class__.__unittest_skip__ = False
                test_case = test
                new_test_suite.addTest(test)

        self.assertIsNotNone(test_case)

        if os.path.exists(test_case.get_out_dir()):
            shutil.rmtree(test_case.get_out_dir())

        with closing(_WritelnDecorator(StringIO())) as buffer:
            tinc_test_runner = TINCTestRunner(stream=buffer,
                                              descriptions=True,
                                              verbosity=1)
            test_result = tinc_test_runner.run(new_test_suite)
            self.assertEqual(test_result.testsRun, 1)
            self.assertEqual(len(test_result.errors), 0)
            self.assertEqual(len(test_result.skipped), 0)
            self.assertEqual(len(test_result.failures), 1)

        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query02_orca.sql')))
        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query02_orca.out')))
        self.assertTrue(
            self._check_str_in_file(
                "SET optimizer=on;",
                os.path.join(test_case.get_out_dir(), 'query02_orca.sql')))
        self.assertTrue(
            self._check_str_in_file(
                "SET optimizer=on;",
                os.path.join(test_case.get_out_dir(), 'query02_orca.out')))
        # Verify that we collect minidump on failure for optimizer execution mode
        self.assertTrue(
            os.path.exists(
                os.path.join(test_case.get_out_dir(), 'query02_minidump.mdp')))
Exemple #21
0
 def test_verify_substitutions_with_templates(self):
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromTestCase(
         MockSQLTestCaseWithTemplateSubstitutions)
     for test_case in test_suite._tests:
         test_case.__class__.__unittest_skip__ = False
     test_result = unittest.TestResult()
     test_suite.run(test_result)
     self.assertEqual(test_result.testsRun, 3)
     self.assertEqual(len(test_result.errors), 0)
     self.assertEqual(len(test_result.skipped), 0)
     self.assertEqual(len(test_result.failures), 0)
 def _discover_and_run_tests(self, start_dirs, patterns, top_level_dir, query_handler):
     tinc_test_loader = tinctest.TINCTestLoader()
     tinc_test_suite = tinc_test_loader.discover(start_dirs = start_dirs,
                                                 patterns = patterns,
                                                 top_level_dir = None,
                                                 query_handler = query_handler
                                                 )
                                                 
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         return tinc_test_result
Exemple #23
0
 def test_suite_construction_with_discover(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     pwd = os.path.dirname(inspect.getfile(self.__class__))
     test_dir = os.path.join(pwd, 'data_provider')
     tinc_test_suite = tinc_test_loader.discover(start_dirs=[test_dir],
                                                 patterns=['test_*.py'],
                                                 top_level_dir=test_dir)
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         # This should have run 11 tests
         self.assertEquals(tinc_test_result.testsRun, 11)
Exemple #24
0
 def test_runner(self):
     test_loader = tinctest.TINCTestLoader()
     tinc_test_suite = test_loader.loadTestsFromName(
         'tinctest.models.concurrency.test.test_concurrency_test_case.MockConcurrencyTestCase'
     )
     for test in tinc_test_suite._tests:
         if not 'test_skip' in test.name:
             test.__class__.__unittest_skip__ = False
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_runner = TINCTestRunner(stream=buffer,
                                           descriptions=True,
                                           verbosity=1)
         tinc_test_runner.run(tinc_test_suite)
Exemple #25
0
 def test_matching_multiple_tags(self):
     loader = tinctest.TINCTestLoader()
     test_suite = loader.loadTestsFromName(
         'tinctest.test.test_core.MockTINCTestCaseForLoaderDiscovery.test_lacking_product_version'
     )
     filtered_test_suite = loader._filter_and_expand(
         test_suite,
         TINCDiscoveryQueryHandler(['tags=storage', 'tags=executor']))
     self.assertEquals(len(filtered_test_suite._tests), 1)
     filtered_test_suite = loader._filter_and_expand(
         test_suite,
         TINCDiscoveryQueryHandler(['tags=storage', 'tags=optimizer']))
     self.assertEquals(len(filtered_test_suite._tests), 0)
Exemple #26
0
    def test_scenario_with_custom_result_fail(self):
        test_loader = tinctest.TINCTestLoader()
        tinc_test_suite = test_loader.loadTestsFromName('tinctest.models.scenario.test.test_scenario_test_case.MockScenarioTestCaseWithCustomResult.test_with_custom_result_fail')
        for test in tinc_test_suite._tests:
            test.__class__.__unittest_skip__ = False
        with closing(_WritelnDecorator(StringIO())) as buffer:
            tinc_test_runner = TINCTestRunner(stream = buffer, descriptions = True, verbosity = 1)
            tinc_test_runner.run(tinc_test_suite)

        for test in tinc_test_suite._tests:
            if 'test_with_custom_result_fail' in test.name:
                self.assertEqual(test.s, 0)
                self.assertEqual(test.f, 1)
Exemple #27
0
 def test_loading_with_decorator_discover(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     pwd = os.path.dirname(inspect.getfile(self.__class__))
     test_dir = os.path.join(pwd, 'skip_loading')
     tinc_test_suite = tinc_test_loader.discover(
         start_dirs=[test_dir],
         patterns=['test_load_with_*.py'],
         top_level_dir=test_dir)
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         # This should have run 2 tests as test_01
         # would have been skipped loading at the base class with decorator
         self.assertEquals(tinc_test_result.testsRun, 2)
Exemple #28
0
 def test_load_explicit_defined_test_from_name(self):
     """
     Test loadTestsFromName for an already defined python test method
     """
     test_loader = tinctest.TINCTestLoader()
     test_suite = test_loader.loadTestsFromName('tinctest.test.test_core.MockTINCTestCaseForLoader.test_0')
     test_case = test_suite._tests[0]
     self.assertIsNotNone(test_case)
     self.assertEqual(test_case.name, 'MockTINCTestCaseForLoader.test_0')
     self.assertEqual(test_case.author, 'balasr3')
     self.assertEqual(test_case.description, 'test test case')
     self.assertEqual(test_case.created_datetime, datetime.strptime('2012-07-05 12:00:00', '%Y-%m-%d %H:%M:%S'))
     self.assertEqual(test_case.modified_datetime, datetime.strptime('2012-07-08 12:00:02', '%Y-%m-%d %H:%M:%S'))
     self.assertEqual(test_case.tags, set(['tag1', 'tag2', 'tag3']))
Exemple #29
0
 def test_discover_with_invalid_imports(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     pwd = os.path.dirname(inspect.getfile(self.__class__))
     test_dir = os.path.join(pwd, 'data_provider')
     tinc_test_suite = tinc_test_loader.discover(start_dirs = [test_dir],
                                                 patterns = ['discover_invalid_imports.py'],
                                                 top_level_dir = test_dir)
                                       
     self.assertEquals(len(tinc_test_suite._tests), 1)
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         # This should have thrown a ModuleImportFailure error
         self.assertTrue('ModuleImportFailure' in str(tinc_test_result.errors[0][0]))
Exemple #30
0
 def test_suite_construction_with_discover_and_tinc_queries(self):
     tinc_test_loader = tinctest.TINCTestLoader()
     pwd = os.path.dirname(inspect.getfile(self.__class__))
     test_dir = os.path.join(pwd, 'data_provider')
     query_handler = TINCDiscoveryQueryHandler("tags=tag1")
     tinc_test_suite = tinc_test_loader.discover(
         start_dirs=[test_dir],
         patterns=['test_*.py'],
         top_level_dir=test_dir,
         query_handler=query_handler)
     with closing(_WritelnDecorator(StringIO())) as buffer:
         tinc_test_result = tinctest.TINCTestResultSet(buffer, True, 1)
         tinc_test_suite.run(tinc_test_result)
         # This should have filtered 4 tests and hence run 7 tests
         self.assertEquals(tinc_test_result.testsRun, 7)