def main(argv=None): parser = argparse.ArgumentParser() add_arguments(parser) args, remaining_args = parser.parse_known_args(argv) for path in args.path: if path not in sys.path: sys.path.append(path) try: import coverage from coverage.execfile import run_python_module, run_python_file except ImportError: print("Error: coverage is not available.") sys.exit(1) cov = coverage.coverage(source=args.source) cov.erase() cov.clear_exclude() if args.no_pragmas: args.pragma = [] args.pragma = args.pragma or DEFAULT_PRAGMAS if args.show: args.show_missing = True for pragma in args.show: if pragma in args.pragma: args.pragma.remove(pragma) for pragma in args.pragma: cov.exclude('pragma: %s' % pragma) ret = 0 cov.start() try: if remaining_args[0] == '-m': run_python_module(remaining_args[1], remaining_args[1:]) else: run_python_file(remaining_args[0], remaining_args) except SystemExit as e: ret = e.code cov.stop() cov.save() cov.report(show_missing=args.show_missing) return ret
def test_no_such_module(self): with self.assertRaisesRegex(NoSource, "No module named '?i_dont_exist'?"): run_python_module(["i_dont_exist"]) with self.assertRaisesRegex(NoSource, "No module named '?i'?"): run_python_module(["i.dont_exist"]) with self.assertRaisesRegex(NoSource, "No module named '?i'?"): run_python_module(["i.dont.exist"])
def test_no_such_module(self): with pytest.raises(NoSource, match="No module named '?i_dont_exist'?"): run_python_module(["i_dont_exist"]) with pytest.raises(NoSource, match="No module named '?i'?"): run_python_module(["i.dont_exist"]) with pytest.raises(NoSource, match="No module named '?i'?"): run_python_module(["i.dont.exist"])
def test_no_such_module(self): with self.assertRaises(NoSource): run_python_module("i_dont_exist", []) with self.assertRaises(NoSource): run_python_module("i.dont_exist", []) with self.assertRaises(NoSource): run_python_module("i.dont.exist", [])
def test_runmod1(self): run_python_module(["runmod1", "hello"]) out, err = self.stdouterr() assert out == "runmod1: passed hello\n" assert err == ""
def test_runmod3(self): run_python_module("pkg1.sub.runmod3", ["runmod3", "hello"]) self.assertEqual(self.stdout(), "runmod3: passed hello\n")
def test_runmod1(self): run_python_module("runmod1", ["runmod1", "hello"]) self.assertEqual(self.stdout(), "runmod1: passed hello\n")
def test_pkg1_main(self): run_python_module(["pkg1", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "pkg1.__init__: pkg1\npkg1.__main__: passed hello\n")
def test_pkg1_init(self): run_python_module(["pkg1.__init__", "wut?"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "pkg1.__init__: pkg1\npkg1.__init__: __main__\n")
def test_runmod3(self): run_python_module(["pkg1.sub.runmod3", "hello"]) assert self.stderr() == "" assert self.stdout() == "pkg1.__init__: pkg1\nrunmod3: passed hello\n"
def test_pkg1_init(self): run_python_module(["pkg1.__init__", "wut?"]) out, err = self.stdouterr() assert out == "pkg1.__init__: pkg1\npkg1.__init__: __main__\n" assert err == ""
def test_no_main(self): with pytest.raises(NoSource): run_python_module(["pkg2", "hi"])
def test_runmod2(self): run_python_module("pkg1.runmod2", ["runmod2", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "runmod2: passed hello\n")
def test_runmod2(self): run_python_module("pkg1.runmod2", ["runmod2", "hello"]) self.assertEqual(self.stdout(), "runmod2: passed hello\n")
def test_pkg1_init(self): run_python_module(["pkg1.__init__", "wut?"]) assert self.stderr() == "" assert self.stdout( ) == "pkg1.__init__: pkg1\npkg1.__init__: __main__\n"
def test_pkg1_sub_main(self): run_python_module(["pkg1.sub", "hello"]) assert self.stderr() == "" assert self.stdout( ) == "pkg1.__init__: pkg1\npkg1.sub.__main__: passed hello\n"
def test_runmod3(self): run_python_module(["pkg1.sub.runmod3", "hello"]) out, err = self.stdouterr() assert out == "pkg1.__init__: pkg1\nrunmod3: passed hello\n" assert err == ""
def test_pkg1_sub_main(self): run_python_module(["pkg1.sub", "hello"]) out, err = self.stdouterr() assert out == "pkg1.__init__: pkg1\npkg1.sub.__main__: passed hello\n" assert err == ""
def test_runmod3(self): run_python_module(["pkg1.sub.runmod3", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "pkg1.__init__: pkg1\nrunmod3: passed hello\n")
def test_runmod3(self): run_python_module("pkg1.sub.runmod3", ["runmod3", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "runmod3: passed hello\n")
def test_runmod1(self): run_python_module(["runmod1", "hello"]) assert self.stderr() == "" assert self.stdout() == "runmod1: passed hello\n"
def test_runmod2(self): run_python_module("pkg1.runmod2", ["runmod2", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "pkg1.__init__: pkg1\nrunmod2: passed hello\n")
def test_pkg1_main(self): run_python_module("pkg1", ["pkg1", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "pkg1.__main__: passed hello\n")
def test_runmod1(self): run_python_module(["runmod1", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual(self.stdout(), "runmod1: passed hello\n")
def test_no_main(self): with self.assertRaises(NoSource): run_python_module("pkg2", ["pkg2", "hi"])
def test_pkg1_sub_main(self): run_python_module(["pkg1.sub", "hello"]) self.assertEqual(self.stderr(), "") self.assertEqual( self.stdout(), "pkg1.__init__: pkg1\npkg1.sub.__main__: passed hello\n")
def test_pkg1_sub_main(self): run_python_module("pkg1.sub", ["pkg1.sub", "hello"]) self.assertEqual(self.stdout(), "pkg1.sub.__main__: passed hello\n")
def test_no_main(self): with self.assertRaises(NoSource): run_python_module(["pkg2", "hi"])