def test_completionFile(self): """ --completion-file causes a version string to be output """ argv = ['--completion-file'] cmdline.main(argv, testing=True) self.assertIn('shell_completion.sh', self.s.getvalue())
def test_completionFile(self): """ --completion-file causes a version string to be output """ config.sys.argv = ['', '--completion-file'] cmdline.main(testing=True) self.assertIn('shell_completion.sh', self.s.getvalue())
def run_tests(self): from green.cmdline import main main(argv=['-r', '-vv']) import coverage cov = coverage.Coverage() cov.load() cov.html_report()
def test_options(self): """ --options causes options to be output """ cmdline.sys.argv = ['', '--options'] cmdline.main(testing=True) self.assertIn('--options', self.s.getvalue()) self.assertIn('--version', self.s.getvalue())
def test_noTestsCreatesEmptyTestSuite(self): "If loadTargets doesn't find any tests, an empty test suite is created" save_TestSuite = cmdline.unittest.suite.TestSuite cmdline.unittest.suite.TestSuite = MagicMock() cmdline.sys.argv = ['', '/tmp/non-existent/path'] cmdline.main(testing=True) cmdline.unittest.suite.TestSuite.assert_called_with() cmdline.unittest.suite.TestSuite = save_TestSuite
def test_options(self): """ --options causes options to be output """ argv = ['--options'] cmdline.main(argv, testing=True) self.assertIn('--options', self.s.getvalue()) self.assertIn('--version', self.s.getvalue())
def test_version(self): """ --version causes a version string to be output """ cmdline.sys.argv = ['', '--version'] cmdline.main(testing=True) self.assertIn('Green', self.s.getvalue()) self.assertIn('Python', self.s.getvalue())
def test_noTestsCreatesEmptyTestSuite(self): """ If loadTargets doesn't find any tests, an empty test suite is created. Coverage test, since loading the module inside the main function (due to coverage handling constraints) prevents injecting a mock. """ argv = ['', '/tmp/non-existent/path'] cmdline.main(argv, testing=True)
def test_noTestsCreatesEmptyTestSuite(self): """ If loadTargets doesn't find any tests, an empty test suite is created. Coverage test, since loading the module inside the main function (due to coverage handling constraints) prevents injecting a mock. """ cmdline.sys.argv = ['', '/tmp/non-existent/path'] cmdline.main(testing=True)
def test_version(self): """ --version causes a version string to be output """ argv = ['--version'] cmdline.main(argv, testing=True) self.assertIn('Green', self.s.getvalue()) self.assertIn('Python', self.s.getvalue())
def test_completions(self): "--completions returns completions (the loader module tests deeper)" cwd = os.getcwd() path = os.path.abspath(__file__) os.chdir(os.path.dirname(os.path.dirname(os.path.dirname(path)))) config.sys.argv = ['', '--completions', 'green'] cmdline.main(testing=True) os.chdir(cwd) self.assertIn('green.test', self.s.getvalue())
def test_notTesting(self): "We actually attempt running loadTargets (coverage test)" tmpdir = tempfile.mkdtemp() cwd = os.getcwd() os.chdir(tmpdir) config.sys.argv = ['', tmpdir] cmdline.main() os.chdir(cwd) shutil.rmtree(tmpdir)
def test_coverage(self): "If coverage and --run-coverage, then coverage is started" save_coverage = config.coverage config.coverage = MagicMock() config.sys.argv = ['', '--run-coverage', '--omit-patterns=abc'] cmdline.main(testing=True, coverage_testing=True) config.coverage.coverage.assert_called_with( data_file=u'.coverage', omit=['abc']) config.coverage = save_coverage
def test_configFileDebug(self): "A debug message is output if a config file is loaded (coverage test)" tmpdir = tempfile.mkdtemp() filename = os.path.join(tmpdir, 'config') fh = open(filename, 'w') fh.write("debug = 2") fh.close() cmdline.sys.argv = ['', '-dd', '--config', filename] cmdline.main(testing=True) shutil.rmtree(tmpdir)
def test_omit_patterns(self): "Omit pattern gets parsed" save_coverage = config.coverage config.coverage = MagicMock() cov = MagicMock() config.coverage.coverage.return_value = cov config.sys.argv = ['', '--run-coverage', '--omit-patterns', 'a,b'] cmdline.main(testing=True, coverage_testing=True) self.assertEqual(cov.report.mock_calls[0][2]['omit'], ['a', 'b']) config.coverage = save_coverage
def test_completions(self): """ --completions returns completions (the loader module tests deeper) """ cwd = os.getcwd() path = os.path.abspath(__file__) os.chdir(os.path.dirname(os.path.dirname(os.path.dirname(path)))) argv = ['--completions', 'green'] cmdline.main(argv, testing=True) os.chdir(cwd) self.assertIn('green.test', self.s.getvalue())
def test_debug(self): "--debug causes the log-level to be set to debug" config.sys.argv = ['', '--debug'] saved_basicConfig = config.logging.basicConfig config.logging.basicConfig = MagicMock() cmdline.main(testing=True) config.logging.basicConfig.assert_called_with( level=logging.DEBUG, format="%(asctime)s %(levelname)9s %(message)s", datefmt="%Y-%m-%d %H:%M:%S") config.logging.basicConfig = saved_basicConfig
def test_configFileDebug(self): """ A debug message is output if a config file is loaded (coverage test) """ tmpdir = tempfile.mkdtemp() filename = os.path.join(tmpdir, 'config') fh = open(filename, 'w') fh.write("debug = 2") fh.close() argv = ['-dd', '--config', filename] cmdline.main(argv, testing=True) shutil.rmtree(tmpdir)
def test_notTesting(self): """ We actually attempt running loadTargets (coverage test) """ tmpdir = tempfile.mkdtemp() cwd = os.getcwd() os.chdir(tmpdir) sys.path.insert(0, cwd) argv = [tmpdir] cmdline.main(argv) os.chdir(cwd) del (sys.path[0]) shutil.rmtree(tmpdir)
def test_generate_junit_test_report(self): """ Test that a report is generated when we use the '--junit-report' option. """ tmpdir = tempfile.mkdtemp() report = join(tmpdir, "test_report.xml") self.assertFalse(isfile(report)) argv = ["--junit-report", report] cmdline.main(argv, testing=True) self.assertTrue(isfile(report)) shutil.rmtree(tmpdir)
def test_debug(self): """ --debug causes the log-level to be set to debug """ config.sys.argv = ['', '--debug'] saved_basicConfig = config.logging.basicConfig self.addCleanup(setattr, config.logging, 'basicConfig', saved_basicConfig) config.logging.basicConfig = MagicMock() cmdline.main(testing=True) config.logging.basicConfig.assert_called_with( level=logging.DEBUG, format="%(asctime)s %(levelname)9s %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
def test_noCoverage(self): "The absence of coverage prompts a return code of 3" save_stdout = config.sys.stdout config.sys.stdout = MagicMock() save_coverage = config.coverage config.coverage = None config.sys.argv = ['', '--run-coverage'] self.assertEqual(cmdline.main(), 3) config.coverage = save_coverage config.sys.stdout = save_stdout
def test_noCoverage(self): """ The absence of coverage prompts a return code of 3 """ save_stdout = config.sys.stdout config.sys.stdout = MagicMock() save_coverage = config.coverage config.coverage = None config.sys.argv = ['', '--run-coverage'] self.assertEqual(cmdline.main(), 3) config.coverage = save_coverage config.sys.stdout = save_stdout
def run(self): self.ensure_finalized() if self.distribution.install_requires: self.distribution.fetch_build_eggs(self.distribution.install_requires) if self.distribution.tests_require: self.distribution.fetch_build_eggs(self.distribution.tests_require) script_args = self.distribution.script_args[1:] if self.distribution.test_suite is not None: script_args.append(self.distribution.test_suite) error_code = main(script_args) if error_code: sys.exit(error_code)
def run(self): self.ensure_finalized() if self.distribution.install_requires: self.distribution.fetch_build_eggs( self.distribution.install_requires) if self.distribution.tests_require: self.distribution.fetch_build_eggs( self.distribution.tests_require) script_args = self.distribution.script_args[1:] if self.distribution.test_suite is not None: script_args.append(self.distribution.test_suite) error_code = main(script_args) if error_code: sys.exit(error_code)
def test_disableWindowsSupport(self): """ --disable-windows """ argv = ['--disable-windows'] cmdline.main(argv, testing=True)
def test_disableWindowsSupport(self): """ --disable-windows """ cmdline.sys.argv = ['', '--disable-windows'] cmdline.main(testing=True)
def test_disableTermcolor(self): """ --notermcolor causes coverage of the line disabling termcolor """ argv = ['--notermcolor'] cmdline.main(argv, testing=True)
def test_disableTermcolor(self): """ --notermcolor causes coverage of the line disabling termcolor """ cmdline.sys.argv = ['', '--notermcolor'] cmdline.main(testing=True)