Skip to content

Commit

Permalink
fix Python 3 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kilink committed Apr 6, 2014
1 parent 23f9a77 commit 520d8ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ghdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def main(args=None, stdout=sys.stdout):
sys.exit(-1)

def read_file(filename):
with open(filename) as f:
with open(filename, "rb") as f:
text = f.read()
codepage = chardet.detect(text)['encoding']
return text.decode(codepage).splitlines()

a = read_file(args[0])
b = read_file(args[1])
six.print_(diff(a, b, css=options.css).encode('utf-8'), file=stdout)
stdout.write(diff(a, b, css=options.css).encode("utf-8"))

if __name__ == "__main__":
main(sys.argv[1:])
6 changes: 3 additions & 3 deletions src/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_script(self):
out = io.BytesIO()
ghdiff.main([f1, f2], stdout=out)
output = out.getvalue()
self.assertTrue("-foobar" in output)
self.assertTrue('+foobar<span class="highlight">baz</span>' in output)
self.assertTrue(b"-foobar" in output)
self.assertTrue(b'+foobar<span class="highlight">baz</span>' in output)

def test_no_css_option(self):
"""Simple test for --no-css option"""
Expand All @@ -43,7 +43,7 @@ def test_no_css_option(self):
out = io.BytesIO()
ghdiff.main([f1, f2, "--no-css"], stdout=out)
output = out.getvalue()
self.assertFalse("<style" in output)
self.assertFalse(b"<style" in output)


def test_suite():
Expand Down

0 comments on commit 520d8ec

Please sign in to comment.