Commit 715debd3 authored by Greg Ward's avatar Greg Ward

Factored out BaseTestCase.check_split() method -- use it wherever

we need to test TextWrapper._split().
parent 24a1c9cf
...@@ -37,6 +37,12 @@ class BaseTestCase(unittest.TestCase): ...@@ -37,6 +37,12 @@ class BaseTestCase(unittest.TestCase):
result = wrap(text, width) result = wrap(text, width)
self.check(result, expect) self.check(result, expect)
def check_split (self, wrapper, text, expect):
result = wrapper._split(text)
self.assertEquals(result, expect,
"\nexpected %r\n"
"but got %r" % (expect, result))
class WrapTestCase(BaseTestCase): class WrapTestCase(BaseTestCase):
...@@ -155,13 +161,10 @@ What a mess! ...@@ -155,13 +161,10 @@ What a mess!
# All of the above behaviour could be deduced by probing the # All of the above behaviour could be deduced by probing the
# _split() method. # _split() method.
text = "Here's an -- em-dash and--here's another---and another!" text = "Here's an -- em-dash and--here's another---and another!"
result = self.wrapper._split(text)
expect = ["Here's", " ", "an", " ", "--", " ", "em-", "dash", " ", expect = ["Here's", " ", "an", " ", "--", " ", "em-", "dash", " ",
"and", "--", "here's", " ", "another", "---", "and", "--", "here's", " ", "another", "---",
"and", " ", "another!"] "and", " ", "another!"]
self.assertEquals(result, expect, self.check_split(self.wrapper, text, expect)
"\nexpected %r\n"
"but got %r" % (expect, result))
def test_unix_options (self): def test_unix_options (self):
# Test that Unix-style command-line options are wrapped correctly. # Test that Unix-style command-line options are wrapped correctly.
...@@ -193,12 +196,9 @@ What a mess! ...@@ -193,12 +196,9 @@ What a mess!
# Again, all of the above can be deduced from _split(). # Again, all of the above can be deduced from _split().
text = "the -n option, or --dry-run or --dryrun" text = "the -n option, or --dry-run or --dryrun"
result = self.wrapper._split(text)
expect = ["the", " ", "-n", " ", "option,", " ", "or", " ", expect = ["the", " ", "-n", " ", "option,", " ", "or", " ",
"--dry-", "run", " ", "or", " ", "--dryrun"] "--dry-", "run", " ", "or", " ", "--dryrun"]
self.assertEquals(result, expect, self.check_split(self.wrapper, text, expect)
"\nexpected %r\n"
"but got %r" % (expect, result))
def test_split(self): def test_split(self):
# Ensure that the standard _split() method works as advertised # Ensure that the standard _split() method works as advertised
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment