diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-18 21:01:09 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-18 21:01:09 -0500 |
commit | 0618e029df90133aa836847a403f6584eeaf57a4 (patch) | |
tree | 16a5b9c9a5a75a6fd687508206ef851da204bb0c | |
parent | 39ff8faf93287a78b105bfb0322f10227af60dae (diff) | |
download | python-coveragepy-git-0618e029df90133aa836847a403f6584eeaf57a4.tar.gz |
Make some test setup more uniform
-rw-r--r-- | tests/test_execfile.py | 12 | ||||
-rw-r--r-- | tests/test_phystokens.py | 4 | ||||
-rw-r--r-- | tests/test_process.py | 7 | ||||
-rw-r--r-- | tests/test_summary.py | 14 |
4 files changed, 23 insertions, 14 deletions
diff --git a/tests/test_execfile.py b/tests/test_execfile.py index bf6d323f..49d6cc8c 100644 --- a/tests/test_execfile.py +++ b/tests/test_execfile.py @@ -1,6 +1,11 @@ """Tests for coverage.execfile""" -import compileall, json, os, re, sys +import compileall +import json +import os +import os.path +import re +import sys from coverage.backward import binary_bytes from coverage.execfile import run_python_file, run_python_module @@ -8,13 +13,14 @@ from coverage.misc import NoCode, NoSource from tests.coveragetest import CoverageTest -here = os.path.dirname(__file__) +HERE = os.path.dirname(__file__) + class RunFileTest(CoverageTest): """Test cases for `run_python_file`.""" def test_run_python_file(self): - tryfile = os.path.join(here, "try_execfile.py") + tryfile = os.path.join(HERE, "try_execfile.py") run_python_file(tryfile, [tryfile, "arg1", "arg2"]) mod_globs = json.loads(self.stdout()) diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index b8986a80..74a52205 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -1,6 +1,6 @@ """Tests for Coverage.py's improved tokenizer.""" -import os +import os.path import re from nose.plugins.skip import SkipTest @@ -23,7 +23,7 @@ def hello(): \tb="indented" """ -HERE = os.path.split(__file__)[0] +HERE = os.path.dirname(__file__) class PhysTokensTest(CoverageTest): diff --git a/tests/test_process.py b/tests/test_process.py index aa179c68..a1c853d1 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -2,6 +2,7 @@ import glob import os +import os.path import sys import textwrap @@ -12,7 +13,7 @@ from coverage import env from tests.coveragetest import CoverageTest -here = os.path.dirname(__file__) +HERE = os.path.dirname(__file__) class ProcessTest(CoverageTest): @@ -325,7 +326,7 @@ class ProcessTest(CoverageTest): self.assertEqual(status, 0) def test_coverage_run_is_like_python(self): - tryfile = os.path.join(here, "try_execfile.py") + tryfile = os.path.join(HERE, "try_execfile.py") with open(tryfile) as f: self.make_file("run_me.py", f.read()) out_cov = self.run_command("coverage run run_me.py") @@ -388,7 +389,7 @@ class ProcessTest(CoverageTest): def test_coverage_run_dashm_is_like_python_dashm_off_path(self): # https://bitbucket.org/ned/coveragepy/issue/242 - tryfile = os.path.join(here, "try_execfile.py") + tryfile = os.path.join(HERE, "try_execfile.py") self.make_file("sub/__init__.py", "") with open(tryfile) as f: self.make_file("sub/run_me.py", f.read()) diff --git a/tests/test_summary.py b/tests/test_summary.py index f603a979..6fc4fc8d 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -2,6 +2,7 @@ import glob import os +import os.path import py_compile import re import sys @@ -14,6 +15,9 @@ from coverage.backward import StringIO from tests.coveragetest import CoverageTest +HERE = os.path.dirname(__file__) + + class SummaryTest(CoverageTest): """Tests of the text summary reporting for coverage.py.""" @@ -26,7 +30,7 @@ class SummaryTest(CoverageTest): print('done') """) # Parent class saves and restores sys.path, we can just modify it. - sys.path.append(self.nice_file(os.path.dirname(__file__), 'modules')) + sys.path.append(self.nice_file(HERE, 'modules')) def test_report(self): out = self.run_command("coverage run mycode.py") @@ -81,10 +85,9 @@ class SummaryTest(CoverageTest): def test_report_omitting(self): # Try reporting while omitting some modules - prefix = os.path.split(__file__)[0] self.run_command("coverage run mycode.py") report = self.report_from_command( - "coverage report --omit '%s/*'" % prefix + "coverage report --omit '%s/*'" % HERE ) # Name Stmts Miss Cover @@ -506,9 +509,8 @@ class SummaryTest2(CoverageTest): def setUp(self): super(SummaryTest2, self).setUp() # Parent class saves and restores sys.path, we can just modify it. - this_dir = os.path.dirname(__file__) - sys.path.append(self.nice_file(this_dir, 'modules')) - sys.path.append(self.nice_file(this_dir, 'moremodules')) + sys.path.append(self.nice_file(HERE, 'modules')) + sys.path.append(self.nice_file(HERE, 'moremodules')) def test_empty_files(self): # Shows that empty files like __init__.py are listed as having zero |