summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.treerc1
-rw-r--r--Makefile1
-rwxr-xr-xalltests.sh4
-rw-r--r--test/coveragetest.py7
-rw-r--r--test/test_parser.py33
5 files changed, 41 insertions, 5 deletions
diff --git a/.treerc b/.treerc
index 7b671ef2..3c75f690 100644
--- a/.treerc
+++ b/.treerc
@@ -7,3 +7,4 @@ ignore =
distribute_setup.py ez_setup.py mock.py
*.min.js
sample_html
+ *.so *.pyd
diff --git a/Makefile b/Makefile
index 0cacaccb..978d4051 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ clean:
python test/test_farm.py clean
-rm -rf build coverage.egg-info dist htmlcov
-rm -f *.pyd */*.pyd
+ -rm -f *.so */*.so
-rm -f *.pyc */*.pyc */*/*.pyc */*/*/*.pyc */*/*/*/*.pyc */*/*/*/*/*.pyc
-rm -f *.pyo */*.pyo */*/*.pyo */*/*/*.pyo */*/*/*/*.pyo */*/*/*/*/*.pyo
-rm -f *.bak */*.bak */*/*.bak */*/*/*.bak */*/*/*/*.bak */*/*/*/*/*.bak
diff --git a/alltests.sh b/alltests.sh
index 7c8b0509..c6cae5b2 100755
--- a/alltests.sh
+++ b/alltests.sh
@@ -9,14 +9,14 @@
source ../ve/26/bin/activate
make --quiet testdata
-for v in 24 25 26 27 # 23 31 32
+for v in 24 25 26 27 31 32 # 23
do
source ../ve/$v/bin/activate
python setup.py -q develop
echo "=== $v c ==="
COVERAGE_TEST_TRACER=c nosetests $@
echo "=== $v py ==="
- rm coverage/tracer.so
+ rm coverage/tracer*.so
COVERAGE_TEST_TRACER=py nosetests $@
done
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 53f0ef0b..1e2c2431 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -123,11 +123,12 @@ class CoverageTest(TestCase):
"""Return the data written to stderr during the test."""
return self.captured_stderr.getvalue()
- def make_file(self, filename, text=""):
+ def make_file(self, filename, text="", newline=None):
"""Create a temp file.
`filename` is the path to the file, including directories if desired,
- and `text` is the content.
+ and `text` is the content. If `newline` is provided, it is a string
+ that will be used as the line endings in the created file.
Returns the path to the file.
@@ -135,6 +136,8 @@ class CoverageTest(TestCase):
# Tests that call `make_file` should be run in a temp environment.
assert self.run_in_temp_dir
text = textwrap.dedent(text)
+ if newline:
+ text = text.replace("\n", newline)
# Make sure the directories are available.
dirs, _ = os.path.split(filename)
diff --git a/test/test_parser.py b/test/test_parser.py
index b398044d..c25611cf 100644
--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -16,7 +16,7 @@ class ParserTest(CoverageTest):
def parse_source(self, text):
"""Parse `text` as source, and return the `CodeParser` used."""
text = textwrap.dedent(text)
- cp = CodeParser(text, exclude="nocover")
+ cp = CodeParser(text=text, exclude="nocover")
cp.parse_source()
return cp
@@ -94,3 +94,34 @@ class ParserTest(CoverageTest):
b = 6
""")
self.assertEqual(cp.exit_counts(), { 1:1, 2:1, 3:1, 6:1 })
+
+
+class ParserFileTest(CoverageTest):
+ """Tests for Coverage.py's code parsing from files."""
+
+ def parse_file(self, filename):
+ """Parse `text` as source, and return the `CodeParser` used."""
+ cp = CodeParser(filename=filename, exclude="nocover")
+ cp.parse_source()
+ return cp
+
+ def test_line_endings(self):
+ text = """\
+ # check some basic branch counting
+ class Foo:
+ def foo(self, a):
+ if a:
+ return 5
+ else:
+ return 7
+
+ class Bar:
+ pass
+ """
+ counts = { 2:1, 3:1, 4:2, 5:1, 7:1, 9:1, 10:1 }
+ name_endings = (("unix", "\n"), ("dos", "\r\n"), ("mac", "\r"))
+ for fname, newline in name_endings:
+ fname = fname + ".py"
+ self.make_file(fname, text, newline=newline)
+ cp = self.parse_file(fname)
+ self.assertEqual(cp.exit_counts(), counts)