summaryrefslogtreecommitdiff
path: root/testsuite/test_api.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2013-05-05 02:28:06 +0200
committerFlorent Xicluna <florent.xicluna@gmail.com>2013-05-05 02:28:06 +0200
commitfe692e30ba1a37796f65ec99120ba7ebd47b999c (patch)
treeace564dca56755ab4b3608a66db904c2c04e34d4 /testsuite/test_api.py
parentc8120906884df69de75827c3351ef5eb12fd6c1a (diff)
downloadpep8-fe692e30ba1a37796f65ec99120ba7ebd47b999c.tar.gz
Don't crash when checking the BOM on Unicode lines, with Python 2
Diffstat (limited to 'testsuite/test_api.py')
-rw-r--r--testsuite/test_api.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/testsuite/test_api.py b/testsuite/test_api.py
index 3fa35f1..6cc9d80 100644
--- a/testsuite/test_api.py
+++ b/testsuite/test_api.py
@@ -302,8 +302,20 @@ class APITestCase(unittest.TestCase):
self.assertRaises(TypeError, pep8style.check_files, 42)
# < 3.3 raises TypeError; >= 3.3 raises AttributeError
self.assertRaises(Exception, pep8style.check_files, [42])
- # TODO: runner
- # TODO: input_file
+
+ def test_check_unicode(self):
+ # Do not crash if lines are Unicode (Python 2.x)
+ pep8.register_check(DummyChecker, ['Z701'])
+ source = '#\n'
+ if hasattr(source, 'decode'):
+ source = source.decode('ascii')
+
+ pep8style = pep8.StyleGuide()
+ count_errors = pep8style.input_file('stdin', lines=[source])
+
+ self.assertFalse(sys.stdout)
+ self.assertFalse(sys.stderr)
+ self.assertEqual(count_errors, 0)
def test_check_nullbytes(self):
pep8.register_check(DummyChecker, ['Z701'])
@@ -314,3 +326,6 @@ class APITestCase(unittest.TestCase):
self.assertTrue(sys.stdout[0].startswith("stdin:1:1: E901 TypeError"))
self.assertFalse(sys.stderr)
self.assertEqual(count_errors, 1)
+
+ # TODO: runner
+ # TODO: input_file