summaryrefslogtreecommitdiff
path: root/tests/test_phystokens.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_phystokens.py')
-rw-r--r--tests/test_phystokens.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py
index 7bdece72..e28fb176 100644
--- a/tests/test_phystokens.py
+++ b/tests/test_phystokens.py
@@ -102,6 +102,7 @@ ENCODING_DECLARATION_SOURCES = [
b"#!/usr/bin/python\n# vim: set fileencoding=cp850:\n",
b"# This Python file uses this encoding: cp850\n",
b"# This file uses a different encoding:\n# coding: cp850\n",
+ b"\n# coding=cp850\n\n",
]
class SourceEncodingTest(CoverageTest):
@@ -126,11 +127,6 @@ class SourceEncodingTest(CoverageTest):
source = b'def parse(src, encoding=None):\n pass'
self.assertEqual(source_encoding(source), DEF_ENCODING)
- def test_detect_source_encoding_on_second_line(self):
- # A coding declaration should be found despite a first blank line.
- source = b"\n# coding=cp850\n\n"
- self.assertEqual(source_encoding(source), 'cp850')
-
def test_dont_detect_source_encoding_on_third_line(self):
# A coding declaration doesn't count on the third line.
source = b"\n\n# coding=cp850\n\n"
@@ -160,6 +156,18 @@ class NeuterEncodingDeclarationTest(CoverageTest):
for source in ENCODING_DECLARATION_SOURCES:
neutered = neuter_encoding_declaration(source.decode("ascii"))
neutered = neutered.encode("ascii")
+
+ # The neutered source should have the same number of lines.
+ source_lines = source.splitlines()
+ neutered_lines = neutered.splitlines()
+ self.assertEqual(len(source_lines), len(neutered_lines))
+
+ # Only one of the lines should be different.
+ lines_different = sum(
+ int(nline != sline) for nline, sline in zip(neutered_lines, source_lines)
+ )
+ self.assertEqual(lines_different, 1)
+
self.assertEqual(
source_encoding(neutered),
DEF_ENCODING,