Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9e082f4e
Commit
9e082f4e
authored
May 08, 2003
by
Greg Ward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DedentTestCase to test dedent() function.
parent
478cd48d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
3 deletions
+68
-3
Lib/test/test_textwrap.py
Lib/test/test_textwrap.py
+68
-3
No files found.
Lib/test/test_textwrap.py
View file @
9e082f4e
...
...
@@ -11,7 +11,7 @@
import
unittest
from
test
import
test_support
from
textwrap
import
TextWrapper
,
wrap
,
fill
from
textwrap
import
TextWrapper
,
wrap
,
fill
,
dedent
class
BaseTestCase
(
unittest
.
TestCase
):
...
...
@@ -323,7 +323,6 @@ How *do* you spell that odd word, anyways?
self
.
check
(
result
,
expect
)
class
IndentTestCases
(
BaseTestCase
):
# called before each test method
...
...
@@ -373,8 +372,74 @@ some (including a hanging indent).'''
self
.
check
(
result
,
expect
)
# Despite the similar names, DedentTestCase is *not* the inverse
# of IndentTestCase!
class
DedentTestCase
(
unittest
.
TestCase
):
def
test_dedent_nomargin
(
self
):
# No lines indented.
text
=
"Hello there.
\
n
How are you?
\
n
Oh good, I'm glad."
self
.
assertEquals
(
dedent
(
text
),
text
)
# Similar, with a blank line.
text
=
"Hello there.
\
n
\
n
Boo!"
self
.
assertEquals
(
dedent
(
text
),
text
)
# Some lines indented, but overall margin is still zero.
text
=
"Hello there.
\
n
This is indented."
self
.
assertEquals
(
dedent
(
text
),
text
)
# Again, add a blank line.
text
=
"Hello there.
\
n
\
n
Boo!
\
n
"
self
.
assertEquals
(
dedent
(
text
),
text
)
def
test_dedent_even
(
self
):
# All lines indented by two spaces.
text
=
" Hello there.
\
n
How are ya?
\
n
Oh good."
expect
=
"Hello there.
\
n
How are ya?
\
n
Oh good."
self
.
assertEquals
(
dedent
(
text
),
expect
)
# Same, with blank lines.
text
=
" Hello there.
\
n
\
n
How are ya?
\
n
Oh good.
\
n
"
expect
=
"Hello there.
\
n
\
n
How are ya?
\
n
Oh good.
\
n
"
self
.
assertEquals
(
dedent
(
text
),
expect
)
# Now indent one of the blank lines.
text
=
" Hello there.
\
n
\
n
How are ya?
\
n
Oh good.
\
n
"
expect
=
"Hello there.
\
n
\
n
How are ya?
\
n
Oh good.
\
n
"
self
.
assertEquals
(
dedent
(
text
),
expect
)
def
test_dedent_uneven
(
self
):
# Lines indented unevenly.
text
=
'''
\
def foo():
while 1:
return foo
'''
expect
=
'''
\
def foo():
while 1:
return foo
'''
self
.
assertEquals
(
dedent
(
text
),
expect
)
# Uneven indentation with a blank line.
text
=
" Foo
\
n
Bar
\
n
\
n
Baz
\
n
"
expect
=
"Foo
\
n
Bar
\
n
\
n
Baz
\
n
"
self
.
assertEquals
(
dedent
(
text
),
expect
)
# Uneven indentation with a whitespace-only line.
text
=
" Foo
\
n
Bar
\
n
\
n
Baz
\
n
"
expect
=
"Foo
\
n
Bar
\
n
\
n
Baz
\
n
"
self
.
assertEquals
(
dedent
(
text
),
expect
)
def
test_main
():
test_support
.
run_unittest
(
WrapTestCase
,
LongWordTestCase
,
IndentTestCases
)
test_support
.
run_unittest
(
WrapTestCase
,
LongWordTestCase
,
IndentTestCases
,
DedentTestCase
)
if
__name__
==
'__main__'
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment