Exemple #1
0
def test_suite():
    return unittest.TestSuite([
        DocFileSuite('../doc/import.txt'),
        DocFileSuite('../doc/export.txt'),
        ])
Exemple #2
0
 def test_addTest__casesuiteclass(self):
     suite = unittest2.TestSuite()
     self.assertRaises(TypeError, suite.addTest, Test_TestSuite)
     self.assertRaises(TypeError, suite.addTest, unittest2.TestSuite)
Exemple #3
0
    def test_init__tests_optional(self):
        suite = unittest2.TestSuite()

        self.assertEqual(suite.countTestCases(), 0)
Exemple #4
0
    def test_countTestCases_simple(self):
        test1 = unittest2.FunctionTestCase(lambda: None)
        test2 = unittest2.FunctionTestCase(lambda: None)
        suite = unittest2.TestSuite((test1, test2))

        self.assertEqual(suite.countTestCases(), 2)
Exemple #5
0
class Test_TestSuite(unittest2.TestCase, EqualityMixin):

    ### Set up attributes needed by inherited tests
    ################################################################

    # Used by EqualityMixin.test_eq
    eq_pairs = [(unittest2.TestSuite(), unittest2.TestSuite()),
                (unittest2.TestSuite(), unittest2.TestSuite([])),
                (_mk_TestSuite('test_1'), _mk_TestSuite('test_1'))]

    # Used by EqualityMixin.test_ne
    ne_pairs = [(unittest2.TestSuite(), _mk_TestSuite('test_1')),
                (unittest2.TestSuite([]), _mk_TestSuite('test_1')),
                (_mk_TestSuite('test_1',
                               'test_2'), _mk_TestSuite('test_1', 'test_3')),
                (_mk_TestSuite('test_1'), _mk_TestSuite('test_2'))]

    ################################################################
    ### /Set up attributes needed by inherited tests

    ### Tests for TestSuite.__init__
    ################################################################

    # "class TestSuite([tests])"
    #
    # The tests iterable should be optional
    def test_init__tests_optional(self):
        suite = unittest2.TestSuite()

        self.assertEqual(suite.countTestCases(), 0)

    # "class TestSuite([tests])"
    # ...
    # "If tests is given, it must be an iterable of individual test cases
    # or other test suites that will be used to build the suite initially"
    #
    # TestSuite should deal with empty tests iterables by allowing the
    # creation of an empty suite
    def test_init__empty_tests(self):
        suite = unittest2.TestSuite([])

        self.assertEqual(suite.countTestCases(), 0)

    # "class TestSuite([tests])"
    # ...
    # "If tests is given, it must be an iterable of individual test cases
    # or other test suites that will be used to build the suite initially"
    #
    # TestSuite should allow any iterable to provide tests
    def test_init__tests_from_any_iterable(self):
        def tests():
            yield unittest2.FunctionTestCase(lambda: None)
            yield unittest2.FunctionTestCase(lambda: None)

        suite_1 = unittest2.TestSuite(tests())
        self.assertEqual(suite_1.countTestCases(), 2)

        suite_2 = unittest2.TestSuite(suite_1)
        self.assertEqual(suite_2.countTestCases(), 2)

        suite_3 = unittest2.TestSuite(set(suite_1))
        self.assertEqual(suite_3.countTestCases(), 2)

    # "class TestSuite([tests])"
    # ...
    # "If tests is given, it must be an iterable of individual test cases
    # or other test suites that will be used to build the suite initially"
    #
    # Does TestSuite() also allow other TestSuite() instances to be present
    # in the tests iterable?
    def test_init__TestSuite_instances_in_tests(self):
        def tests():
            ftc = unittest2.FunctionTestCase(lambda: None)
            yield unittest2.TestSuite([ftc])
            yield unittest2.FunctionTestCase(lambda: None)

        suite = unittest2.TestSuite(tests())
        self.assertEqual(suite.countTestCases(), 2)

    ################################################################
    ### /Tests for TestSuite.__init__

    # Container types should support the iter protocol
    def test_iter(self):
        test1 = unittest2.FunctionTestCase(lambda: None)
        test2 = unittest2.FunctionTestCase(lambda: None)
        suite = unittest2.TestSuite((test1, test2))

        self.assertEqual(list(suite), [test1, test2])

    # "Return the number of tests represented by the this test object.
    # ...this method is also implemented by the TestSuite class, which can
    # return larger [greater than 1] values"
    #
    # Presumably an empty TestSuite returns 0?
    def test_countTestCases_zero_simple(self):
        suite = unittest2.TestSuite()

        self.assertEqual(suite.countTestCases(), 0)

    # "Return the number of tests represented by the this test object.
    # ...this method is also implemented by the TestSuite class, which can
    # return larger [greater than 1] values"
    #
    # Presumably an empty TestSuite (even if it contains other empty
    # TestSuite instances) returns 0?
    def test_countTestCases_zero_nested(self):
        class Test1(unittest2.TestCase):
            def test(self):
                pass

        suite = unittest2.TestSuite([unittest2.TestSuite()])

        self.assertEqual(suite.countTestCases(), 0)

    # "Return the number of tests represented by the this test object.
    # ...this method is also implemented by the TestSuite class, which can
    # return larger [greater than 1] values"
    def test_countTestCases_simple(self):
        test1 = unittest2.FunctionTestCase(lambda: None)
        test2 = unittest2.FunctionTestCase(lambda: None)
        suite = unittest2.TestSuite((test1, test2))

        self.assertEqual(suite.countTestCases(), 2)

    # "Return the number of tests represented by the this test object.
    # ...this method is also implemented by the TestSuite class, which can
    # return larger [greater than 1] values"
    #
    # Make sure this holds for nested TestSuite instances, too
    def test_countTestCases_nested(self):
        class Test1(unittest2.TestCase):
            def test1(self):
                pass

            def test2(self):
                pass

        test2 = unittest2.FunctionTestCase(lambda: None)
        test3 = unittest2.FunctionTestCase(lambda: None)
        child = unittest2.TestSuite((Test1('test2'), test2))
        parent = unittest2.TestSuite((test3, child, Test1('test1')))

        self.assertEqual(parent.countTestCases(), 4)

    # "Run the tests associated with this suite, collecting the result into
    # the test result object passed as result."
    #
    # And if there are no tests? What then?
    def test_run__empty_suite(self):
        events = []
        result = LoggingResult(events)

        suite = unittest2.TestSuite()

        suite.run(result)

        self.assertEqual(events, [])

    # "Note that unlike TestCase.run(), TestSuite.run() requires the
    # "result object to be passed in."
    def test_run__requires_result(self):
        suite = unittest2.TestSuite()

        try:
            suite.run()
        except TypeError:
            pass
        else:
            self.fail("Failed to raise TypeError")

    # "Run the tests associated with this suite, collecting the result into
    # the test result object passed as result."
    def test_run(self):
        events = []
        result = LoggingResult(events)

        class LoggingCase(unittest2.TestCase):
            def run(self, result):
                events.append('run {0!s}'.format(self._testMethodName))

            def test1(self):
                pass

            def test2(self):
                pass

        tests = [LoggingCase('test1'), LoggingCase('test2')]

        unittest2.TestSuite(tests).run(result)

        self.assertEqual(events, ['run test1', 'run test2'])

    # "Add a TestCase ... to the suite"
    def test_addTest__TestCase(self):
        class Foo(unittest2.TestCase):
            def test(self):
                pass

        test = Foo('test')
        suite = unittest2.TestSuite()

        suite.addTest(test)

        self.assertEqual(suite.countTestCases(), 1)
        self.assertEqual(list(suite), [test])

    # "Add a ... TestSuite to the suite"
    def test_addTest__TestSuite(self):
        class Foo(unittest2.TestCase):
            def test(self):
                pass

        suite_2 = unittest2.TestSuite([Foo('test')])

        suite = unittest2.TestSuite()
        suite.addTest(suite_2)

        self.assertEqual(suite.countTestCases(), 1)
        self.assertEqual(list(suite), [suite_2])

    # "Add all the tests from an iterable of TestCase and TestSuite
    # instances to this test suite."
    #
    # "This is equivalent to iterating over tests, calling addTest() for
    # each element"
    def test_addTests(self):
        class Foo(unittest2.TestCase):
            def test_1(self):
                pass

            def test_2(self):
                pass

        test_1 = Foo('test_1')
        test_2 = Foo('test_2')
        inner_suite = unittest2.TestSuite([test_2])

        def gen():
            yield test_1
            yield test_2
            yield inner_suite

        suite_1 = unittest2.TestSuite()
        suite_1.addTests(gen())

        self.assertEqual(list(suite_1), list(gen()))

        # "This is equivalent to iterating over tests, calling addTest() for
        # each element"
        suite_2 = unittest2.TestSuite()
        for t in gen():
            suite_2.addTest(t)

        self.assertEqual(suite_1, suite_2)

    # "Add all the tests from an iterable of TestCase and TestSuite
    # instances to this test suite."
    #
    # What happens if it doesn't get an iterable?
    def test_addTest__noniterable(self):
        suite = unittest2.TestSuite()

        try:
            suite.addTests(5)
        except TypeError:
            pass
        else:
            self.fail("Failed to raise TypeError")

    def test_addTest__noncallable(self):
        suite = unittest2.TestSuite()
        self.assertRaises(TypeError, suite.addTest, 5)

    def test_addTest__casesuiteclass(self):
        suite = unittest2.TestSuite()
        self.assertRaises(TypeError, suite.addTest, Test_TestSuite)
        self.assertRaises(TypeError, suite.addTest, unittest2.TestSuite)

    def test_addTests__string(self):
        suite = unittest2.TestSuite()
        self.assertRaises(TypeError, suite.addTests, "foo")

    def test_function_in_suite(self):
        def f(_):
            pass

        suite = unittest2.TestSuite()
        suite.addTest(f)

        # when the bug is fixed this line will not crash
        suite.run(unittest2.TestResult())

    def test_basetestsuite(self):
        class Test(unittest2.TestCase):
            wasSetUp = False
            wasTornDown = False

            @classmethod
            def setUpClass(cls):
                cls.wasSetUp = True

            @classmethod
            def tearDownClass(cls):
                cls.wasTornDown = True

            def testPass(self):
                pass

            def testFail(self):
                fail

        class Module(object):
            wasSetUp = False
            wasTornDown = False

            @staticmethod
            def setUpModule():
                Module.wasSetUp = True

            @staticmethod
            def tearDownModule():
                Module.wasTornDown = True

        Test.__module__ = 'Module'
        sys.modules['Module'] = Module
        self.addCleanup(sys.modules.pop, 'Module')

        suite = unittest2.BaseTestSuite()
        suite.addTests([Test('testPass'), Test('testFail')])
        self.assertEqual(suite.countTestCases(), 2)

        result = unittest2.TestResult()
        suite.run(result)
        self.assertFalse(Module.wasSetUp)
        self.assertFalse(Module.wasTornDown)
        self.assertFalse(Test.wasSetUp)
        self.assertFalse(Test.wasTornDown)
        self.assertEqual(len(result.errors), 1)
        self.assertEqual(len(result.failures), 0)
        self.assertEqual(result.testsRun, 2)
