diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/osinfo.py | 7 | ||||
-rw-r--r-- | tests/test_arcs.py | 11 | ||||
-rw-r--r-- | tests/test_concurrency.py | 12 | ||||
-rw-r--r-- | tests/test_config.py | 2 | ||||
-rw-r--r-- | tests/test_coverage.py | 5 | ||||
-rw-r--r-- | tests/test_html.py | 7 | ||||
-rw-r--r-- | tests/test_phystokens.py | 16 | ||||
-rw-r--r-- | tests/test_plugins.py | 14 | ||||
-rw-r--r-- | tests/test_process.py | 23 | ||||
-rw-r--r-- | tests/test_summary.py | 5 |
10 files changed, 50 insertions, 52 deletions
diff --git a/tests/osinfo.py b/tests/osinfo.py index a123123c..0b86ef54 100644 --- a/tests/osinfo.py +++ b/tests/osinfo.py @@ -1,8 +1,9 @@ """OS information for testing.""" -import sys +from coverage import env -if sys.platform == 'win32': + +if env.WINDOWS: # Windows implementation def process_ram(): """How much RAM is this process using? (Windows)""" @@ -34,7 +35,7 @@ if sys.platform == 'win32': return 0 return mem_struct.PrivateUsage -elif sys.platform == 'linux2': +elif env.LINUX: # Linux implementation import os diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 3856a2cf..92dac5de 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1,8 +1,9 @@ """Tests for Coverage.py's arc measurement.""" -import sys from tests.coveragetest import CoverageTest +from coverage import env + class SimpleArcTest(CoverageTest): """Tests for Coverage.py's arc measurement.""" @@ -247,7 +248,7 @@ class LoopArcTest(CoverageTest): ) # With "while True", 2.x thinks it's computation, 3.x thinks it's # constant. - if sys.version_info >= (3, 0): + if env.PY3: arcz = ".1 12 23 34 45 36 63 57 7." else: arcz = ".1 12 23 27 34 45 36 62 57 7." @@ -306,7 +307,7 @@ class LoopArcTest(CoverageTest): ) def test_confusing_for_loop_bug_175(self): - if sys.version_info >= (3, 0): + if env.PY3: # Py3 counts the list comp as a separate code object. arcz = ".1 .2 2-2 12 23 34 45 53 3." else: @@ -319,7 +320,7 @@ class LoopArcTest(CoverageTest): y = tup[1] """, arcz=arcz, arcz_missing="", arcz_unpredicted="") - if sys.version_info >= (3, 0): + if env.PY3: arcz = ".1 12 .2 2-2 23 34 42 2." else: arcz = ".1 12 23 34 42 2." @@ -504,7 +505,7 @@ class ExceptionArcTest(CoverageTest): # Run this test only on Py2 for now. I hope to fix it on Py3 # eventually... - if sys.version_info < (3, 0): + if env.PY2: # "except Exception as e" is crucial here. def test_bug_212(self): self.check_coverage("""\ diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 02163d2f..77b8c0ec 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -1,8 +1,11 @@ """Tests for concurrency libraries.""" -import os, os.path, sys, threading +import os +import os.path +import threading import coverage +from coverage import env from tests.coveragetest import CoverageTest @@ -24,9 +27,6 @@ try: except ImportError: greenlet = None -# Are we running with the C tracer or not? -C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' - def line_count(s): """How many non-blank non-comment lines are in `s`?""" @@ -78,7 +78,7 @@ class ConcurrencyTest(CoverageTest): """.format(LIMIT=LIMIT) # Import the things to use threads. - if sys.version_info < (3, 0): + if env.PY2: THREAD = """\ import threading import Queue as queue @@ -135,7 +135,7 @@ class ConcurrencyTest(CoverageTest): "the module isn't installed.\n" % concurrency ) self.assertEqual(out, expected_out) - elif C_TRACER or concurrency == "thread": + elif env.C_TRACER or concurrency == "thread": # We can fully measure the code if we are using the C tracer, which # can support all the concurrency, or if we are using threads. if expected_out is None: diff --git a/tests/test_config.py b/tests/test_config.py index 65586846..450c94fc 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -86,7 +86,7 @@ class ConfigTest(CoverageTest): self.set_environ("COVERAGE_FILE", "fromenv.dat") cov = coverage.coverage() self.assertEqual(cov.config.data_file, "fromenv.dat") - # But the constructor args override the env var. + # But the constructor arguments override the environment variable. cov = coverage.coverage(data_file="fromarg.dat") self.assertEqual(cov.config.data_file, "fromarg.dat") diff --git a/tests/test_coverage.py b/tests/test_coverage.py index b69fd986..21f9154f 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -1,9 +1,10 @@ """Tests for Coverage.""" # http://nedbatchelder.com/code/coverage -import sys import coverage +from coverage import env from coverage.misc import CoverageException + from tests.coveragetest import CoverageTest @@ -305,7 +306,7 @@ class SimpleStatementTest(CoverageTest): """, [1,2,3,6,9], "") - if sys.version_info < (3, 0): # Print statement is gone in Py3k. + if env.PY2: # Print statement is gone in Py3k. def test_print(self): self.check_coverage("""\ print "hello, world!" diff --git a/tests/test_html.py b/tests/test_html.py index b0cb839e..b4189af2 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- """Tests that HTML generation is awesome.""" -import os.path, re, sys +import os.path +import re + import coverage +from coverage import env import coverage.html from coverage.misc import CoverageException, NotPython, NoSource @@ -303,7 +306,7 @@ class HtmlWithUnparsableFilesTest(HtmlTestHelpers, CoverageTest): cov.html_report() html_report = self.get_html_report_content("sub/not_ascii.py") - if sys.version_info < (3, 0): + if env.PY2: expected = "# Isn't this great?�!" else: expected = "# Isn't this great?Ë!" diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index bbd956ea..b8986a80 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -2,13 +2,14 @@ import os import re -import sys from nose.plugins.skip import SkipTest -from tests.coveragetest import CoverageTest +from coverage import env from coverage.phystokens import source_token_lines, source_encoding +from tests.coveragetest import CoverageTest + SIMPLE = """\ # yay! @@ -87,7 +88,7 @@ class PhysTokensTest(CoverageTest): # The default encoding is different in Python 2 and Python 3. -if sys.version_info >= (3, 0): +if env.PY3: DEF_ENCODING = "utf-8" else: DEF_ENCODING = "ascii" @@ -110,11 +111,10 @@ class SourceEncodingTest(CoverageTest): self.assertEqual(source_encoding(source), 'utf-8') def test_detect_source_encoding_not_in_comment(self): - if '__pypy__' in sys.builtin_module_names: - if sys.version_info > (3, 0): - # PyPy3 gets this case wrong. Not sure what I can do about it, - # so skip the test. - raise SkipTest + if env.PYPY and env.PY3: + # PyPy3 gets this case wrong. Not sure what I can do about it, + # so skip the test. + raise SkipTest # Should not detect anything here source = b'def parse(src, encoding=None):\n pass' self.assertEqual(source_encoding(source), DEF_ENCODING) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index a1710c5f..f3b8d580 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -1,20 +1,13 @@ """Tests for plugins.""" -import os -import sys - -from nose.plugins.skip import SkipTest - import coverage +from coverage import env from coverage.control import Plugins import coverage.plugin from tests.coveragetest import CoverageTest -# Are we running with the C tracer or not? -C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' - class FakeConfig(object): """A fake config for use in tests.""" @@ -142,14 +135,11 @@ class PluginTest(CoverageTest): cov.stop() -if not C_TRACER: +if not env.C_TRACER: class FileTracerTest(CoverageTest): """Tests of plugins that implement file_tracer.""" def test_plugin1(self): - if sys.platform == 'win32': - raise SkipTest("Plugin stuff is jank on windows.. fixing soon...") - self.make_file("simple.py", """\ import try_xyz a = 1 diff --git a/tests/test_process.py b/tests/test_process.py index 569618ee..aa179c68 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -1,18 +1,19 @@ """Tests for process behavior of coverage.py.""" -import glob, os, sys, textwrap +import glob +import os +import sys +import textwrap + from nose.plugins.skip import SkipTest + import coverage +from coverage import env from tests.coveragetest import CoverageTest here = os.path.dirname(__file__) -# Determine what kind of tests we are running, because some of these tests don't -# work in certain situations. -C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' -METACOV = os.getenv('COVERAGE_COVERAGE', '') != '' - class ProcessTest(CoverageTest): """Tests of the per-process behavior of coverage.py.""" @@ -273,7 +274,7 @@ class ProcessTest(CoverageTest): # same traceback. status, out = self.run_command_status("coverage run throw.py") out2 = self.run_command("python throw.py") - if '__pypy__' in sys.builtin_module_names: + if env.PYPY: # Pypy has an extra frame in the traceback for some reason lines2 = out2.splitlines() out2 = "".join(l+"\n" for l in lines2 if "toplevel" not in l) @@ -528,9 +529,9 @@ class ProcessTest(CoverageTest): self.assertIn("Trace function changed", out) - if sys.version_info >= (3, 0): # This only works on 3.x for now. + if env.PY3: # This only works on 3.x for now. # It only works with the C tracer, and if we aren't measuring ourselves. - if C_TRACER and not METACOV: # pragma: not covered + if env.C_TRACER and not env.METACOV: # pragma: not covered def test_fullcoverage(self): # fullcoverage is a trick to get stdlib modules measured from # the very beginning of the process. Here we import os and @@ -716,7 +717,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): """Test that we can measure coverage in sub-processes.""" def test_subprocess_with_pth_files(self): # pragma: not covered - if METACOV: + if env.METACOV: raise SkipTest( "Can't test sub-process pth file suppport during metacoverage" ) @@ -766,7 +767,7 @@ class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest): def assert_pth_and_source_work_together( self, dashm, package, source ): # pragma: not covered - if METACOV: + if env.METACOV: raise SkipTest( "Can't test sub-process pth file suppport during metacoverage" ) diff --git a/tests/test_summary.py b/tests/test_summary.py index 77381186..f603a979 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -9,6 +9,7 @@ import sys from nose.plugins.skip import SkipTest import coverage +from coverage import env from coverage.backward import StringIO from tests.coveragetest import CoverageTest @@ -423,7 +424,7 @@ class SummaryTest(CoverageTest): self.assertIn("TheCode", report) self.assertNotIn("thecode", report) - if sys.platform == 'win32': + if env.WINDOWS: def test_pyw_files(self): # https://bitbucket.org/ned/coveragepy/issue/261 self.make_file("start.pyw", """\ @@ -463,7 +464,7 @@ class SummaryTest(CoverageTest): def test_missing_py_file_during_run(self): # PyPy2 doesn't run bare .pyc files. - if '__pypy__' in sys.builtin_module_names and sys.version_info < (3,): + if env.PYPY and env.PY2: raise SkipTest("PyPy2 doesn't run bare .pyc files") # Create two Python files. |