Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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"])
Exemplo n.º 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"])
Exemplo n.º 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", [])
Exemplo n.º 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", [])
Exemplo n.º 7
0
 def test_runmod1(self):
     run_python_module(["runmod1", "hello"])
     out, err = self.stdouterr()
     assert out == "runmod1: passed hello\n"
     assert err == ""
Exemplo n.º 8
0
 def test_runmod3(self):
     run_python_module("pkg1.sub.runmod3", ["runmod3", "hello"])
     self.assertEqual(self.stdout(), "runmod3: passed hello\n")
Exemplo n.º 9
0
 def test_runmod1(self):
     run_python_module("runmod1", ["runmod1", "hello"])
     self.assertEqual(self.stdout(), "runmod1: passed hello\n")
Exemplo 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")
Exemplo 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")
Exemplo 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"
Exemplo 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 == ""
Exemplo n.º 14
0
 def test_no_main(self):
     with pytest.raises(NoSource):
         run_python_module(["pkg2", "hi"])
Exemplo n.º 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")
Exemplo n.º 16
0
 def test_runmod2(self):
     run_python_module("pkg1.runmod2", ["runmod2", "hello"])
     self.assertEqual(self.stdout(), "runmod2: passed hello\n")
Exemplo 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")
Exemplo 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"
Exemplo 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"
Exemplo 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 == ""
Exemplo n.º 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 == ""
Exemplo n.º 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")
Exemplo 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")
Exemplo n.º 24
0
 def test_runmod1(self):
     run_python_module(["runmod1", "hello"])
     assert self.stderr() == ""
     assert self.stdout() == "runmod1: passed hello\n"
Exemplo 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")
Exemplo 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")
Exemplo n.º 27
0
 def test_runmod1(self):
     run_python_module(["runmod1", "hello"])
     self.assertEqual(self.stderr(), "")
     self.assertEqual(self.stdout(), "runmod1: passed hello\n")
Exemplo n.º 28
0
 def test_no_main(self):
     with self.assertRaises(NoSource):
         run_python_module("pkg2", ["pkg2", "hi"])
Exemplo n.º 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")
Exemplo 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")
Exemplo n.º 31
0
 def test_no_main(self):
     with self.assertRaises(NoSource):
         run_python_module(["pkg2", "hi"])
Exemplo n.º 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")