Exemple #6
0
                    dylib_src, dylib_dst)
                if subprocess.call(
                        cmd, shell=True) != 0 or not os.path.isfile(dylib_dst):
                    raise Exception('command failed: "{}"'.format(cmd))
        finally:
            compile_lock.release()
            del compile_lock

        setCrashInfoHook = __setCrashInfoHook_Mac

    else:
        pass


# The test suite.
suite = unittest2.TestSuite()

# The list of categories we said we care about
categoriesList = None
# set to true if we are going to use categories for cherry-picking test cases
useCategories = False
# Categories we want to skip
skipCategories = []
# use this to track per-category failures
failuresPerCategory = {}

# The path to LLDB.framework is optional.
lldbFrameworkPath = None

# Test suite repeat count.  Can be overwritten with '-# count'.
count = 1
Exemple #7
0
    def test_iter(self):
        test1 = unittest2.FunctionTestCase(lambda: None)
        test2 = unittest2.FunctionTestCase(lambda: None)
        suite = unittest2.TestSuite((test1, test2))

        self.assertEqual(list(suite), [test1, test2])
Exemple #8
0
def suite():
    all_tests = []
    all_tests.append(unittest2.makeSuite(ChanCreationTestCase, "test"))
    all_tests.append(unittest2.makeSuite(ChanPropertyTestCase, "test"))
    all_tests.append(unittest2.makeSuite(ChanStateTestCase, "test"))
    return unittest2.TestSuite(all_tests)
