Exemplo n.º 1
0
def import_session(rlog, session_export):
    ssn = session.Session()
    ssn.config = session_export['config']
    ssn.hooks = RecordingPluginInterface()
    ssn.verbosity = session_export['verbosity']
    ssn.startDir = session_export['startDir']
    ssn.topLevelDir = session_export['topLevelDir']
    ssn.prepareSysPath()
    loader_ = loader.PluggableTestLoader(ssn)
    ssn.testLoader = loader_
    result_ = result.PluggableTestResult(ssn)
    ssn.testResult = result_
    runner_ = runner.PluggableTestRunner(ssn)  # needed??
    ssn.testRunner = runner_
    # load and register plugins, forcing multiprocess to the end
    ssn.plugins = [
        plugin(session=ssn) for plugin in session_export['pluginClasses']
        if plugin is not MultiProcess
    ]
    rlog.debug("Plugins loaded: %s", ssn.plugins)

    for plugin in ssn.plugins:
        plugin.register()
        rlog.debug("Registered %s in subprocess", plugin)

    # instantiating the plugin will register it.
    ssn.plugins.append(MultiProcess(session=ssn))
    rlog.debug("Registered %s in subprocess", MultiProcess)
    ssn.plugins[-1].pluginsLoaded(events.PluginsLoadedEvent(ssn.plugins))
    return ssn
Exemplo n.º 2
0
    def setUp(self):
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(session=self.session)
        self.plugin = TestCaseLoader(session=self.session)

        class Mod(object):
            pass
        self.module = Mod()

        class A(TestCase):

            def test(self):
                pass

        class B(TestCase):

            def runTest(self):
                pass

        class C(TestCase):

            def foo(self):
                pass

        class Test(object):

            def test(self):
                pass

        self.module.A = A
        self.module.B = B
        self.module.C = C
        self.module.Test = Test
Exemplo n.º 3
0
    def setUp(self):
        super(TestJunitXmlPlugin, self).setUp()
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(self.session)
        self.result = result.PluggableTestResult(self.session)
        self.plugin = junitxml.JUnitXmlReporter(session=self.session)
        self.plugin.register()

        #unittest2 needs this
        if not hasattr(self, 'assertRegexp'):
            self.assertRegex = self.assertRegexpMatches

        class Test(unittest.TestCase):
            def test(self):
                pass
            def test_fail(self):
                assert False
            def test_err(self):
                1/0
            def test_skip(self):
                raise unittest.SkipTest('skip')
            def test_bad_xml(self):
                raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_U)
            def test_bad_xml_b(self):
                raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_B)
            def test_gen(self):
                def check(a, b):
                    self.assertEqual(a, b)
                yield check, 1, 1
                yield check, 1, 2
            @tools.params(1, 2, 3)
            def test_params(self, p):
                self.assertEqual(p, 2)
        self.case = Test
Exemplo n.º 4
0
    def setUp(self):
        super(TestJunitXmlPlugin, self).setUp()
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(self.session)
        self.result = result.PluggableTestResult(self.session)
        self.plugin = junitxml.JUnitXmlReporter(session=self.session)
        self.plugin.register()

        class Test(unittest.TestCase):
            def test(self):
                pass
            def test_fail(self):
                assert False
            def test_err(self):
                1/0
            def test_skip(self):
                raise unittest.SkipTest('skip')
            def test_gen(self):
                def check(a, b):
                    self.assertEqual(a, b)
                yield check, 1, 1
                yield check, 1, 2
            @tools.params(1, 2, 3)
            def test_params(self, p):
                self.assertEqual(p, 2)
        self.case = Test
Exemplo n.º 5
0
    def setUp(self):
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(session=self.session)
        self.plugin = TestClassLoader(session=self.session)

        class Mod(object):
            pass

        self.module = Mod()

        class TestA(object):
            def test(self):
                pass

        class TestB(object):
            def runTest(self):
                pass

        class TestC(object):
            def foo(self):
                pass

        class Test(TestCase):
            def test(self):
                pass

        self.module.TestA = TestA
        self.module.TestB = TestB
        self.module.TestC = TestC
        self.module.Test = Test
