Exemplo n.º 1
0
 def test_NonExit(self):
     program = unittest.main(
         exit=False,
         argv=["foobar"],
         testRunner=unittest.TextTestRunner(stream=StringIO()),
         testLoader=self.FooBarLoader())
     self.assertTrue(hasattr(program, 'result'))
Exemplo n.º 2
0
 def test_NonExit(self):
     program = unittest.main(
         exit=False,
         argv=["foobar"],
         testRunner=unittest.TextTestRunner(stream=StringIO()),
         testLoader=self.FooBarLoader(),
     )
     self.assertTrue(hasattr(program, "result"))
Exemplo n.º 3
0
    def test_pickle_unpickle(self):
        # Issue #7197: a TextTestRunner should be (un)pickleable. This is
        # required by test_multiprocessing under Windows (in verbose mode).
        from StringIO import StringIO as PickleableIO
        # cStringIO objects are not pickleable, but StringIO objects are.
        stream = PickleableIO("foo")
        runner = unittest.TextTestRunner(stream)
        for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
            s = pickle.dumps(runner, protocol=protocol)
            obj = pickle.loads(s)
            # StringIO objects never compare equal, a cheap test instead.
            self.assertEqual(obj.stream.getvalue(), stream.getvalue())

    def test_resultclass(self):
        def MockResultClass(*args):
            return args
        STREAM = object()
        DESCRIPTIONS = object()
        VERBOSITY = object()
        runner = unittest.TextTestRunner(STREAM, DESCRIPTIONS, VERBOSITY,
                                         resultclass=MockResultClass)
        self.assertEqual(runner.resultclass, MockResultClass)

        expectedresult = (runner.stream, DESCRIPTIONS, VERBOSITY)
        self.assertEqual(runner._makeResult(), expectedresult)


if __name__ == '__main__':
    unittest.main()
Exemplo n.º 4
0
        tests = [Foo('test_1'), Foo('test_2')]

        loader = unittest.TestLoader()
        loader.suiteClass = list
        self.assertEqual(loader.loadTestsFromName('Foo', m), tests)

    # It is implicit in the documentation for TestLoader.suiteClass that
    # all TestLoader.loadTestsFrom* methods respect it. Let's make sure
    def test_suiteClass__loadTestsFromNames(self):
        m = types.ModuleType('m')
        class Foo(unittest.TestCase):
            def test_1(self): pass
            def test_2(self): pass
            def foo_bar(self): pass
        m.Foo = Foo

        tests = [[Foo('test_1'), Foo('test_2')]]

        loader = unittest.TestLoader()
        loader.suiteClass = list
        self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests)

    # "The default value is the TestSuite class"
    def test_suiteClass__default_value(self):
        loader = unittest.TestLoader()
        self.assertTrue(loader.suiteClass is unittest.TestSuite)


if __name__ == '__main__':
    unittest.main()
Exemplo n.º 5
0
    def testAssertIsNotNone(self):
        self.assertMessages(
            "assertIsNotNone",
            (None,),
            ["^unexpectedly None$", "^oops$", "^unexpectedly None$", "^unexpectedly None : oops$"],
        )

    def testAssertIs(self):
        self.assertMessages(
            "assertIs",
            (None, "foo"),
            ["^None is not 'foo'$", "^oops$", "^None is not 'foo'$", "^None is not 'foo' : oops$"],
        )

    def testAssertIsNot(self):
        self.assertMessages(
            "assertIsNot",
            (None, None),
            [
                "^unexpectedly identical: None$",
                "^oops$",
                "^unexpectedly identical: None$",
                "^unexpectedly identical: None : oops$",
            ],
        )


if __name__ == "__main__":
    redgreenunittest.main()
Exemplo n.º 6
0
import os
import sys
import redgreenunittest


here = os.path.dirname(__file__)
loader = redgreenunittest.defaultTestLoader

def suite():
    suite = redgreenunittest.TestSuite()
    for fn in os.listdir(here):
        if fn.startswith("test") and fn.endswith(".py"):
            modname = "redgreenunittest.test." + fn[:-3]
            __import__(modname)
            module = sys.modules[modname]
            suite.addTest(loader.loadTestsFromModule(module))
    return suite


if __name__ == "__main__":
    redgreenunittest.main(defaultTest="suite")
Exemplo n.º 7
0
        ])

    def testAssertIsNone(self):
        self.assertMessages('assertIsNone', ('not None', ), [
            "^'not None' is not None$", "^oops$", "^'not None' is not None$",
            "^'not None' is not None : oops$"
        ])

    def testAssertIsNotNone(self):
        self.assertMessages('assertIsNotNone', (None, ), [
            "^unexpectedly None$", "^oops$", "^unexpectedly None$",
            "^unexpectedly None : oops$"
        ])

    def testAssertIs(self):
        self.assertMessages('assertIs', (None, 'foo'), [
            "^None is not 'foo'$", "^oops$", "^None is not 'foo'$",
            "^None is not 'foo' : oops$"
        ])

    def testAssertIsNot(self):
        self.assertMessages('assertIsNot', (None, None), [
            "^unexpectedly identical: None$", "^oops$",
            "^unexpectedly identical: None$",
            "^unexpectedly identical: None : oops$"
        ])


if __name__ == '__main__':
    redgreenunittest.main()