Exemple #9
0
def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(SMIMETestCase))
    suite.addTest(unittest.makeSuite(WriteLoadTestCase))
    return suite
Exemple #10
0
            #(cls.srno,cls.username,cls.pid,cls.input_file,cls.logfile)
            no_of_batches= pre_process ( self.input_file,self.srno,self.username,self.pid,self.logfile )
         print(MockHelper.call_args)
         self.assertTrue(MockHelper.called)
    """def test_mock_func(self):
         with mock.patch('fpb_pre_process.mock_func') as MockHelper:
           mock_func_test(1,2)
         MockHelper.assert_called_once_with(1,2)"""
        



if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Firms Test Suite Runner')
    parser.add_argument("-r",'--runner',
                        help='Type of Runner Require(Text or Html)',
                        default='Text')
    results = parser.parse_args()
    runner=results.runner

    JsonTest = unittest2.TestLoader().loadTestsFromTestCase(ExcelToJsonAndJsonValidator)
    PreProcessTest = unittest2.TestLoader().loadTestsFromTestCase(TestPreProcess)
    suite = unittest2.TestSuite([JsonTest,PreProcessTest])

	
    if runner=='Text':
    	unittest2.TextTestRunner(verbosity=2).run(suite)
    else:
        HtmlTestRunner.HTMLTestRunner(output="Htmloutdir").run(suite)