Exemplo n.º 6
0
def procserver(session_export, conn):
    # init logging system
    rlog = multiprocessing.log_to_stderr()
    rlog.setLevel(session_export['logLevel'])

    # make a real session from the "session" we got
    ssn = session.Session()
    ssn.config = session_export['config']
    ssn.hooks = RecordingPluginInterface()
    ssn.verbosity = session_export['verbosity']
    ssn.startDir = session_export['startDir']
    ssn.topLevelDir = session_export['topLevelDir']
    ssn.prepareSysPath()
    loader_ = loader.PluggableTestLoader(ssn)
    ssn.testLoader = loader_
    result_ = result.PluggableTestResult(ssn)
    ssn.testResult = result_
    runner_ = runner.PluggableTestRunner(ssn)  # needed??
    ssn.testRunner = runner_
    # load and register plugins
    ssn.plugins = [
        plugin(session=ssn) for plugin in session_export['pluginClasses']
    ]
    rlog.debug("Plugins loaded: %s", ssn.plugins)
    for plugin in ssn.plugins:
        plugin.register()
        rlog.debug("Registered %s in subprocess", plugin)

    if isinstance(conn, collections.Sequence):
        conn = connection.Client(conn[:2], authkey=conn[2])

    event = SubprocessEvent(loader_, result_, runner_, ssn.plugins, conn)
    res = ssn.hooks.startSubprocess(event)
    if event.handled and not res:
        conn.send(None)
        conn.close()
        ssn.hooks.stopSubprocess(event)
        return
    # receive and run tests
    executor = event.executeTests
    for testid in gentests(conn):
        if testid is None:
            break
        # XXX to handle weird cases like layers, need to
        # deal with the case that testid is something other
        # than a simple string.
        test = event.loader.loadTestsFromName(testid)
        # xxx try/except?
        rlog.debug("Execute test %s (%s)", testid, test)
        executor(test, event.result)
        events = [e for e in ssn.hooks.flush()]
        conn.send((testid, events))
        rlog.debug("Log for %s returned", testid)
    conn.send(None)
    conn.close()
    ssn.hooks.stopSubprocess(event)
Exemplo n.º 7
0
    def setUp(self):
        super(TestJunitXmlPlugin, self).setUp()
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(self.session)
        self.result = result.PluggableTestResult(self.session)
        self.plugin = junitxml.JUnitXmlReporter(session=self.session)
        self.plugin.register()

        # Python 2.7 needs this
        # assertRegexpMatches() was renamed to assertRegex() in 3.2
        if not hasattr(self, 'assertRegex'):
            self.assertRegex = self.assertRegexpMatches

        class Test(unittest.TestCase):
            def test(self):
                pass

            def test_chdir(self):
                TEMP_SUBFOLDER = 'test_chdir'

                os.mkdir(TEMP_SUBFOLDER)
                os.chdir(TEMP_SUBFOLDER)

            def test_fail(self):
                assert False

            def test_err(self):
                1 / 0

            def test_skip(self):
                self.skipTest('skip')

            def test_skip_no_reason(self):
                self.skipTest('')

            def test_bad_xml(self):
                raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_U)

            def test_bad_xml_b(self):
                raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_B)

            def test_gen(self):
                def check(a, b):
                    self.assertEqual(a, b)

                yield check, 1, 1
                yield check, 1, 2

            @tools.params(1, 2, 3)
            def test_params(self, p):
                self.assertEqual(p, 2)

            def test_with_log(self):
                logging.info('log message')

        self.case = Test
 def setUp(self):
     self.session = session.Session()
     self.loader = loader.PluggableTestLoader(self.session)
     self.expect = [
         (0, ('call', (0, 1))),
         (1, ('call', (1, 2))),
         (2, ('call', (2, 3))),
     ]
     self.plugin = generators.Generators(session=self.session)
     # need testcase loader to make the initial response to load from module
     self.tcl = testcases.TestCaseLoader(session=self.session)
