diff --git a/docformatter.py b/docformatter.py index 359c811..8155d8f 100644 --- a/docformatter.py +++ b/docformatter.py @@ -162,14 +162,14 @@ def format_docstring(indentation, docstring, {description}{post_description} {indentation}"""\ '''.format(pre_summary=('\n' + indentation if pre_summary_newline - else unicode()), + else ''), summary=wrap_summary(normalize_summary(summary), wrap_length=summary_wrap_length, initial_indent=initial_indent, subsequent_indent=indentation).lstrip(), description='\n'.join([indent_non_indented(l, indentation).rstrip() for l in description.splitlines()]), - post_description=('\n' if post_description_blank else unicode()), + post_description=('\n' if post_description_blank else ''), indentation=indentation) else: return wrap_summary('"""' + normalize_summary(contents) + '"""', @@ -219,7 +219,7 @@ def split_summary_and_description(contents): if len(split) == 2: return (split[0].strip(), (token + split[1]).strip()) - return (split[0].strip(), unicode()) + return (split[0].strip(), '') def strip_docstring(docstring): @@ -303,7 +303,7 @@ def format_file(filename, args, standard_out): 'before/' + filename, 'after/' + filename, lineterm='') - standard_out.write(unicode('\n').join(list(diff) + [''])) + standard_out.write('\n'.join(list(diff) + [''])) def main(argv, standard_out, standard_error): diff --git a/setup.py b/setup.py index 2abdee6..f8c288d 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,9 @@ #!/usr/bin/env python + """Setup for docformatter.""" +from __future__ import unicode_literals + import ast from distutils import core diff --git a/test_docformatter.py b/test_docformatter.py index a8ee383..3c31b4a 100755 --- a/test_docformatter.py +++ b/test_docformatter.py @@ -2,6 +2,8 @@ """Test suite for docformatter.""" +from __future__ import unicode_literals + import contextlib import io import tempfile @@ -15,12 +17,6 @@ import docformatter -try: - unicode -except NameError: - unicode = str - - class TestUnits(unittest.TestCase): def test_strip_docstring(self): @@ -193,12 +189,12 @@ def foo(): """Hello foo.""" ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): """ Hello foo. """ -'''))) +''')) def test_format_code_with_empty_string(self): self.assertEqual( @@ -214,14 +210,14 @@ def foo(): \t\tx = 1 ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): \t""" \tHello foo. \t""" \tif True: \t\tx = 1 -'''))) +''')) def test_format_code_with_mixed_tabs(self): self.assertEqual( @@ -232,14 +228,14 @@ def foo(): \t x = 1 ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): \t""" \tHello foo. \t""" \tif True: \t x = 1 -'''))) +''')) def test_format_code_with_escaped_newlines(self): self.assertEqual( @@ -249,13 +245,13 @@ def test_format_code_with_escaped_newlines(self): 1 ''', docformatter.format_code( - unicode(r'''def foo(): + r'''def foo(): """ Hello foo. """ x = \ 1 -'''))) +''')) def test_format_code_with_comments(self): self.assertEqual( @@ -267,7 +263,7 @@ def foo(): 123 '''.lstrip(), docformatter.format_code( - unicode(r''' + r''' def foo(): """ Hello foo. @@ -275,7 +271,7 @@ def foo(): # My comment # My comment with escape \ 123 -'''.lstrip()))) +'''.lstrip())) def test_format_code_skip_complex(self): """We do not handle r/u/b prefixed strings.""" @@ -287,12 +283,12 @@ def foo(): """ ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): r""" Hello foo. """ -'''))) +''')) def test_format_code_skip_complex_single(self): """We do not handle r/u/b prefixed strings.""" @@ -304,19 +300,19 @@ def foo(): ''' """, docformatter.format_code( - unicode("""\ + """\ def foo(): r''' Hello foo. ''' -"""))) +""")) def test_format_code_skip_nested(self): - code = unicode("""\ + code = """\ def foo(): '''Hello foo. \"\"\"abc\"\"\" ''' -""") +""" self.assertEqual(code, docformatter.format_code(code)) def test_format_code_with_multiple_sentences(self): @@ -330,13 +326,13 @@ def foo(): """ ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): """ Hello foo. This is a docstring. """ -'''))) +''')) def test_format_code_with_multiple_sentences_same_line(self): self.assertEqual( @@ -349,12 +345,12 @@ def foo(): """ ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): """ Hello foo. This is a docstring. """ -'''))) +''')) def test_format_code_with_multiple_sentences_multiline_summary(self): self.assertEqual( @@ -367,13 +363,13 @@ def foo(): """ ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): """ Hello foo. This is a docstring. """ -'''))) +''')) def test_format_code_with_empty_lines(self): self.assertEqual( @@ -388,7 +384,7 @@ def foo(): """ ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): """ Hello @@ -396,7 +392,7 @@ def foo(): More stuff. """ -'''))) +''')) def test_format_code_with_trailing_whitespace(self): self.assertEqual( @@ -411,7 +407,7 @@ def foo(): """ ''', docformatter.format_code( - (unicode('''\ + ('''\ def foo(): """ Hello @@ -419,13 +415,13 @@ def foo(): More stuff.\t """ -''')))) +'''))) def test_format_code_with_no_docstring(self): - line = unicode('''\ + line = '''\ def foo(): "Just a regular string" -''') +''' self.assertEqual(line, docformatter.format_code(line)) def test_format_code_with_assignment_on_first_line(self): @@ -435,10 +431,10 @@ def foo(): x = """Just a regular string. Alpha.""" ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): x = """Just a regular string. Alpha.""" -'''))) +''')) def test_format_code_with_regular_strings_too(self): self.assertEqual( @@ -459,7 +455,7 @@ def foo(): touched\t""" ''', docformatter.format_code( - unicode('''\ + '''\ def foo(): """ Hello @@ -473,11 +469,11 @@ def foo(): """More stuff that should not be touched\t""" -'''))) +''')) def test_format_code_with_syntax_error(self): self.assertEqual('"""\n', - docformatter.format_code(unicode('"""\n'))) + docformatter.format_code('"""\n')) def test_split_summary_and_description(self): self.assertEqual(('This is the first.', @@ -553,14 +549,14 @@ def foo(): docformatter.main(argv=['my_fake_program', filename], standard_out=output_file, standard_error=None) - self.assertEqual(unicode('''\ + self.assertEqual('''\ @@ -1,4 +1,2 @@ def foo(): - """ - Hello world - """ + """Hello world.""" -'''), '\n'.join(output_file.getvalue().split('\n')[2:])) +''', '\n'.join(output_file.getvalue().split('\n')[2:])) def test_diff_with_nonexistent_file(self): output_file = io.StringIO()