(FiRMS-venv1) bash-4.2$ 
def test_suite():
    return unittest.TestSuite([
        DocFileSuite('integration/cart.txt'),
    ])
Exemple #12
0
def run():
    suite1 = unittest.TestLoader().loadTestsFromTestCase(TestVOFS)
    suite2 = unittest.TestLoader().loadTestsFromTestCase(TestMyIOProxy)
    suite3 = unittest.TestLoader().loadTestsFromTestCase(TestHandleWrapper)
    unittest.TestSuite([suite1, suite2, suite3])
    return unittest.TextTestRunner(verbosity=2).run(suite1)
Exemple #13
0
def runtests():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    suite.addTests(loader.loadTestsFromNames(testmodules))
    unittest.TextTestRunner(verbosity=2).run(suite)
def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestKMLDocument))
    return suite
Exemple #15
0
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(ObjectsTestCase))
    return s
Exemple #16
0
def suite():
    """Test suite for GOES netCDF reader"""
    loader = unittest.TestLoader()
    mysuite = unittest.TestSuite()
    mysuite.addTest(loader.loadTestsFromTestCase(GOESNCFileHandlerTest))
    return mysuite
Exemple #17
0
def suite():
    result = unittest.TestSuite()
    result.addTests(unittest.makeSuite(DynamicOITest))
    result.addTests(unittest.makeSuite(NewStaticOITest))
    return result
Exemple #18
0
def build_test_suite(test_classes):
    suite = unittest.TestSuite()
    for klass in test_classes:
        suite.addTest(unittest.makeSuite(klass))
    return suite
Exemple #19
0
def runAll():
    """ Unittest runner """
    suite = unittest.TestSuite()
    suite.addTest(unittest.TestLoader().loadTestsFromTestCase(BasicTestCase))

    unittest.TextTestRunner(verbosity=2).run(suite)
Exemple #20
0
            # We need to strip off the leading directory and replace the
            # directory separators with periods.
            x = full_path[len(base_path)+1:len(full_path) - 3]
            result.append('scalyr_agent.' + x.replace(os.sep, '.'))

    return result


def run_all_tests():
    """Runs all the tests containing this this directory and its children (where tests are
    contained in files ending in '_test.py'.
    """
    test_loader = unittest.defaultTestLoader
    suites = []
    error = False
    for test_case in find_all_tests():
        try:
            suites.append(test_loader.loadTestsFromName(test_case))
        except Exception, e:
            error = True
            print( "Error loading test_case '%s'.  %s, %s" % (test_case, str(e), traceback.format_exc()) )

    test_suite = unittest.TestSuite(suites)
    text_runner = unittest.TextTestRunner().run(test_suite)
    if not text_runner.wasSuccessful():
        error = True
    sys.exit(error)

if __name__ == '__main__':
    run_all_tests()
Exemple #21
0
    def test_countTestCases_zero_simple(self):
        suite = unittest2.TestSuite()

        self.assertEqual(suite.countTestCases(), 0)
            document_store = connection.get_store(store_path='/find-by-id-test-store1')
        else:
            document_store = connection.create_store(store_path='/find-by-id-test-store1')

        self.assertTrue(connection.is_store_exists('/find-by-id-test-store1'))

        condition = OJAIQueryCondition().exists_('false_field').close().build()
        doc = document_store.find_by_id('id008', condition=condition, results_as_document=True)
        self.assertEqual(doc.as_dictionary(), {})
        condition = OJAIQueryCondition().exists_('test_list').close().build()
        doc = document_store.find_by_id('id008', condition=condition, results_as_document=True,
                                        field_paths=['test_null', 'test_dict', '_id', 'test_str'])
        self.assertEqual(doc.as_dictionary(),
                         {'_id': 'id008', 'test_dict': {'test_int': 5},
                          'test_null': None, 'test_str': 'strstr'})