Exemplo n.º 9
0
        def _collector(self, result_):
            ssn = session.Session()
            ldr = loader.PluggableTestLoader(ssn)
            rnr = runner.PluggableTestRunner(ssn)

            ssn.loadConfigFiles('unittest.cfg', 'nose2.cfg', 'setup.cfg')
            ssn.prepareSysPath()
            ssn.loadPlugins(PluggableTestProgram.defaultPlugins)

            test = ldr.loadTestsFromNames([], None)
            rslt = rnr.run(test)
            return rslt.wasSuccessful()
Exemplo n.º 10
0
    def setUp(self):
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(session=self.session)
        self.plugin = TestClassLoader(session=self.session)

        class Mod(object):
            pass

        self.module = Mod()

        class TestA(object):
            def __init__(self):
                raise RuntimeError("Something bad happened!")

            def test(self):
                pass

        self.module.TestA = TestA
Exemplo n.º 11
0
 def setUp(self):
     self.session = session.Session()
     self.loader = loader.PluggableTestLoader(self.session)
     self.plugin = doctests.DocTestLoader(session=self.session)
     super(UnitTestDocTestLoader, self).setUp()
Exemplo n.º 12
0
 def setUp(self):
     self.session = session.Session()
     self.plug = DiscoveryLoader(session=self.session)
     self.loader = loader.PluggableTestLoader(self.session)
     self.watcher = Watcher(session=self.session)
     self.watcher.register()
Exemplo n.º 13
0
 def _get_objects(self):
     ssn = session.Session()
     ldr = loader.PluggableTestLoader(ssn)
     rnr = runner.PluggableTestRunner(ssn)
     return ssn, ldr, rnr
Exemplo n.º 14
0
 def setUp(self):
     self.session = session.Session()
     self.loader = loader.PluggableTestLoader(self.session)
Exemplo n.º 15
0
 def setUp(self):
     self.session = session.Session()
     self.loader = loader.PluggableTestLoader(session=self.session)
     self.session.testLoader = self.loader
     self.plugin = layers.Layers(session=self.session)
Exemplo n.º 16
0
 def setUp(self):
     self.session = session.Session()
     self.loader = loader.PluggableTestLoader(self.session)
     self.plugin = functions.Functions(session=self.session)
Exemplo n.º 17
0
 def setUp(self):
     self.session = session.Session()
     self.loader = loader.PluggableTestLoader(self.session)
     self.plugin = parameters.Parameters(session=self.session)
     # need testcase loader to make the initial response to load from module
     self.tcl = testcases.TestCaseLoader(session=self.session)
Exemplo n.º 18
0
    def setUp(self):
        super(TestJunitXmlPlugin, self).setUp()
        self.session = session.Session()
        self.loader = loader.PluggableTestLoader(self.session)
        self.result = result.PluggableTestResult(self.session)
        self.plugin = junitxml.JUnitXmlReporter(session=self.session)
        self.plugin.register()

        # Python 2.7 needs this
        # assertRegexpMatches() was renamed to assertRegex() in 3.2
        if not hasattr(self, "assertRegex"):
            self.assertRegex = self.assertRegexpMatches

        class Test(unittest.TestCase):
            def test(self):
                pass

            def test_chdir(self):
                TEMP_SUBFOLDER = "test_chdir"

                os.mkdir(TEMP_SUBFOLDER)
                os.chdir(TEMP_SUBFOLDER)

            def test_fail(self):
                assert False

            def test_err(self):
                1 / 0

            def test_skip(self):
                self.skipTest("skip")

            def test_skip_no_reason(self):
                self.skipTest("")

            def test_bad_xml(self):
                raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_U)

            def test_bad_xml_b(self):
                raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_B)

            def test_gen(self):
                def check(a, b):
                    # workaround:
                    # for the test which ensures that the timestamp increases between
                    # generator test runs, insert a very small sleep
                    #
                    # on py3.10 on Windows, we have observed both of these tests getting
                    # the same timestamp
                    time.sleep(0.001)
                    self.assertEqual(a, b)

                yield check, 1, 1
                yield check, 1, 2

            @tools.params(1, 2, 3)
            def test_params(self, p):
                self.assertEqual(p, 2)

            def test_with_log(self):
                logging.info("log message")

        self.case = Test