Skip to content

Commit

Permalink
use textwrap.dedent() to make long tests strings more legible.
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Sep 30, 2016
1 parent 197cf79 commit ec65384
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/zope/testing/test_renormalizing.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import unittest

import textwrap
from zope.testing.renormalizing import strip_dottedname_from_traceback


class Exception2To3(unittest.TestCase):

def test_strip_dottedname(self):
string = """\
Traceback (most recent call last):
foo.bar.FooBarError: requires at least one argument."""
Traceback (most recent call last):
foo.bar.FooBarError: requires at least one argument."""
string = textwrap.dedent(string)
expected = """\
Traceback (most recent call last):
FooBarError: requires at least one argument."""
Traceback (most recent call last):
FooBarError: requires at least one argument."""
expected = textwrap.dedent(expected)
self.assertEqual(expected, strip_dottedname_from_traceback(string))

def test_no_dots_in_name(self):
string = """\
Traceback (most recent call last):
FooBarError: requires at least one argument."""
Traceback (most recent call last):
FooBarError: requires at least one argument."""
string = textwrap.dedent(string)
expected = """\
Traceback (most recent call last):
FooBarError: requires at least one argument."""
Traceback (most recent call last):
FooBarError: requires at least one argument."""
expected = textwrap.dedent(expected)
self.assertEqual(expected, strip_dottedname_from_traceback(string))

def test_no_colon_in_first_word(self):
string = """\
Traceback (most recent call last):
foo.bar.FooBarError requires at least one argument."""
Traceback (most recent call last):
foo.bar.FooBarError requires at least one argument."""
string = textwrap.dedent(string)
expected = """\
Traceback (most recent call last):
foo.bar.FooBarError requires at least one argument."""
Traceback (most recent call last):
foo.bar.FooBarError requires at least one argument."""
expected = textwrap.dedent(expected)
self.assertEqual(expected, strip_dottedname_from_traceback(string))

def test_input_empty(self):
Expand All @@ -44,11 +50,13 @@ def test_input_spaces(self):

def test_last_line_empty(self):
string = """\
Traceback (most recent call last):
Traceback (most recent call last):
"""
"""
string = textwrap.dedent(string)
expected = """\
Traceback (most recent call last):
Traceback (most recent call last):
"""
"""
expected = textwrap.dedent(expected)
self.assertEqual(expected, strip_dottedname_from_traceback(string))

0 comments on commit ec65384

Please sign in to comment.