if __name__ == '__main__':

    test_classes_to_run = [FindByIdTest]
    loader = unittest.TestLoader()
    suites_list = []
    for test_class in test_classes_to_run:
        suite = loader.loadTestsFromTestCase(test_class)
        suites_list.append(suite)

    big_suite = unittest.TestSuite(suites_list)

    runner = unittest.TextTestRunner()
    results = runner.run(big_suite)
Exemple #23
0
def _mk_TestSuite(*names):
    return unittest2.TestSuite(Test.Foo(n) for n in names)
Exemple #24
0
        pass

    def test_virtual_pool(self):
        key = id_generator()
        val = id_generator()

        self.gamma.set('{alpha_namespace}' + key, val)
        self.gamma.set('{beta_namespace}' + key, val)

        mcval = self.alpha.get('{alpha_namespace}' + key)
        self.assertEqual(mcval, val)

        mcval = self.beta.get('{beta_namespace}' + key)
        self.assertEqual(mcval, val)

    # def test_notify(self):
    #     key = id_generator()

    #     self.mcq.delete("alpha")

    #     self.alpha.delete(key)
    #     rval = self.mcq.lpop("alpha")
    #     self.assertEqual(rval, "delete %s" % key)


if __name__ == '__main__':
    suite = unittest.TestSuite(
        [unittest.TestLoader().loadTestsFromTestCase(TestBasic)])

    unittest.TextTestRunner(verbosity=2).run(suite)
Exemple #25
0
 def test_addTest__noncallable(self):
     suite = unittest2.TestSuite()
     self.assertRaises(TypeError, suite.addTest, 5)
Exemple #26
0
def run_tests_from_names(names, buffer_test_output, xml_output, skipUntil):
    loader = unittest.TestLoader()
    suites = []
    for name in names:
        full_name = add_class_path_prefix(name)
        try:
            suite = loader.loadTestsFromName(full_name)
            suites.append(suite)
        except AttributeError as e:
            raise ImportError(
                "Could not load '" + full_name +
                "'. Please ensure the file exists and all imports (including imports in imported files) are valid."
            )

    if skipUntil == None:
        markers = [["", ""]]
    else:
        markers = map(lambda x: map(lambda y: y.strip(), x.split("-")),
                      skipUntil.split(","))

    for marker in markers:
        for i in range(0, len(marker)):
            if marker[i] != "":
                marker[i] = add_class_path_prefix(marker[i])

    if skipUntil != None:
        for marker in markers:
            if len(marker) == 1:
                print(marker[0])
            else:
                print(marker[0], "-", marker[1])

    # simulate nonlocal in python 2.x
    d = {"filtered_markers": filter(lambda marker: marker[0] == "", markers)}

    suitelist = []

    def filter_testcase(suite, marker):
        return fnmatch.fnmatch(suite.id(), marker)

    def filter_testsuite(suite):
        if isinstance(suite, unittest.TestCase):
            if len(d["filtered_markers"]) == 0:
                d["filtered_markers"] = filter(
                    lambda marker: filter_testcase(suite, marker[0]), markers)
            if len(d["filtered_markers"]) != 0:
                suitelist.append(suite)
                d["filtered_markers"] = filter(
                    lambda marker: marker[-1] == "" or not filter_testcase(
                        suite, marker[-1]), d["filtered_markers"])
        else:
            for subsuite in suite:
                filter_testsuite(subsuite)

    filter_testsuite(suites)
    super_suite = unittest.TestSuite(suitelist)

    if xml_output:
        import xmlrunner
        runner = xmlrunner.XMLTestRunner(output='test-reports', verbosity=2)
    else:
        runner = unittest.TextTestRunner(verbosity=2,
                                         failfast=True,
                                         buffer=buffer_test_output,
                                         resultclass=RegisteredTestResult)
    results = runner.run(super_suite)
    return results
Exemple #27
0
 def test_addTests__string(self):
     suite = unittest2.TestSuite()
     self.assertRaises(TypeError, suite.addTests, "foo")
Exemple #28
0
def suite():
    """Create the testsuite that has all the tests."""
    suite = unittest.TestSuite()
    for other_suite in iter_suites():
        suite.addTest(other_suite)
    return suite
Exemple #29
0
    def test_init__empty_tests(self):
        suite = unittest2.TestSuite([])

        self.assertEqual(suite.countTestCases(), 0)
Exemple #30
0
def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestSetup))
    return suite