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
2fdd0d5a
Commit
2fdd0d5a
authored
Apr 13, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved test coverage for distutils.cmd
parent
abc26603
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
7 deletions
+47
-7
Lib/distutils/cmd.py
Lib/distutils/cmd.py
+7
-7
Lib/distutils/tests/test_cmd.py
Lib/distutils/tests/test_cmd.py
+40
-0
No files found.
Lib/distutils/cmd.py
View file @
2fdd0d5a
...
...
@@ -214,7 +214,7 @@ class Command:
# and they can be guaranteed that thereafter, self.foo will be
# a list of strings.
def
_ensure_stringlike
(
self
,
option
,
what
,
default
=
None
):
def
_ensure_stringlike
(
self
,
option
,
what
,
default
=
None
):
val
=
getattr
(
self
,
option
)
if
val
is
None
:
setattr
(
self
,
option
,
default
)
...
...
@@ -224,13 +224,13 @@ class Command:
"'%s' must be a %s (got `%s`)"
%
(
option
,
what
,
val
)
return
val
def
ensure_string
(
self
,
option
,
default
=
None
):
def
ensure_string
(
self
,
option
,
default
=
None
):
"""Ensure that 'option' is a string; if not defined, set it to
'default'.
"""
self
.
_ensure_stringlike
(
option
,
"string"
,
default
)
def
ensure_string_list
(
self
,
option
):
def
ensure_string_list
(
self
,
option
):
"""Ensure that 'option' is a list of strings. If 'option' is
currently a string, we split it either on /,
\
s*/ o
r
/
\
s+/, so
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
...
...
@@ -258,20 +258,20 @@ class Command:
(
option
,
val
)
def
_ensure_tested_string
(
self
,
option
,
tester
,
what
,
error_fmt
,
default
=
None
):
def
_ensure_tested_string
(
self
,
option
,
tester
,
what
,
error_fmt
,
default
=
None
):
val
=
self
.
_ensure_stringlike
(
option
,
what
,
default
)
if
val
is
not
None
and
not
tester
(
val
):
raise
DistutilsOptionError
,
\
(
"error in '%s' option: "
+
error_fmt
)
%
(
option
,
val
)
def
ensure_filename
(
self
,
option
):
def
ensure_filename
(
self
,
option
):
"""Ensure that 'option' is the name of an existing file."""
self
.
_ensure_tested_string
(
option
,
os
.
path
.
isfile
,
"filename"
,
"'%s' does not exist or is not a file"
)
def
ensure_dirname
(
self
,
option
):
def
ensure_dirname
(
self
,
option
):
self
.
_ensure_tested_string
(
option
,
os
.
path
.
isdir
,
"directory name"
,
"'%s' does not exist or is not a directory"
)
...
...
Lib/distutils/tests/test_cmd.py
View file @
2fdd0d5a
"""Tests for distutils.cmd."""
import
unittest
import
os
from
distutils.cmd
import
Command
from
distutils.dist
import
Distribution
...
...
@@ -62,6 +63,45 @@ class CommandTestCase(unittest.TestCase):
' option2 = 1'
]
self
.
assertEquals
(
msgs
,
wanted
)
def
test_ensure_string
(
self
):
cmd
=
self
.
cmd
cmd
.
option1
=
'ok'
cmd
.
ensure_string
(
'option1'
)
cmd
.
option2
=
None
cmd
.
ensure_string
(
'option2'
,
'xxx'
)
self
.
assert_
(
hasattr
(
cmd
,
'option2'
))
cmd
.
option3
=
1
self
.
assertRaises
(
DistutilsOptionError
,
cmd
.
ensure_string
,
'option3'
)
def
test_ensure_string_list
(
self
):
cmd
=
self
.
cmd
cmd
.
option1
=
'ok,dok'
cmd
.
ensure_string_list
(
'option1'
)
self
.
assertEquals
(
cmd
.
option1
,
[
'ok'
,
'dok'
])
cmd
.
option2
=
[
'xxx'
,
'www'
]
cmd
.
ensure_string_list
(
'option2'
)
cmd
.
option3
=
[
'ok'
,
2
]
self
.
assertRaises
(
DistutilsOptionError
,
cmd
.
ensure_string_list
,
'option3'
)
def
test_ensure_filename
(
self
):
cmd
=
self
.
cmd
cmd
.
option1
=
__file__
cmd
.
ensure_filename
(
'option1'
)
cmd
.
option2
=
'xxx'
self
.
assertRaises
(
DistutilsOptionError
,
cmd
.
ensure_filename
,
'option2'
)
def
test_ensure_dirname
(
self
):
cmd
=
self
.
cmd
cmd
.
option1
=
os
.
path
.
dirname
(
__file__
)
cmd
.
ensure_dirname
(
'option1'
)
cmd
.
option2
=
'xxx'
self
.
assertRaises
(
DistutilsOptionError
,
cmd
.
ensure_dirname
,
'option2'
)
def
test_suite
():
return
unittest
.
makeSuite
(
CommandTestCase
)
...
...
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