Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
7f0b8ac0
Commit
7f0b8ac0
authored
Feb 06, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed types usage and added test coverage (work for #3986)
parent
bd73f62c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
9 deletions
+51
-9
cmd.py
cmd.py
+13
-9
tests/test_cmd.py
tests/test_cmd.py
+38
-0
No files found.
cmd.py
View file @
7f0b8ac0
...
...
@@ -7,8 +7,7 @@ in the distutils.command package.
__revision__
=
"$Id$"
import
sys
,
os
,
string
,
re
from
types
import
*
from
distutils.errors
import
*
from
distutils.errors
import
DistutilsOptionError
from
distutils
import
util
,
dir_util
,
file_util
,
archive_util
,
dep_util
from
distutils
import
log
...
...
@@ -220,7 +219,7 @@ class Command:
if
val
is
None
:
setattr
(
self
,
option
,
default
)
return
default
elif
type
(
val
)
is
not
StringType
:
elif
not
isinstance
(
val
,
str
)
:
raise
DistutilsOptionError
,
\
"'%s' must be a %s (got `%s`)"
%
(
option
,
what
,
val
)
return
val
...
...
@@ -240,19 +239,24 @@ class Command:
val
=
getattr
(
self
,
option
)
if
val
is
None
:
return
elif
type
(
val
)
is
StringType
:
elif
isinstance
(
val
,
str
)
:
setattr
(
self
,
option
,
re
.
split
(
r',\
s*|
\s+'
,
val
))
else
:
if
type
(
val
)
is
ListType
:
types
=
map
(
type
,
val
)
ok
=
(
types
==
[
StringType
]
*
len
(
val
))
if
isinstance
(
val
,
list
):
# checks if all elements are str
ok
=
1
for
element
in
val
:
if
not
isinstance
(
element
,
str
):
ok
=
0
break
else
:
ok
=
0
if
not
ok
:
raise
DistutilsOptionError
,
\
"'%s' must be a list of strings (got %r)"
%
\
(
option
,
val
)
"'%s' must be a list of strings (got %r)"
%
\
(
option
,
val
)
def
_ensure_tested_string
(
self
,
option
,
tester
,
what
,
error_fmt
,
default
=
None
):
...
...
tests/test_cmd.py
0 → 100644
View file @
7f0b8ac0
"""Tests for distutils.cmd."""
import
unittest
from
distutils.cmd
import
Command
from
distutils.dist
import
Distribution
from
distutils.errors
import
DistutilsOptionError
class
CommandTestCase
(
unittest
.
TestCase
):
def
test_ensure_string_list
(
self
):
class
MyCmd
(
Command
):
def
initialize_options
(
self
):
pass
dist
=
Distribution
()
cmd
=
MyCmd
(
dist
)
cmd
.
not_string_list
=
[
'one'
,
2
,
'three'
]
cmd
.
yes_string_list
=
[
'one'
,
'two'
,
'three'
]
cmd
.
not_string_list2
=
object
()
cmd
.
yes_string_list2
=
'ok'
cmd
.
ensure_string_list
(
'yes_string_list'
)
cmd
.
ensure_string_list
(
'yes_string_list2'
)
self
.
assertRaises
(
DistutilsOptionError
,
cmd
.
ensure_string_list
,
'not_string_list'
)
self
.
assertRaises
(
DistutilsOptionError
,
cmd
.
ensure_string_list
,
'not_string_list2'
)
def
test_suite
():
return
unittest
.
makeSuite
(
CommandTestCase
)
if
__name__
==
'__main__'
:
test_support
.
run_unittest
(
test_suite
())
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