Python unittest.TestProgram() Examples
The following are 30
code examples of unittest.TestProgram().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unittest
, or try the search function
.
Example #1
Source File: test_program.py From Imogen with MIT License | 6 votes |
def test_defaultTest_with_iterable(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram( testRunner=runner, exit=False, defaultTest=['unittest.test', 'unittest.test2'], testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(['unittest.test', 'unittest.test2'], program.testNames)
Example #2
Source File: test_program.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
def test_defaultTest_with_iterable(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram( testRunner=runner, exit=False, defaultTest=['unittest.test', 'unittest.test2'], testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(['unittest.test', 'unittest.test2'], program.testNames)
Example #3
Source File: test_program.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
def testWarning(self): """Test the warnings argument""" # see #10535 class FakeTP(unittest.TestProgram): def parseArgs(self, *args, **kw): pass def runTests(self, *args, **kw): pass warnoptions = sys.warnoptions[:] try: sys.warnoptions[:] = [] # no warn options, no arg -> default self.assertEqual(FakeTP().warnings, 'default') # no warn options, w/ arg -> arg value self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') sys.warnoptions[:] = ['somevalue'] # warn options, no arg -> None # warn options, w/ arg -> arg value self.assertEqual(FakeTP().warnings, None) self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') finally: sys.warnoptions[:] = warnoptions
Example #4
Source File: core.py From locality-sensitive-hashing with MIT License | 6 votes |
def __init__(self, module=None, defaultTest='.', argv=None, testRunner=None, testLoader=None, env=None, config=None, suite=None, exit=True, plugins=None, addplugins=None): if env is None: env = os.environ if config is None: config = self.makeConfig(env, plugins) if addplugins: config.plugins.addPlugins(extraplugins=addplugins) self.config = config self.suite = suite self.exit = exit extra_args = {} version = sys.version_info[0:2] if version >= (2,7) and version != (3,0): extra_args['exit'] = exit unittest.TestProgram.__init__( self, module=module, defaultTest=defaultTest, argv=argv, testRunner=testRunner, testLoader=testLoader, **extra_args)
Example #5
Source File: test_program.py From jawfish with MIT License | 6 votes |
def testWarning(self): """Test the warnings argument""" # see #10535 class FakeTP(unittest.TestProgram): def parseArgs(self, *args, **kw): pass def runTests(self, *args, **kw): pass warnoptions = sys.warnoptions[:] try: sys.warnoptions[:] = [] # no warn options, no arg -> default self.assertEqual(FakeTP().warnings, 'default') # no warn options, w/ arg -> arg value self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') sys.warnoptions[:] = ['somevalue'] # warn options, no arg -> None # warn options, w/ arg -> arg value self.assertEqual(FakeTP().warnings, None) self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') finally: sys.warnoptions[:] = warnoptions
Example #6
Source File: test_program.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def testWarning(self): """Test the warnings argument""" # see #10535 class FakeTP(unittest.TestProgram): def parseArgs(self, *args, **kw): pass def runTests(self, *args, **kw): pass warnoptions = sys.warnoptions[:] try: sys.warnoptions[:] = [] # no warn options, no arg -> default self.assertEqual(FakeTP().warnings, 'default') # no warn options, w/ arg -> arg value self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') sys.warnoptions[:] = ['somevalue'] # warn options, no arg -> None # warn options, w/ arg -> arg value self.assertEqual(FakeTP().warnings, None) self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') finally: sys.warnoptions[:] = warnoptions
Example #7
Source File: test_program.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_defaultTest_with_iterable(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram( testRunner=runner, exit=False, defaultTest=['unittest.test', 'unittest.test2'], testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(['unittest.test', 'unittest.test2'], program.testNames)
Example #8
Source File: absltest.py From abseil-py with Apache License 2.0 | 6 votes |
def run_tests(argv, args, kwargs): # pylint: disable=line-too-long # type: (MutableSequence[Text], Sequence[Any], MutableMapping[Text, Any]) -> None # pylint: enable=line-too-long """Executes a set of Python unit tests. Most users should call absltest.main() instead of run_tests. Please note that run_tests should be called from app.run. Calling absltest.main() would ensure that. Please note that run_tests is allowed to make changes to kwargs. Args: argv: sys.argv with the command-line flags removed from the front, i.e. the argv with which app.run() has called __main__.main. args: Positional arguments passed through to unittest.TestProgram.__init__. kwargs: Keyword arguments passed through to unittest.TestProgram.__init__. """ result = _run_and_get_tests_result( argv, args, kwargs, xml_reporter.TextAndXMLTestRunner) sys.exit(not result.wasSuccessful())
Example #9
Source File: test_program.py From ironpython3 with Apache License 2.0 | 6 votes |
def testWarning(self): """Test the warnings argument""" # see #10535 class FakeTP(unittest.TestProgram): def parseArgs(self, *args, **kw): pass def runTests(self, *args, **kw): pass warnoptions = sys.warnoptions[:] try: sys.warnoptions[:] = [] # no warn options, no arg -> default self.assertEqual(FakeTP().warnings, 'default') # no warn options, w/ arg -> arg value self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') sys.warnoptions[:] = ['somevalue'] # warn options, no arg -> None # warn options, w/ arg -> arg value self.assertEqual(FakeTP().warnings, None) self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') finally: sys.warnoptions[:] = warnoptions
Example #10
Source File: test_program.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_defaultTest_with_iterable(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram( testRunner=runner, exit=False, defaultTest=['unittest.test', 'unittest.test2'], testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(['unittest.test', 'unittest.test2'], program.testNames)
Example #11
Source File: basetest.py From google-apputils with Apache License 2.0 | 6 votes |
def main(*args, **kwargs): # pylint: disable=g-doc-args """Executes a set of Python unit tests. Usually this function is called without arguments, so the unittest.TestProgram instance will get created with the default settings, so it will run all test methods of all TestCase classes in the __main__ module. Args: args: Positional arguments passed through to unittest.TestProgram.__init__. kwargs: Keyword arguments passed through to unittest.TestProgram.__init__. """ # pylint: enable=g-doc-args _RunInApp(RunTests, args, kwargs)
Example #12
Source File: test_program.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_defaultTest_with_iterable(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram( testRunner=runner, exit=False, defaultTest=['unittest.test', 'unittest.test2'], testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(['unittest.test', 'unittest.test2'], program.testNames)
Example #13
Source File: test_program.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def testWarning(self): """Test the warnings argument""" # see #10535 class FakeTP(unittest.TestProgram): def parseArgs(self, *args, **kw): pass def runTests(self, *args, **kw): pass warnoptions = sys.warnoptions[:] try: sys.warnoptions[:] = [] # no warn options, no arg -> default self.assertEqual(FakeTP().warnings, 'default') # no warn options, w/ arg -> arg value self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') sys.warnoptions[:] = ['somevalue'] # warn options, no arg -> None # warn options, w/ arg -> arg value self.assertEqual(FakeTP().warnings, None) self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') finally: sys.warnoptions[:] = warnoptions
Example #14
Source File: test_program.py From Imogen with MIT License | 6 votes |
def testWarning(self): """Test the warnings argument""" # see #10535 class FakeTP(unittest.TestProgram): def parseArgs(self, *args, **kw): pass def runTests(self, *args, **kw): pass warnoptions = sys.warnoptions[:] try: sys.warnoptions[:] = [] # no warn options, no arg -> default self.assertEqual(FakeTP().warnings, 'default') # no warn options, w/ arg -> arg value self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') sys.warnoptions[:] = ['somevalue'] # warn options, no arg -> None # warn options, w/ arg -> arg value self.assertEqual(FakeTP().warnings, None) self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore') finally: sys.warnoptions[:] = warnoptions
Example #15
Source File: core.py From Computable with MIT License | 6 votes |
def __init__(self, module=None, defaultTest='.', argv=None, testRunner=None, testLoader=None, env=None, config=None, suite=None, exit=True, plugins=None, addplugins=None): if env is None: env = os.environ if config is None: config = self.makeConfig(env, plugins) if addplugins: config.plugins.addPlugins(extraplugins=addplugins) self.config = config self.suite = suite self.exit = exit extra_args = {} version = sys.version_info[0:2] if version >= (2,7) and version != (3,0): extra_args['exit'] = exit unittest.TestProgram.__init__( self, module=module, defaultTest=defaultTest, argv=argv, testRunner=testRunner, testLoader=testLoader, **extra_args)
Example #16
Source File: test_program.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_defaultTest_with_string(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram(testRunner=runner, exit=False, defaultTest='unittest.test', testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(('unittest.test',), program.testNames)
Example #17
Source File: test_program.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def testNoExit(self): result = object() test = object() class FakeRunner(object): def run(self, test): self.test = test return result runner = FakeRunner() oldParseArgs = unittest.TestProgram.parseArgs def restoreParseArgs(): unittest.TestProgram.parseArgs = oldParseArgs unittest.TestProgram.parseArgs = lambda *args: None self.addCleanup(restoreParseArgs) def removeTest(): del unittest.TestProgram.test unittest.TestProgram.test = test self.addCleanup(removeTest) program = unittest.TestProgram(testRunner=runner, exit=False, verbosity=2) self.assertEqual(program.result, result) self.assertEqual(runner.test, test) self.assertEqual(program.verbosity, 2)
Example #18
Source File: test_discovery.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_command_line_handling_do_discovery_too_many_arguments(self): class Stop(Exception): pass def usageExit(): raise Stop program = object.__new__(unittest.TestProgram) program.usageExit = usageExit program.testLoader = None with self.assertRaises(Stop): # too many args program._do_discovery(['one', 'two', 'three', 'four'])
Example #19
Source File: basetest.py From google-apputils with Apache License 2.0 | 5 votes |
def runTests(self, do_run=False): """Run the tests.""" if do_run: unittest.TestProgram.runTests(self)
Example #20
Source File: HTMLTestRunner.py From seldom with Apache License 2.0 | 5 votes |
def runTests(self): # Pick HTMLTestRunner as the default test runner. # base class's testRunner parameter is not useful because it means # we have to instantiate HTMLTestRunner before we know self.verbosity. if self.testRunner is None: self.testRunner = HTMLTestRunner(verbosity=self.verbosity) unittest.TestProgram.runTests(self)
Example #21
Source File: HTMLTestRunner.py From seldom with Apache License 2.0 | 5 votes |
def _generate_ending(self): return self.ENDING_TMPL ############################################################################## # Facilities for running tests from the command line ############################################################################## # Note: Reuse unittest.TestProgram to launch test. In the future we may # build our own launcher to support more specific command line # parameters like test title, CSS, etc.
Example #22
Source File: test_discovery.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_command_line_handling_do_discovery_uses_default_loader(self): program = object.__new__(unittest.TestProgram) class Loader(object): args = [] def discover(self, start_dir, pattern, top_level_dir): self.args.append((start_dir, pattern, top_level_dir)) return 'tests' program.testLoader = Loader() program._do_discovery(['-v']) self.assertEqual(Loader.args, [('.', 'test*.py', None)])
Example #23
Source File: test_program.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testNoExit(self): result = object() test = object() class FakeRunner(object): def run(self, test): self.test = test return result runner = FakeRunner() oldParseArgs = unittest.TestProgram.parseArgs def restoreParseArgs(): unittest.TestProgram.parseArgs = oldParseArgs unittest.TestProgram.parseArgs = lambda *args: None self.addCleanup(restoreParseArgs) def removeTest(): del unittest.TestProgram.test unittest.TestProgram.test = test self.addCleanup(removeTest) program = unittest.TestProgram(testRunner=runner, exit=False, verbosity=2) self.assertEqual(program.result, result) self.assertEqual(runner.test, test) self.assertEqual(program.verbosity, 2)
Example #24
Source File: test_program.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_defaultTest_with_string(self): class FakeRunner(object): def run(self, test): self.test = test return True old_argv = sys.argv sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram(testRunner=runner, exit=False, defaultTest='unittest.test', testLoader=self.FooBarLoader()) sys.argv = old_argv self.assertEqual(('unittest.test',), program.testNames)
Example #25
Source File: test_program.py From ironpython3 with Apache License 2.0 | 5 votes |
def testNoExit(self): result = object() test = object() class FakeRunner(object): def run(self, test): self.test = test return result runner = FakeRunner() oldParseArgs = unittest.TestProgram.parseArgs def restoreParseArgs(): unittest.TestProgram.parseArgs = oldParseArgs unittest.TestProgram.parseArgs = lambda *args: None self.addCleanup(restoreParseArgs) def removeTest(): del unittest.TestProgram.test unittest.TestProgram.test = test self.addCleanup(removeTest) program = unittest.TestProgram(testRunner=runner, exit=False, verbosity=2) self.assertEqual(program.result, result) self.assertEqual(runner.test, test) self.assertEqual(program.verbosity, 2)
Example #26
Source File: test_discovery.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_command_line_handling_do_discovery_uses_default_loader(self): program = object.__new__(unittest.TestProgram) program._initArgParsers() class Loader(object): args = [] def discover(self, start_dir, pattern, top_level_dir): self.args.append((start_dir, pattern, top_level_dir)) return 'tests' program.testLoader = Loader() program._do_discovery(['-v']) self.assertEqual(Loader.args, [('.', 'test*.py', None)])
Example #27
Source File: xmlrunner.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def runTests(self): if self.testRunner is None: self.testRunner = XMLTestRunner() unittest.TestProgram.runTests(self)
Example #28
Source File: test_discovery.py From android_universal with MIT License | 5 votes |
def test_command_line_handling_do_discovery_uses_default_loader(self): program = object.__new__(unittest.TestProgram) program._initArgParsers() class Loader(object): args = [] def discover(self, start_dir, pattern, top_level_dir): self.args.append((start_dir, pattern, top_level_dir)) return 'tests' program.testLoader = Loader() program._do_discovery(['-v']) self.assertEqual(Loader.args, [('.', 'test*.py', None)])
Example #29
Source File: test_program.py From jawfish with MIT License | 5 votes |
def testNoExit(self): result = object() test = object() class FakeRunner(object): def run(self, test): self.test = test return result runner = FakeRunner() oldParseArgs = unittest.TestProgram.parseArgs def restoreParseArgs(): unittest.TestProgram.parseArgs = oldParseArgs unittest.TestProgram.parseArgs = lambda *args: None self.addCleanup(restoreParseArgs) def removeTest(): del unittest.TestProgram.test unittest.TestProgram.test = test self.addCleanup(removeTest) program = unittest.TestProgram(testRunner=runner, exit=False, verbosity=2) self.assertEqual(program.result, result) self.assertEqual(runner.test, test) self.assertEqual(program.verbosity, 2)
Example #30
Source File: test_discovery.py From datafari with Apache License 2.0 | 5 votes |
def test_command_line_handling_do_discovery_too_many_arguments(self): class Stop(Exception): pass def usageExit(): raise Stop program = object.__new__(unittest.TestProgram) program.usageExit = usageExit program.testLoader = None with self.assertRaises(Stop): # too many args program._do_discovery(['one', 'two', 'three', 'four'])