Skip to content

Commit

Permalink
Fix Python 3 support
Browse files Browse the repository at this point in the history
This fixes Python 3 support for doc8.

Change-Id: Id3f3a35f2d68c4cb6eefcf7a960d7991b8f4522f
  • Loading branch information
jd committed Jan 27, 2015
1 parent e9cd504 commit 4d82c26
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion doc8/checks.py
Expand Up @@ -80,7 +80,7 @@ def __init__(self, cfg):
super(CheckNewlineEndOfFile, self).__init__(cfg)

def report_iter(self, parsed_file):
if parsed_file.lines and not parsed_file.lines[-1].endswith('\n'):
if parsed_file.lines and not parsed_file.lines[-1].endswith(b'\n'):
yield (len(parsed_file.lines), 'D005', 'No newline at end of file')


Expand Down
28 changes: 14 additions & 14 deletions doc8/tests/test_checks.py
Expand Up @@ -60,7 +60,7 @@ def test_cr(self):

class TestLineLength(testtools.TestCase):
def test_over_length(self):
content = """
content = b"""
===
aaa
===
Expand All @@ -70,9 +70,9 @@ def test_over_length(self):
----
"""
content += "\n\n"
content += ("a" * 60) + " " + ("b" * 60)
content += "\n"
content += b"\n\n"
content += (b"a" * 60) + b" " + (b"b" * 60)
content += b"\n"
conf = {
'max_line_length': 79,
'allow_long_titles': True,
Expand All @@ -96,8 +96,8 @@ def test_correct_length(self):
}
with tempfile.NamedTemporaryFile(suffix='.rst') as fh:
fh.write(b'known exploit in the wild, for example'
' \xe2\x80\x93 the time'
' between advance notification')
b' \xe2\x80\x93 the time'
b' between advance notification')
fh.flush()

parsed_file = parser.ParsedFile(fh.name, encoding='utf-8')
Expand All @@ -106,7 +106,7 @@ def test_correct_length(self):
self.assertEqual(0, len(errors))

def test_unsplittable_length(self):
content = """
content = b"""
===
aaa
===
Expand All @@ -116,9 +116,9 @@ def test_unsplittable_length(self):
----
"""
content += "\n\n"
content += "a" * 100
content += "\n"
content += b"\n\n"
content += b"a" * 100
content += b"\n"
conf = {
'max_line_length': 79,
'allow_long_titles': True,
Expand All @@ -140,10 +140,10 @@ def test_unsplittable_length(self):

class TestNewlineEndOfFile(testtools.TestCase):
def test_newline(self):
tests = [(1, "testing"),
(1, "testing\ntesting"),
(0, "testing\n"),
(0, "testing\ntesting\n")]
tests = [(1, b"testing"),
(1, b"testing\ntesting"),
(0, b"testing\n"),
(0, b"testing\ntesting\n")]

for expected_errors, line in tests:
with tempfile.NamedTemporaryFile() as fh:
Expand Down
1 change: 0 additions & 1 deletion test-requirements.txt
Expand Up @@ -6,6 +6,5 @@ doc8
hacking>=0.9.2,<0.10
nose
oslosphinx
pylint==0.25.2
sphinx>=1.1.2,!=1.2.0,<1.3
testtools
3 changes: 2 additions & 1 deletion tox.ini
@@ -1,7 +1,7 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = py26,py27,pep8
envlist = py26,py27,py34,pep8

[testenv]
setenv = VIRTUAL_ENV={envdir}
Expand All @@ -15,6 +15,7 @@ commands = nosetests {posargs}
commands = flake8 {posargs}

[testenv:pylint]
requirements = pylint==0.25.2
commands = pylint doc8

[tox:jenkins]
Expand Down

1 comment on commit 4d82c26

@jquast
Copy link

@jquast jquast commented on 4d82c26 Apr 14, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any plans to release to pypi? I just ran into this bug today.

Please sign in to comment.