示例#1
0
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
示例#2
0
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
示例#3
0
 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"])
示例#4
0
 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"])
示例#5
0
 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", [])
示例#6
0
 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", [])
示例#7
0
 def test_runmod1(self):
     run_python_module(["runmod1", "hello"])
     out, err = self.stdouterr()
     assert out == "runmod1: passed hello\n"
     assert err == ""
示例#8
0
 def test_runmod3(self):
     run_python_module("pkg1.sub.runmod3", ["runmod3", "hello"])
     self.assertEqual(self.stdout(), "runmod3: passed hello\n")
示例#9
0
 def test_runmod1(self):
     run_python_module("runmod1", ["runmod1", "hello"])
     self.assertEqual(self.stdout(), "runmod1: passed hello\n")
示例#10
0
 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")
示例#11
0
 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")
示例#12
0
 def test_runmod3(self):
     run_python_module(["pkg1.sub.runmod3", "hello"])
     assert self.stderr() == ""
     assert self.stdout() == "pkg1.__init__: pkg1\nrunmod3: passed hello\n"
示例#13
0
 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 == ""
示例#14
0
 def test_no_main(self):
     with pytest.raises(NoSource):
         run_python_module(["pkg2", "hi"])
示例#15
0
 def test_runmod2(self):
     run_python_module("pkg1.runmod2", ["runmod2", "hello"])
     self.assertEqual(self.stderr(), "")
     self.assertEqual(self.stdout(), "runmod2: passed hello\n")
示例#16
0
 def test_runmod2(self):
     run_python_module("pkg1.runmod2", ["runmod2", "hello"])
     self.assertEqual(self.stdout(), "runmod2: passed hello\n")
示例#17
0
 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")
示例#18
0
 def test_pkg1_init(self):
     run_python_module(["pkg1.__init__", "wut?"])
     assert self.stderr() == ""
     assert self.stdout(
     ) == "pkg1.__init__: pkg1\npkg1.__init__: __main__\n"
示例#19
0
 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"
示例#20
0
 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 == ""
示例#21
0
 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 == ""
示例#22
0
 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")
示例#23
0
 def test_runmod3(self):
     run_python_module("pkg1.sub.runmod3", ["runmod3", "hello"])
     self.assertEqual(self.stderr(), "")
     self.assertEqual(self.stdout(), "runmod3: passed hello\n")
示例#24
0
 def test_runmod1(self):
     run_python_module(["runmod1", "hello"])
     assert self.stderr() == ""
     assert self.stdout() == "runmod1: passed hello\n"
示例#25
0
 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")
示例#26
0
 def test_pkg1_main(self):
     run_python_module("pkg1", ["pkg1", "hello"])
     self.assertEqual(self.stderr(), "")
     self.assertEqual(self.stdout(), "pkg1.__main__: passed hello\n")
示例#27
0
 def test_runmod1(self):
     run_python_module(["runmod1", "hello"])
     self.assertEqual(self.stderr(), "")
     self.assertEqual(self.stdout(), "runmod1: passed hello\n")
示例#28
0
 def test_no_main(self):
     with self.assertRaises(NoSource):
         run_python_module("pkg2", ["pkg2", "hi"])
示例#29
0
 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")
示例#30
0
 def test_pkg1_sub_main(self):
     run_python_module("pkg1.sub", ["pkg1.sub", "hello"])
     self.assertEqual(self.stdout(), "pkg1.sub.__main__: passed hello\n")
示例#31
0
 def test_no_main(self):
     with self.assertRaises(NoSource):
         run_python_module(["pkg2", "hi"])
示例#32
0
 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")