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
7462fa65
Commit
7462fa65
authored
Mar 16, 2011
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport improved test coverage for string.py
parent
454e11d8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
0 deletions
+41
-0
Lib/test/test_pep292.py
Lib/test/test_pep292.py
+13
-0
Lib/test/test_string.py
Lib/test/test_string.py
+24
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_pep292.py
View file @
7462fa65
...
...
@@ -42,6 +42,19 @@ class TestTemplate(unittest.TestCase):
s
=
Template
(
'$who likes $$'
)
eq
(
s
.
substitute
(
dict
(
who
=
'tim'
,
what
=
'ham'
)),
'tim likes $'
)
def
test_invalid
(
self
):
class
MyPattern
(
Template
):
pattern
=
r"""
(?:
(?P<invalid>) |
(?P<escaped>%(delim)s) |
@(?P<named>%(id)s) |
@{(?P<braced>%(id)s)}
)
"""
s
=
MyPattern
(
'$'
)
self
.
assertRaises
(
ValueError
,
s
.
substitute
,
dict
())
def
test_percents
(
self
):
eq
=
self
.
assertEqual
s
=
Template
(
'%(foo)s $foo ${foo}'
)
...
...
Lib/test/test_string.py
View file @
7462fa65
...
...
@@ -112,6 +112,30 @@ class ModuleTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
fmt
.
format
,
"{0}"
,
10
,
20
,
i
=
100
)
self
.
assertRaises
(
ValueError
,
fmt
.
format
,
"{i}"
,
10
,
20
,
i
=
100
)
def
test_vformat_assert
(
self
):
cls
=
string
.
Formatter
()
kwargs
=
{
"i"
:
100
}
self
.
assertRaises
(
ValueError
,
cls
.
_vformat
,
cls
.
format
,
"{0}"
,
kwargs
,
set
(),
-
2
)
def
test_convert_field
(
self
):
cls
=
string
.
Formatter
()
self
.
assertEqual
(
cls
.
format
(
"{0!s}"
,
'foo'
),
'foo'
)
self
.
assertRaises
(
ValueError
,
cls
.
format
,
"{0!h}"
,
'foo'
)
def
test_get_field
(
self
):
cls
=
string
.
Formatter
()
class
MyClass
:
name
=
'lumberjack'
x
=
MyClass
()
self
.
assertEqual
(
cls
.
format
(
"{0.name}"
,
x
),
'lumberjack'
)
lookup
=
[
"eggs"
,
"and"
,
"spam"
]
self
.
assertEqual
(
cls
.
format
(
"{0[2]}"
,
lookup
),
'spam'
)
def
test_main
():
support
.
run_unittest
(
ModuleTest
)
...
...
Misc/ACKS
View file @
7462fa65
...
...
@@ -32,6 +32,7 @@ Oliver Andrich
Ross Andrus
Jon Anglin
Éric Araujo
Alicia Arlen
Jason Asbahr
David Ascher
Chris AtLee
...
...
Misc/NEWS
View file @
7462fa65
...
...
@@ -122,6 +122,9 @@ Tools/Demos
Tests
-----
- Issue #11505: improves test coverage of string.py. Patch by Alicia
Arlen.
- Issue #11548: Improve test coverage of the shutil module. Patch by
Evan Dandrea.
...
...
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