def test_checks_requires(self): dist = Distribution() cmd = test(dist) phony_project = 'ohno_ohno-impossible_1234-name_stop-that!' cmd.tests_require = [phony_project] cmd.ensure_finalized() logs = self.get_logs() self.assertIn(phony_project, logs[-1])
def test_calls_discover(self): self.safely_replace(ut1.TestLoader, "discover", delete=True) mock_ut2 = self.prepare_mock_ut2() record = [] mock_ut2.TestLoader.discover = lambda self, path: record.append(path) dist = Distribution() cmd = test(dist) cmd.run() self.assertEqual(record, [os.curdir])
def test_gets_unittest_discovery(self): mock_ut2 = self.prepare_mock_ut2() dist = Distribution() cmd = test(dist) self.safely_replace(ut1.TestLoader, "discover", lambda: None) self.assertEqual(cmd.get_ut_with_discovery(), ut1) del ut1.TestLoader.discover self.assertEqual(cmd.get_ut_with_discovery(), mock_ut2)
def test_custom_runner(self): dist = Distribution() cmd = test(dist) record = [] cmd.runner = self.prepare_named_function(lambda: record.append("runner called")) cmd.ensure_finalized() cmd.run() self.assertEqual(["runner called"], record)
def test_calls_discover(self): self.safely_replace(ut1.TestLoader, "discover", delete=True) mock_ut2 = self.prepare_mock_ut2() record = [] mock_ut2.TestLoader.discover = lambda self, path: record.append(path) dist = Distribution() cmd = test(dist) cmd.run() self.assertEqual([os.curdir], record)
def test_custom_runner(self): dist = Distribution() cmd = test(dist) record = [] cmd.runner = self.prepare_named_function( lambda: record.append("runner called")) cmd.ensure_finalized() cmd.run() self.assertEqual(["runner called"], record)
def test_checks_requires(self): dist = Distribution() cmd = test(dist) phony_project = 'ohno_ohno-impossible_1234-name_stop-that!' cmd.tests_require = [phony_project] record = [] cmd.announce = lambda *args: record.append(args) cmd.ensure_finalized() self.assertEqual(1, len(record)) self.assertIn(phony_project, record[0][0])
def test_builds_before_running_tests(self): self.addCleanup(set_command, 'distutils2.command.build.build') set_command('distutils2.tests.test_command_test.MockBuildCmd') dist = Distribution() dist.get_command_obj('build')._record = record = [] cmd = test(dist) cmd.runner = self.prepare_named_function(lambda: None) cmd.ensure_finalized() cmd.run() self.assertEqual(['build has run'], record)
def test_builds_before_running_tests(self): dist = Distribution() cmd = test(dist) cmd.runner = self.prepare_named_function(lambda: None) record = [] class MockBuildCmd(Command): build_lib = "mock build lib" def initialize_options(self): pass def finalize_options(self): pass def run(self): record.append("build run") dist.cmdclass['build'] = MockBuildCmd cmd.ensure_finalized() cmd.run() self.assertEqual(record, ['build run'])
def test_runs_unittest(self): module_name, a_module = self.prepare_a_module() record = [] a_module.recorder = lambda *args: record.append("suite") class MockTextTestRunner(object): def __init__(*_, **__): pass def run(_self, suite): record.append("run") self.safely_replace(ut1, "TextTestRunner", MockTextTestRunner) dist = Distribution() cmd = test(dist) cmd.suite = "%s.recorder" % module_name cmd.run() self.assertEqual(record, ["suite", "run"])
def test_runs_unittest(self): module_name, a_module = self.prepare_a_module() record = [] a_module.recorder = lambda *args: record.append("suite") class MockTextTestRunner: def __init__(*_, **__): pass def run(_self, suite): record.append("run") self.safely_replace(ut1, "TextTestRunner", MockTextTestRunner) dist = Distribution() cmd = test(dist) cmd.suite = "%s.recorder" % module_name cmd.run() self.assertEqual(record, ["suite", "run"])