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
b58e0bd8
Commit
b58e0bd8
authored
Jan 23, 2010
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use assert[Not]In where appropriate
parent
0f77f465
Changes
39
Hide whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
176 additions
and
173 deletions
+176
-173
Lib/test/mapping_tests.py
Lib/test/mapping_tests.py
+15
-14
Lib/test/pickletester.py
Lib/test/pickletester.py
+4
-4
Lib/test/seq_tests.py
Lib/test/seq_tests.py
+5
-5
Lib/test/test_bigmem.py
Lib/test/test_bigmem.py
+6
-6
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+5
-6
Lib/test/test_cfgparser.py
Lib/test/test_cfgparser.py
+2
-2
Lib/test/test_collections.py
Lib/test/test_collections.py
+2
-2
Lib/test/test_compile.py
Lib/test/test_compile.py
+8
-8
Lib/test/test_copy.py
Lib/test/test_copy.py
+1
-1
Lib/test/test_datetime.py
Lib/test/test_datetime.py
+0
-3
Lib/test/test_dbm.py
Lib/test/test_dbm.py
+1
-1
Lib/test/test_descr.py
Lib/test/test_descr.py
+4
-4
Lib/test/test_dict.py
Lib/test/test_dict.py
+1
-8
Lib/test/test_dis.py
Lib/test/test_dis.py
+2
-2
Lib/test/test_docxmlrpc.py
Lib/test/test_docxmlrpc.py
+38
-12
Lib/test/test_errno.py
Lib/test/test_errno.py
+2
-2
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+1
-1
Lib/test/test_float.py
Lib/test/test_float.py
+4
-9
Lib/test/test_http_cookiejar.py
Lib/test/test_http_cookiejar.py
+17
-19
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+2
-2
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+1
-1
Lib/test/test_multibytecodec.py
Lib/test/test_multibytecodec.py
+1
-1
Lib/test/test_pep352.py
Lib/test/test_pep352.py
+2
-2
Lib/test/test_pkgimport.py
Lib/test/test_pkgimport.py
+3
-3
Lib/test/test_profile.py
Lib/test/test_profile.py
+1
-1
Lib/test/test_pyclbr.py
Lib/test/test_pyclbr.py
+0
-1
Lib/test/test_range.py
Lib/test/test_range.py
+12
-12
Lib/test/test_sax.py
Lib/test/test_sax.py
+2
-2
Lib/test/test_site.py
Lib/test/test_site.py
+5
-5
Lib/test/test_strptime.py
Lib/test/test_strptime.py
+8
-8
Lib/test/test_sys.py
Lib/test/test_sys.py
+1
-2
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+1
-1
Lib/test/test_threading.py
Lib/test/test_threading.py
+1
-1
Lib/test/test_traceback.py
Lib/test/test_traceback.py
+2
-2
Lib/test/test_unittest.py
Lib/test/test_unittest.py
+2
-2
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+2
-3
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+3
-3
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+6
-9
Lib/test/test_weakset.py
Lib/test/test_weakset.py
+3
-3
No files found.
Lib/test/mapping_tests.py
View file @
b58e0bd8
...
...
@@ -56,9 +56,9 @@ class BasicTestMappingProtocol(unittest.TestCase):
self
.
assertEqual
(
len
(
d
),
len
(
self
.
reference
))
#__contains__
for
k
in
self
.
reference
:
self
.
assert
True
(
k
in
d
)
self
.
assert
In
(
k
,
d
)
for
k
in
self
.
other
:
self
.
assert
False
(
k
in
d
)
self
.
assert
NotIn
(
k
,
d
)
#cmp
self
.
assertEqual
(
p
,
p
)
self
.
assertEqual
(
d
,
d
)
...
...
@@ -85,7 +85,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
knownkey
,
knownvalue
=
next
(
iter
(
self
.
other
.
items
()))
self
.
assertEqual
(
d
.
get
(
key
,
knownvalue
),
value
)
self
.
assertEqual
(
d
.
get
(
knownkey
,
knownvalue
),
knownvalue
)
self
.
assert
False
(
knownkey
in
d
)
self
.
assert
NotIn
(
knownkey
,
d
)
def
test_write
(
self
):
# Test for write operations on mapping
...
...
@@ -115,16 +115,16 @@ class BasicTestMappingProtocol(unittest.TestCase):
self
.
assertEqual
(
d
[
knownkey
],
knownvalue
)
#pop
self
.
assertEqual
(
d
.
pop
(
knownkey
),
knownvalue
)
self
.
assert
False
(
knownkey
in
d
)
self
.
assert
NotIn
(
knownkey
,
d
)
self
.
assertRaises
(
KeyError
,
d
.
pop
,
knownkey
)
default
=
909
d
[
knownkey
]
=
knownvalue
self
.
assertEqual
(
d
.
pop
(
knownkey
,
default
),
knownvalue
)
self
.
assert
False
(
knownkey
in
d
)
self
.
assert
NotIn
(
knownkey
,
d
)
self
.
assertEqual
(
d
.
pop
(
knownkey
,
default
),
default
)
#popitem
key
,
value
=
d
.
popitem
()
self
.
assert
False
(
key
in
d
)
self
.
assert
NotIn
(
key
,
d
)
self
.
assertEqual
(
value
,
self
.
reference
[
key
])
p
=
self
.
_empty_mapping
()
self
.
assertRaises
(
KeyError
,
p
.
popitem
)
...
...
@@ -142,8 +142,8 @@ class BasicTestMappingProtocol(unittest.TestCase):
d
=
self
.
_empty_mapping
()
self
.
assertEqual
(
list
(
d
.
keys
()),
[])
d
=
self
.
reference
self
.
assert
True
(
list
(
self
.
inmapping
.
keys
())[
0
]
in
d
.
keys
())
self
.
assert
True
(
list
(
self
.
other
.
keys
())[
0
]
not
in
d
.
keys
())
self
.
assert
In
(
list
(
self
.
inmapping
.
keys
())[
0
],
d
.
keys
())
self
.
assert
NotIn
(
list
(
self
.
other
.
keys
())[
0
],
d
.
keys
())
self
.
assertRaises
(
TypeError
,
d
.
keys
,
None
)
def
test_values
(
self
):
...
...
@@ -320,9 +320,9 @@ class TestMappingProtocol(BasicTestMappingProtocol):
self
.
assertEqual
(
list
(
d
.
keys
()),
[])
d
=
self
.
_full_mapping
({
'a'
:
1
,
'b'
:
2
})
k
=
d
.
keys
()
self
.
assert
True
(
'a'
in
k
)
self
.
assert
True
(
'b'
in
k
)
self
.
assert
True
(
'c'
not
in
k
)
self
.
assert
In
(
'a'
,
k
)
self
.
assert
In
(
'b'
,
k
)
self
.
assert
NotIn
(
'c'
,
k
)
def
test_values
(
self
):
BasicTestMappingProtocol
.
test_values
(
self
)
...
...
@@ -337,12 +337,13 @@ class TestMappingProtocol(BasicTestMappingProtocol):
def
test_contains
(
self
):
d
=
self
.
_empty_mapping
()
self
.
assertNotIn
(
'a'
,
d
)
self
.
assertTrue
(
not
(
'a'
in
d
))
self
.
assertTrue
(
'a'
not
in
d
)
d
=
self
.
_full_mapping
({
'a'
:
1
,
'b'
:
2
})
self
.
assert
True
(
'a'
in
d
)
self
.
assert
True
(
'b'
in
d
)
self
.
assert
True
(
'c'
not
in
d
)
self
.
assert
In
(
'a'
,
d
)
self
.
assert
In
(
'b'
,
d
)
self
.
assert
NotIn
(
'c'
,
d
)
self
.
assertRaises
(
TypeError
,
d
.
__contains__
)
...
...
Lib/test/pickletester.py
View file @
b58e0bd8
...
...
@@ -770,8 +770,8 @@ class AbstractPickleTests(unittest.TestCase):
# Dump using protocol 1 for comparison.
s1
=
self
.
dumps
(
x
,
1
)
self
.
assert
True
(
__name__
.
encode
(
"utf-8"
)
in
s1
)
self
.
assert
True
(
b"MyList"
in
s1
)
self
.
assert
In
(
__name__
.
encode
(
"utf-8"
),
s1
)
self
.
assert
In
(
b"MyList"
,
s1
)
self
.
assertEqual
(
opcode_in_pickle
(
opcode
,
s1
),
False
)
y
=
self
.
loads
(
s1
)
...
...
@@ -780,8 +780,8 @@ class AbstractPickleTests(unittest.TestCase):
# Dump using protocol 2 for test.
s2
=
self
.
dumps
(
x
,
2
)
self
.
assert
True
(
__name__
.
encode
(
"utf-8"
)
not
in
s2
)
self
.
assert
True
(
b"MyList"
not
in
s2
)
self
.
assert
NotIn
(
__name__
.
encode
(
"utf-8"
),
s2
)
self
.
assert
NotIn
(
b"MyList"
,
s2
)
self
.
assertEqual
(
opcode_in_pickle
(
opcode
,
s2
),
True
,
repr
(
s2
))
y
=
self
.
loads
(
s2
)
...
...
Lib/test/seq_tests.py
View file @
b58e0bd8
...
...
@@ -199,9 +199,9 @@ class CommonTest(unittest.TestCase):
def
test_contains
(
self
):
u
=
self
.
type2test
([
0
,
1
,
2
])
for
i
in
u
:
self
.
assert
_
(
i
in
u
)
self
.
assert
In
(
i
,
u
)
for
i
in
min
(
u
)
-
1
,
max
(
u
)
+
1
:
self
.
assert
_
(
i
not
in
u
)
self
.
assert
NotIn
(
i
,
u
)
self
.
assertRaises
(
TypeError
,
u
.
__contains__
)
...
...
@@ -213,8 +213,8 @@ class CommonTest(unittest.TestCase):
def
__eq__
(
self
,
other
):
return
True
__hash__
=
None
# Can't meet hash invariant requirements
self
.
assert
_
(
AllEq
()
not
in
self
.
type2test
([]))
self
.
assert
_
(
AllEq
()
in
self
.
type2test
([
1
]))
self
.
assert
NotIn
(
AllEq
(),
self
.
type2test
([]))
self
.
assert
In
(
AllEq
(),
self
.
type2test
([
1
]))
def
test_contains_order
(
self
):
# Sequences must test in-order. If a rich comparison has side
...
...
@@ -227,7 +227,7 @@ class CommonTest(unittest.TestCase):
raise
DoNotTestEq
checkfirst
=
self
.
type2test
([
1
,
StopCompares
()])
self
.
assert
_
(
1
in
checkfirst
)
self
.
assert
In
(
1
,
checkfirst
)
checklast
=
self
.
type2test
([
StopCompares
(),
1
])
self
.
assertRaises
(
DoNotTestEq
,
checklast
.
__contains__
,
1
)
...
...
Lib/test/test_bigmem.py
View file @
b58e0bd8
...
...
@@ -520,9 +520,9 @@ class BaseStrTest:
s
=
_
(
''
).
join
([
edge
,
SUBSTR
,
edge
])
del
edge
self
.
assertIn
(
SUBSTR
,
s
)
self
.
assert
False
(
SUBSTR
*
2
in
s
)
self
.
assert
NotIn
(
SUBSTR
*
2
,
s
)
self
.
assertIn
(
_
(
'-'
),
s
)
self
.
assert
False
(
_
(
'a'
)
in
s
)
self
.
assert
NotIn
(
_
(
'a'
),
s
)
s
+=
_
(
'a'
)
self
.
assertIn
(
_
(
'a'
),
s
)
...
...
@@ -769,8 +769,8 @@ class TupleTest(unittest.TestCase):
t
=
(
1
,
2
,
3
,
4
,
5
)
*
size
self
.
assertEquals
(
len
(
t
),
size
*
5
)
self
.
assertIn
(
5
,
t
)
self
.
assert
False
((
1
,
2
,
3
,
4
,
5
)
in
t
)
self
.
assert
False
(
0
in
t
)
self
.
assert
NotIn
((
1
,
2
,
3
,
4
,
5
),
t
)
self
.
assert
NotIn
(
0
,
t
)
@
bigmemtest
(
minsize
=
_2G
+
10
,
memuse
=
8
)
def
test_hash
(
self
,
size
):
...
...
@@ -918,8 +918,8 @@ class ListTest(unittest.TestCase):
l
=
[
1
,
2
,
3
,
4
,
5
]
*
size
self
.
assertEquals
(
len
(
l
),
size
*
5
)
self
.
assertIn
(
5
,
l
)
self
.
assert
False
([
1
,
2
,
3
,
4
,
5
]
in
l
)
self
.
assert
False
(
0
in
l
)
self
.
assert
NotIn
([
1
,
2
,
3
,
4
,
5
],
l
)
self
.
assert
NotIn
(
0
,
l
)
@
bigmemtest
(
minsize
=
_2G
+
10
,
memuse
=
8
)
def
test_hash
(
self
,
size
):
...
...
Lib/test/test_bytes.py
View file @
b58e0bd8
...
...
@@ -231,8 +231,7 @@ class BaseBytesTest(unittest.TestCase):
b
=
self
.
type2test
(
b"abc"
)
self
.
assertIn
(
ord
(
'a'
),
b
)
self
.
assertIn
(
int
(
ord
(
'a'
)),
b
)
self
.
assertFalse
(
200
in
b
)
self
.
assertFalse
(
200
in
b
)
self
.
assertNotIn
(
200
,
b
)
self
.
assertRaises
(
ValueError
,
lambda
:
300
in
b
)
self
.
assertRaises
(
ValueError
,
lambda
:
-
1
in
b
)
self
.
assertRaises
(
TypeError
,
lambda
:
None
in
b
)
...
...
@@ -246,10 +245,10 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertIn
(
f
(
b"ab"
),
b
)
self
.
assertIn
(
f
(
b"bc"
),
b
)
self
.
assertIn
(
f
(
b"abc"
),
b
)
self
.
assert
False
(
f
(
b"ac"
)
in
b
)
self
.
assert
False
(
f
(
b"d"
)
in
b
)
self
.
assert
False
(
f
(
b"dab"
)
in
b
)
self
.
assert
False
(
f
(
b"abd"
)
in
b
)
self
.
assert
NotIn
(
f
(
b"ac"
),
b
)
self
.
assert
NotIn
(
f
(
b"d"
),
b
)
self
.
assert
NotIn
(
f
(
b"dab"
),
b
)
self
.
assert
NotIn
(
f
(
b"abd"
),
b
)
def
test_fromhex
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
type2test
.
fromhex
)
...
...
Lib/test/test_cfgparser.py
View file @
b58e0bd8
...
...
@@ -76,8 +76,8 @@ class TestCaseBase(unittest.TestCase):
eq
(
cf
.
get
(
'Spaces'
,
'key with spaces'
),
'value'
)
eq
(
cf
.
get
(
'Spaces'
,
'another with spaces'
),
'splat!'
)
self
.
assert
False
(
'__name__'
in
cf
.
options
(
"Foo Bar"
),
'__name__ "option" should not be exposed by the API!'
)
self
.
assert
NotIn
(
'__name__'
,
cf
.
options
(
"Foo Bar"
),
'__name__ "option" should not be exposed by the API!'
)
# Make sure the right things happen for remove_option();
# added to include check for SourceForge bug #123324:
...
...
Lib/test/test_collections.py
View file @
b58e0bd8
...
...
@@ -540,10 +540,10 @@ class TestCounter(unittest.TestCase):
self
.
assertEqual
(
c
,
dict
(
a
=
4
,
b
=
0
,
d
=-
2
,
e
=-
5
,
f
=
4
))
self
.
assertEqual
(
''
.
join
(
sorted
(
c
.
elements
())),
'aaaaffff'
)
self
.
assertEqual
(
c
.
pop
(
'f'
),
4
)
self
.
assert
Equal
(
'f'
in
c
,
False
)
self
.
assert
NotIn
(
'f'
,
c
)
for
i
in
range
(
3
):
elem
,
cnt
=
c
.
popitem
()
self
.
assert
Equal
(
elem
in
c
,
False
)
self
.
assert
NotIn
(
elem
,
c
)
c
.
clear
()
self
.
assertEqual
(
c
,
{})
self
.
assertEqual
(
repr
(
c
),
'Counter()'
)
...
...
Lib/test/test_compile.py
View file @
b58e0bd8
...
...
@@ -317,56 +317,56 @@ if 1:
d
[
1
]
+=
1
self
.
assertEqual
(
d
[
1
],
2
)
del
d
[
1
]
self
.
assert
Equal
(
1
in
d
,
False
)
self
.
assert
NotIn
(
1
,
d
)
# Tuple of indices
d
[
1
,
1
]
=
1
self
.
assertEqual
(
d
[
1
,
1
],
1
)
d
[
1
,
1
]
+=
1
self
.
assertEqual
(
d
[
1
,
1
],
2
)
del
d
[
1
,
1
]
self
.
assert
Equal
((
1
,
1
)
in
d
,
False
)
self
.
assert
NotIn
((
1
,
1
),
d
)
# Simple slice
d
[
1
:
2
]
=
1
self
.
assertEqual
(
d
[
1
:
2
],
1
)
d
[
1
:
2
]
+=
1
self
.
assertEqual
(
d
[
1
:
2
],
2
)
del
d
[
1
:
2
]
self
.
assert
Equal
(
slice
(
1
,
2
)
in
d
,
False
)
self
.
assert
NotIn
(
slice
(
1
,
2
),
d
)
# Tuple of simple slices
d
[
1
:
2
,
1
:
2
]
=
1
self
.
assertEqual
(
d
[
1
:
2
,
1
:
2
],
1
)
d
[
1
:
2
,
1
:
2
]
+=
1
self
.
assertEqual
(
d
[
1
:
2
,
1
:
2
],
2
)
del
d
[
1
:
2
,
1
:
2
]
self
.
assert
Equal
((
slice
(
1
,
2
),
slice
(
1
,
2
))
in
d
,
False
)
self
.
assert
NotIn
((
slice
(
1
,
2
),
slice
(
1
,
2
)),
d
)
# Extended slice
d
[
1
:
2
:
3
]
=
1
self
.
assertEqual
(
d
[
1
:
2
:
3
],
1
)
d
[
1
:
2
:
3
]
+=
1
self
.
assertEqual
(
d
[
1
:
2
:
3
],
2
)
del
d
[
1
:
2
:
3
]
self
.
assert
Equal
(
slice
(
1
,
2
,
3
)
in
d
,
False
)
self
.
assert
NotIn
(
slice
(
1
,
2
,
3
),
d
)
# Tuple of extended slices
d
[
1
:
2
:
3
,
1
:
2
:
3
]
=
1
self
.
assertEqual
(
d
[
1
:
2
:
3
,
1
:
2
:
3
],
1
)
d
[
1
:
2
:
3
,
1
:
2
:
3
]
+=
1
self
.
assertEqual
(
d
[
1
:
2
:
3
,
1
:
2
:
3
],
2
)
del
d
[
1
:
2
:
3
,
1
:
2
:
3
]
self
.
assert
Equal
((
slice
(
1
,
2
,
3
),
slice
(
1
,
2
,
3
))
in
d
,
False
)
self
.
assert
NotIn
((
slice
(
1
,
2
,
3
),
slice
(
1
,
2
,
3
)),
d
)
# Ellipsis
d
[...]
=
1
self
.
assertEqual
(
d
[...],
1
)
d
[...]
+=
1
self
.
assertEqual
(
d
[...],
2
)
del
d
[...]
self
.
assert
Equal
(
Ellipsis
in
d
,
False
)
self
.
assert
NotIn
(
Ellipsis
,
d
)
# Tuple of Ellipses
d
[...,
...]
=
1
self
.
assertEqual
(
d
[...,
...],
1
)
d
[...,
...]
+=
1
self
.
assertEqual
(
d
[...,
...],
2
)
del
d
[...,
...]
self
.
assert
Equal
((
Ellipsis
,
Ellipsis
)
in
d
,
False
)
self
.
assert
NotIn
((
Ellipsis
,
Ellipsis
),
d
)
def
test_annotation_limit
(
self
):
# 16 bits are available for # of annotations, but only 8 bits are
...
...
Lib/test/test_copy.py
View file @
b58e0bd8
...
...
@@ -627,7 +627,7 @@ class TestCopy(unittest.TestCase):
x
,
y
=
C
(),
C
()
# The underlying containers are decoupled
v
[
x
]
=
y
self
.
assert
False
(
x
in
u
)
self
.
assert
NotIn
(
x
,
u
)
def
test_copy_weakkeydict
(
self
):
self
.
_check_copy_weakdict
(
weakref
.
WeakKeyDictionary
)
...
...
Lib/test/test_datetime.py
View file @
b58e0bd8
...
...
@@ -140,10 +140,7 @@ class HarmlessMixedComparison:
self
.
assertTrue
(()
!=
me
)
self
.
assertIn
(
me
,
[
1
,
20
,
[],
me
])
self
.
assertFalse
(
me
not
in
[
1
,
20
,
[],
me
])
self
.
assertIn
([],
[
me
,
1
,
20
,
[]])
self
.
assertFalse
([]
not
in
[
me
,
1
,
20
,
[]])
def
test_harmful_mixed_comparison
(
self
):
me
=
self
.
theclass
(
1
,
1
,
1
)
...
...
Lib/test/test_dbm.py
View file @
b58e0bd8
...
...
@@ -93,7 +93,7 @@ class AnyDBMTestCase(unittest.TestCase):
self
.
init_db
()
f
=
dbm
.
open
(
_fname
,
'r'
)
key
=
"a"
.
encode
(
"ascii"
)
assert
(
key
in
f
)
self
.
assertIn
(
key
,
f
)
assert
(
f
[
key
]
==
b"Python:"
)
f
.
close
()
...
...
Lib/test/test_descr.py
View file @
b58e0bd8
...
...
@@ -1654,7 +1654,7 @@ order (MRO) for bases """
self
.
assertNotIn
(
-
1
,
c1
)
for
i
in
range
(
10
):
self
.
assertIn
(
i
,
c1
)
self
.
assert
False
(
10
in
c1
)
self
.
assert
NotIn
(
10
,
c1
)
# Test the default behavior for dynamic classes
class
D
(
object
):
def
__getitem__
(
self
,
i
):
...
...
@@ -1677,7 +1677,7 @@ order (MRO) for bases """
self
.
assertNotIn
(
-
1
,
d1
)
for
i
in
range
(
10
):
self
.
assertIn
(
i
,
d1
)
self
.
assert
False
(
10
in
d1
)
self
.
assert
NotIn
(
10
,
d1
)
# Test overridden behavior
class
Proxy
(
object
):
def
__init__
(
self
,
x
):
...
...
@@ -1721,10 +1721,10 @@ order (MRO) for bases """
self
.
assertEqual
(
str
(
p0
),
"Proxy:0"
)
self
.
assertEqual
(
repr
(
p0
),
"Proxy(0)"
)
p10
=
Proxy
(
range
(
10
))
self
.
assert
False
(
-
1
in
p10
)
self
.
assert
NotIn
(
-
1
,
p10
)
for
i
in
range
(
10
):
self
.
assertIn
(
i
,
p10
)
self
.
assert
False
(
10
in
p10
)
self
.
assert
NotIn
(
10
,
p10
)
def
test_weakrefs
(
self
):
# Testing weak references...
...
...
Lib/test/test_dict.py
View file @
b58e0bd8
...
...
@@ -34,9 +34,7 @@ class DictTest(unittest.TestCase):
self
.
assertEqual
(
set
(
d
.
keys
()),
set
())
d
=
{
'a'
:
1
,
'b'
:
2
}
k
=
d
.
keys
()
self
.
assertTrue
(
'a'
in
d
)
self
.
assertIn
(
'a'
,
d
)
self
.
assertTrue
(
'b'
in
d
)
self
.
assertIn
(
'b'
,
d
)
self
.
assertRaises
(
TypeError
,
d
.
keys
,
None
)
self
.
assertEqual
(
repr
(
dict
(
a
=
1
).
keys
()),
"dict_keys(['a'])"
)
...
...
@@ -60,15 +58,12 @@ class DictTest(unittest.TestCase):
def
test_contains
(
self
):
d
=
{}
self
.
assertNotIn
(
'a'
,
d
)
self
.
assertTrue
(
not
(
'a'
in
d
))
self
.
assertTrue
(
'a'
not
in
d
)
self
.
assertNotIn
(
'a'
,
d
)
d
=
{
'a'
:
1
,
'b'
:
2
}
self
.
assertTrue
(
'a'
in
d
)
self
.
assertIn
(
'a'
,
d
)
self
.
assertTrue
(
'b'
in
d
)
self
.
assertIn
(
'b'
,
d
)
self
.
assertTrue
(
'c'
not
in
d
)
self
.
assertNotIn
(
'c'
,
d
)
self
.
assertRaises
(
TypeError
,
d
.
__contains__
)
...
...
@@ -524,9 +519,7 @@ class DictTest(unittest.TestCase):
d
=
D
({
1
:
2
,
3
:
4
})
self
.
assertEqual
(
d
[
1
],
2
)
self
.
assertEqual
(
d
[
3
],
4
)
self
.
assertTrue
(
2
not
in
d
)
self
.
assertNotIn
(
2
,
d
)
self
.
assertTrue
(
2
not
in
d
.
keys
())
self
.
assertNotIn
(
2
,
d
.
keys
())
self
.
assertEqual
(
d
[
2
],
42
)
class
E
(
dict
):
...
...
Lib/test/test_dis.py
View file @
b58e0bd8
...
...
@@ -118,8 +118,8 @@ class DisTests(unittest.TestCase):
def
test_opmap
(
self
):
self
.
assertEqual
(
dis
.
opmap
[
"STOP_CODE"
],
0
)
self
.
assert
Equal
(
dis
.
opmap
[
"LOAD_CONST"
]
in
dis
.
hasconst
,
True
)
self
.
assert
Equal
(
dis
.
opmap
[
"STORE_NAME"
]
in
dis
.
hasname
,
Tru
e
)
self
.
assert
In
(
dis
.
opmap
[
"LOAD_CONST"
],
dis
.
hasconst
)
self
.
assert
In
(
dis
.
opmap
[
"STORE_NAME"
],
dis
.
hasnam
e
)
def
test_opname
(
self
):
self
.
assertEqual
(
dis
.
opname
[
dis
.
opmap
[
"LOAD_FAST"
]],
"LOAD_FAST"
)
...
...
Lib/test/test_docxmlrpc.py
View file @
b58e0bd8
...
...
@@ -18,8 +18,8 @@ def server(evt, numrequests):
serv
.
set_server_title
(
"DocXMLRPCServer Test Documentation"
)
serv
.
set_server_name
(
"DocXMLRPCServer Test Docs"
)
serv
.
set_server_documentation
(
"""This is an XML-RPC server's documentation, but the server can be used by
POSTing to /RPC2. Try self.add, too.""
"
)
"This is an XML-RPC server's documentation, but the server "
"can be used by POSTing to /RPC2. Try self.add, too.
"
)
# Create and register classes and functions
class
TestClass
(
object
):
...
...
@@ -106,9 +106,9 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
self
.
client
.
request
(
"GET"
,
"/"
)
response
=
self
.
client
.
getresponse
()
self
.
assert
True
(
b"""<dl><dt><a name="-<lambda>"><strong><lambda></strong></a>(x, y)</dt></dl>"""
in
response
.
read
())
self
.
assert
In
((
b'<dl><dt><a name="-<lambda>"><strong>'
b'<lambda></strong></a>(x, y)</dt></dl>'
),
response
.
read
())
def
test_autolinking
(
self
):
"""Test that the server correctly automatically wraps references to PEPS
...
...
@@ -120,9 +120,17 @@ b"""<dl><dt><a name="-<lambda>"><strong><lambda></strong></a>(x, y)<
self
.
client
.
request
(
"GET"
,
"/"
)
response
=
self
.
client
.
getresponse
().
read
()
self
.
assertTrue
(
# This is ugly ... how can it be made better?
b"""<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd><tt>Add two instances together. This follows <a href="http://www.python.org/dev/peps/pep-0008/">PEP008</a>, but has nothing<br>
\
n
to do with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">RFC1952</a>. Case should matter: pEp008 and rFC1952. Things<br>
\
n
that start with http and ftp should be auto-linked, too:<br>
\
n
<a href="http://google.com">http://google.com</a>.</tt></dd></dl>"""
in
response
,
response
)
self
.
assertIn
(
(
b'<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd>'
b'<tt>Add two instances together. This '
b'follows <a href="http://www.python.org/dev/peps/pep-0008/">'
b'PEP008</a>, but has nothing<br>
\
n
to do '
b'with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">'
b'RFC1952</a>. Case should matter: pEp008 '
b'and rFC1952. Things<br>
\
n
that start '
b'with http and ftp should be '
b'auto-linked, too:<br>
\
n
<a href="http://google.com">'
b'http://google.com</a>.</tt></dd></dl>'
),
response
)
def
test_system_methods
(
self
):
"""Test the precense of three consecutive system.* methods.
...
...
@@ -133,8 +141,26 @@ b"""<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd><tt>Add t
self
.
client
.
request
(
"GET"
,
"/"
)
response
=
self
.
client
.
getresponse
().
read
()
self
.
assertTrue
(
b"""<dl><dt><a name="-system.methodHelp"><strong>system.methodHelp</strong></a>(method_name)</dt><dd><tt><a href="#-system.methodHelp">system.methodHelp</a>(
\
'
add
\
'
) => "Adds two integers together"<br>
\
n
<br>
\
n
Returns a string containing documentation for the specified method.</tt></dd></dl>
\
n
<dl><dt><a name="-system.methodSignature"><strong>system.methodSignature</strong></a>(method_name)</dt><dd><tt><a href="#-system.methodSignature">system.methodSignature</a>(
\
'
add
\
'
) => [double, int, int]<br>
\
n
<br>
\
n
Returns a list describing the signature of the method. In the<br>
\
n
above example, the add method takes two integers as arguments<br>
\
n
and returns a double result.<br>
\
n
<br>
\
n
This server does NOT support system.methodSignature.</tt></dd></dl>
\
n
<dl><dt><a name="-test_method"><strong>test_method</strong></a>(arg)</dt><dd><tt>Test method
\
'
s docs. This method truly does very little.</tt></dd></dl>"""
in
response
)
self
.
assertIn
(
(
b'<dl><dt><a name="-system.methodHelp"><strong>system.methodHelp'
b'</strong></a>(method_name)</dt><dd><tt><a href="#-system.method'
b'Help">system.methodHelp</a>(
\
'
add
\
'
) => "Adds '
b'two integers together"<br>
\
n
<br>
\
n
Returns a'
b' string containing documentation for '
b'the specified method.</tt></dd></dl>
\
n
<dl><dt><a name'
b'="-system.methodSignature"><strong>system.methodSignature</strong>'
b'</a>(method_name)</dt><dd><tt><a href="#-system.methodSignature">'
b'system.methodSignature</a>(
\
'
add
\
'
) => [double, '
b'int, int]<br>
\
n
<br>
\
n
Returns a list '
b'describing the signature of the method.'
b' In the<br>
\
n
above example, the add '
b'method takes two integers as arguments'
b'<br>
\
n
and returns a double result.<br>
\
n
'
b'<br>
\
n
This server does NOT support system'
b'.methodSignature.</tt></dd></dl>
\
n
<dl><dt><a name="-test_method">'
b'<strong>test_method</strong></a>(arg)</dt><dd><tt>Test '
b'method
\
'
s docs. This method truly does'
b' very little.</tt></dd></dl>'
),
response
)
def
test_autolink_dotted_methods
(
self
):
"""Test that selfdot values are made strong automatically in the
...
...
@@ -142,8 +168,8 @@ b"""<dl><dt><a name="-system.methodHelp"><strong>system.methodHelp</strong></a>(
self
.
client
.
request
(
"GET"
,
"/"
)
response
=
self
.
client
.
getresponse
()
self
.
assert
True
(
b"""Try self.<strong>add</strong>, too."""
in
response
.
read
())
self
.
assert
In
(
b"""Try self.<strong>add</strong>, too."""
,
response
.
read
())
def
test_main
():
support
.
run_unittest
(
DocXMLRPCHTTPGETServer
)
...
...
Lib/test/test_errno.py
View file @
b58e0bd8
...
...
@@ -28,8 +28,8 @@ class ErrorcodeTests(unittest.TestCase):
def
test_attributes_in_errorcode
(
self
):
for
attribute
in
errno
.
__dict__
.
keys
():
if
attribute
.
isupper
():
self
.
assert
True
(
getattr
(
errno
,
attribute
)
in
errno
.
errorcode
,
'no %s attr in errno.errorcode'
%
attribute
)
self
.
assert
In
(
getattr
(
errno
,
attribute
),
errno
.
errorcode
,
'no %s attr in errno.errorcode'
%
attribute
)
def
test_main
():
...
...
Lib/test/test_exceptions.py
View file @
b58e0bd8
...
...
@@ -413,7 +413,7 @@ class ExceptionTests(unittest.TestCase):
except
Exception
as
e
:
self
.
assertTrue
(
e
)
del
e
self
.
assert
False
(
'e'
in
locals
())
self
.
assert
NotIn
(
'e'
,
locals
())
def
testExceptionCleanupState
(
self
):
# Make sure exception state is cleaned up as soon as the except
...
...
Lib/test/test_float.py
View file @
b58e0bd8
...
...
@@ -214,16 +214,11 @@ class GeneralFloatCases(unittest.TestCase):
floats
=
(
INF
,
-
INF
,
0.0
,
1.0
,
NAN
)
for
f
in
floats
:
self
.
assertIn
(
f
,
[
f
])
self
.
assertTrue
(
f
in
[
f
],
"'%r' not in []"
%
f
)
self
.
assertIn
(
f
,
(
f
,))
self
.
assertTrue
(
f
in
(
f
,),
"'%r' not in ()"
%
f
)
self
.
assertIn
(
f
,
{
f
})
self
.
assertTrue
(
f
in
{
f
},
"'%r' not in set()"
%
f
)
self
.
assertIn
(
f
,
{
f
:
None
})
self
.
assertTrue
(
f
in
{
f
:
None
},
"'%r' not in {}"
%
f
)
self
.
assertEqual
([
f
].
count
(
f
),
1
,
"[].count('%r') != 1"
%
f
)
self
.
assertIn
(
f
,
floats
)
self
.
assertTrue
(
f
in
floats
,
"'%r' not in container"
%
f
)
for
f
in
floats
:
# nonidentical containers, same type, same contents
...
...
@@ -459,10 +454,10 @@ class FormatFunctionsTestCase(unittest.TestCase):
float
.
__setformat__
(
'float'
,
self
.
save_formats
[
'float'
])
def
test_getformat
(
self
):
self
.
assert
True
(
float
.
__getformat__
(
'double'
)
in
[
'unknown'
,
'IEEE, big-endian'
,
'IEEE, little-endian'
])
self
.
assert
True
(
float
.
__getformat__
(
'float'
)
in
[
'unknown'
,
'IEEE, big-endian'
,
'IEEE, little-endian'
])
self
.
assert
In
(
float
.
__getformat__
(
'double'
),
[
'unknown'
,
'IEEE, big-endian'
,
'IEEE, little-endian'
])
self
.
assert
In
(
float
.
__getformat__
(
'float'
),
[
'unknown'
,
'IEEE, big-endian'
,
'IEEE, little-endian'
])
self
.
assertRaises
(
ValueError
,
float
.
__getformat__
,
'chicken'
)
self
.
assertRaises
(
TypeError
,
float
.
__getformat__
,
1
)
...
...
Lib/test/test_http_cookiejar.py
View file @
b58e0bd8
...
...
@@ -901,8 +901,7 @@ class CookieTests(TestCase):
url
=
"http://foo.bar.com/"
interact_2965
(
c
,
url
,
"spam=eggs; Version=1"
)
h
=
interact_2965
(
c
,
url
)
self
.
assertTrue
(
"Path"
not
in
h
,
"absent path returned with path present"
)
self
.
assertNotIn
(
"Path"
,
h
,
"absent path returned with path present"
)
c
=
CookieJar
(
pol
)
url
=
"http://foo.bar.com/"
...
...
@@ -917,8 +916,7 @@ class CookieTests(TestCase):
url
=
"http://foo.bar.com/"
interact_2965
(
c
,
url
,
"spam=eggs; Version=1"
)
h
=
interact_2965
(
c
,
url
)
self
.
assertTrue
(
"Port"
not
in
h
,
"absent port returned with port present"
)
self
.
assertNotIn
(
"Port"
,
h
,
"absent port returned with port present"
)
c
=
CookieJar
(
pol
)
url
=
"http://foo.bar.com/"
...
...
@@ -931,16 +929,16 @@ class CookieTests(TestCase):
url
=
"http://foo.bar.com/"
interact_2965
(
c
,
url
,
'spam=eggs; Version=1; Port="80"'
)
h
=
interact_2965
(
c
,
url
)
self
.
assert
True
(
'$Port="80"'
in
h
,
"port with single value not returned with single value"
)
self
.
assert
In
(
'$Port="80"'
,
h
,
"port with single value not returned with single value"
)
c
=
CookieJar
(
pol
)
url
=
"http://foo.bar.com/"
interact_2965
(
c
,
url
,
'spam=eggs; Version=1; Port="80,8080"'
)
h
=
interact_2965
(
c
,
url
)
self
.
assert
True
(
'$Port="80,8080"'
in
h
,
"port with multiple values not returned with multiple "
"values"
)
self
.
assert
In
(
'$Port="80,8080"'
,
h
,
"port with multiple values not returned with multiple "
"values"
)
def
test_no_return_comment
(
self
):
c
=
CookieJar
(
DefaultCookiePolicy
(
rfc2965
=
True
))
...
...
@@ -1105,8 +1103,8 @@ class LWPCookieTests(TestCase):
c
.
add_cookie_header
(
req
)
h
=
req
.
get_header
(
"Cookie"
)
self
.
assert
True
(
"PART_NUMBER=ROCKET_LAUNCHER_0001"
in
h
and
"CUSTOMER=WILE_E_COYOTE"
in
h
)
self
.
assert
In
(
"PART_NUMBER=ROCKET_LAUNCHER_0001"
,
h
)
self
.
assertIn
(
"CUSTOMER=WILE_E_COYOTE"
,
h
)
headers
.
append
(
'Set-Cookie: SHIPPING=FEDEX; path=/foo'
)
res
=
FakeResponse
(
headers
,
"http://www.acme.com"
)
...
...
@@ -1116,17 +1114,17 @@ class LWPCookieTests(TestCase):
c
.
add_cookie_header
(
req
)
h
=
req
.
get_header
(
"Cookie"
)
self
.
assert
True
(
"PART_NUMBER=ROCKET_LAUNCHER_0001"
in
h
and
"CUSTOMER=WILE_E_COYOTE"
in
h
and
"SHIPPING=FEDEX"
not
in
h
)
self
.
assert
In
(
"PART_NUMBER=ROCKET_LAUNCHER_0001"
,
h
)
self
.
assertIn
(
"CUSTOMER=WILE_E_COYOTE"
,
h
)
self
.
assertNotIn
(
"SHIPPING=FEDEX"
,
h
)
req
=
urllib
.
request
.
Request
(
"http://www.acme.com/foo/"
)
c
.
add_cookie_header
(
req
)
h
=
req
.
get_header
(
"Cookie"
)
self
.
assert
True
((
"PART_NUMBER=ROCKET_LAUNCHER_0001"
in
h
and
"CUSTOMER=WILE_E_COYOTE"
in
h
and
h
.
startswith
(
"SHIPPING=FEDEX;"
)
))
self
.
assert
In
(
"PART_NUMBER=ROCKET_LAUNCHER_0001"
,
h
)
self
.
assertIn
(
"CUSTOMER=WILE_E_COYOTE"
,
h
)
self
.
assertTrue
(
h
.
startswith
(
"SHIPPING=FEDEX;"
))
def
test_netscape_example_2
(
self
):
# Second Example transaction sequence:
...
...
@@ -1344,8 +1342,8 @@ class LWPCookieTests(TestCase):
# the server.
cookie = interact_2965(c, "
http
:
//
www
.
acme
.
com
/
acme
/
parts
/
")
self.assert
True("
Rocket_Launcher_0001
" in cookie and
"
Riding_Rocket_0023
" not in
cookie)
self.assert
In("
Rocket_Launcher_0001
", cookie)
self.assertNotIn("
Riding_Rocket_0023
",
cookie)
def test_rejection(self):
# Test rejection of Set-Cookie2 responses based on domain, path, port.
...
...
Lib/test/test_inspect.py
View file @
b58e0bd8
...
...
@@ -474,8 +474,8 @@ class TestClassesAndFunctions(unittest.TestCase):
self
.
assertIn
((
's'
,
'static method'
,
A
),
attrs
,
'missing static method'
)
self
.
assertIn
((
'c'
,
'class method'
,
A
),
attrs
,
'missing class method'
)
self
.
assertIn
((
'p'
,
'property'
,
A
),
attrs
,
'missing property'
)
self
.
assert
True
((
'm'
,
'method'
,
A
)
in
attrs
,
'missing plain method: %r'
%
attrs
)
self
.
assert
In
((
'm'
,
'method'
,
A
),
attrs
,
'missing plain method: %r'
%
attrs
)
self
.
assertIn
((
'm1'
,
'method'
,
A
),
attrs
,
'missing plain method'
)
self
.
assertIn
((
'datablob'
,
'data'
,
A
),
attrs
,
'missing data'
)
...
...
Lib/test/test_itertools.py
View file @
b58e0bd8
...
...
@@ -1405,7 +1405,7 @@ class SubclassWithKwargsTest(unittest.TestCase):
Subclass
(
newarg
=
1
)
except
TypeError
as
err
:
# we expect type errors because of wrong argument count
self
.
assert
False
(
"does not take keyword arguments"
in
err
.
args
[
0
])
self
.
assert
NotIn
(
"does not take keyword arguments"
,
err
.
args
[
0
])
libreftest
=
""" Doctest for examples in the library reference: libitertools.tex
...
...
Lib/test/test_multibytecodec.py
View file @
b58e0bd8
...
...
@@ -242,7 +242,7 @@ class Test_ISO2022(unittest.TestCase):
self
.
assertEqual
(
iso2022jp2
.
decode
(
'iso2022-jp-2'
),
uni
)
def
test_iso2022_jp_g0
(
self
):
self
.
assert
False
(
b'
\
x0e
'
in
'
\
N{SOFT HYPHEN}
'
.
encode
(
'iso-2022-jp-2'
))
self
.
assert
NotIn
(
b'
\
x0e
'
,
'
\
N{SOFT HYPHEN}
'
.
encode
(
'iso-2022-jp-2'
))
for
encoding
in
(
'iso-2022-jp-2004'
,
'iso-2022-jp-3'
):
e
=
'
\
u3406
'
.
encode
(
encoding
)
self
.
assertFalse
(
any
(
x
>
0x80
for
x
in
e
))
...
...
Lib/test/test_pep352.py
View file @
b58e0bd8
...
...
@@ -38,8 +38,8 @@ class ExceptionClassTests(unittest.TestCase):
last_exc
=
getattr
(
builtins
,
superclass_name
)
except
AttributeError
:
self
.
fail
(
"base class %s not a built-in"
%
superclass_name
)
self
.
assert
True
(
superclass_name
in
exc_set
,
'%s not found'
%
superclass_name
)
self
.
assert
In
(
superclass_name
,
exc_set
,
'%s not found'
%
superclass_name
)
exc_set
.
discard
(
superclass_name
)
superclasses
=
[]
# Loop will insert base exception
last_depth
=
0
...
...
Lib/test/test_pkgimport.py
View file @
b58e0bd8
...
...
@@ -51,9 +51,9 @@ class TestImport(unittest.TestCase):
self
.
rewrite_file
(
'for'
)
try
:
__import__
(
self
.
module_name
)
except
SyntaxError
:
pass
else
:
raise
RuntimeError
(
'Failed to induce SyntaxError'
)
self
.
assert
True
(
self
.
module_name
not
in
sys
.
modules
and
not
hasattr
(
sys
.
modules
[
self
.
package_name
],
'foo'
))
else
:
raise
RuntimeError
(
'Failed to induce SyntaxError'
)
# self.fail()?
self
.
assert
NotIn
(
self
.
module_name
,
sys
.
modules
)
self
.
assertFalse
(
hasattr
(
sys
.
modules
[
self
.
package_name
],
'foo'
))
# ...make up a variable name that isn't bound in __builtins__
var
=
'a'
...
...
Lib/test/test_profile.py
View file @
b58e0bd8
...
...
@@ -72,7 +72,7 @@ class ProfileTest(unittest.TestCase):
stats
=
pstats
.
Stats
(
prof
,
stream
=
s
)
stats
.
print_stats
()
res
=
s
.
getvalue
()
self
.
assert
True
(
self
.
expected_max_output
in
res
,
self
.
assert
In
(
self
.
expected_max_output
,
res
,
"Profiling {0!r} didn't report max:
\
n
{1}"
.
format
(
stmt
,
res
))
...
...
Lib/test/test_pyclbr.py
View file @
b58e0bd8
...
...
@@ -41,7 +41,6 @@ class PyclbrTest(TestCase):
if
key
not
in
obj
:
print
(
"***"
,
key
,
file
=
sys
.
stderr
)
self
.
assertIn
(
key
,
obj
)
self
.
assertTrue
(
key
in
obj
,
"%r in %r"
%
(
key
,
obj
))
def
assertEqualsOrIgnored
(
self
,
a
,
b
,
ignore
):
''' succeed iff a == b or a in ignore or b in ignore '''
...
...
Lib/test/test_range.py
View file @
b58e0bd8
...
...
@@ -126,7 +126,7 @@ class RangeTest(unittest.TestCase):
class
C2
:
def
__int__
(
self
):
return
1
def
__index__
(
self
):
return
1
self
.
assert
False
(
C2
()
in
range
(
3
))
self
.
assert
NotIn
(
C2
(),
range
(
3
))
# ..except if explicitly told so.
self
.
assertIn
(
int
(
C2
()),
range
(
3
))
...
...
@@ -140,32 +140,32 @@ class RangeTest(unittest.TestCase):
def
test_strided_limits
(
self
):
r
=
range
(
0
,
101
,
2
)
self
.
assertIn
(
0
,
r
)
self
.
assert
False
(
1
in
r
)
self
.
assert
NotIn
(
1
,
r
)
self
.
assertIn
(
2
,
r
)
self
.
assert
False
(
99
in
r
)
self
.
assert
NotIn
(
99
,
r
)
self
.
assertIn
(
100
,
r
)
self
.
assert
False
(
101
in
r
)
self
.
assert
NotIn
(
101
,
r
)
r
=
range
(
0
,
-
20
,
-
1
)
self
.
assertIn
(
0
,
r
)
self
.
assertIn
(
-
1
,
r
)
self
.
assertIn
(
-
19
,
r
)
self
.
assert
False
(
-
20
in
r
)
self
.
assert
NotIn
(
-
20
,
r
)
r
=
range
(
0
,
-
20
,
-
2
)
self
.
assertIn
(
-
18
,
r
)
self
.
assert
False
(
-
19
in
r
)
self
.
assert
False
(
-
20
in
r
)
self
.
assert
NotIn
(
-
19
,
r
)
self
.
assert
NotIn
(
-
20
,
r
)
def
test_empty
(
self
):
r
=
range
(
0
)
self
.
assert
False
(
0
in
r
)
self
.
assert
False
(
1
in
r
)
self
.
assert
NotIn
(
0
,
r
)
self
.
assert
NotIn
(
1
,
r
)
r
=
range
(
0
,
-
10
)
self
.
assert
False
(
0
in
r
)
self
.
assert
False
(
-
1
in
r
)
self
.
assert
False
(
1
in
r
)
self
.
assert
NotIn
(
0
,
r
)
self
.
assert
NotIn
(
-
1
,
r
)
self
.
assert
NotIn
(
1
,
r
)
def
test_range_iterators
(
self
):
# exercise 'fast' iterators, that use a rangeiterobject internally.
...
...
Lib/test/test_sax.py
View file @
b58e0bd8
...
...
@@ -30,7 +30,7 @@ class XmlTestBase(unittest.TestCase):
self
.
assertEquals
(
attrs
.
getNames
(),
[])
self
.
assertEquals
(
attrs
.
getQNames
(),
[])
self
.
assertEquals
(
len
(
attrs
),
0
)
self
.
assert
False
(
"attr"
in
attrs
)
self
.
assert
NotIn
(
"attr"
,
attrs
)
self
.
assertEquals
(
list
(
attrs
.
keys
()),
[])
self
.
assertEquals
(
attrs
.
get
(
"attrs"
),
None
)
self
.
assertEquals
(
attrs
.
get
(
"attrs"
,
25
),
25
)
...
...
@@ -47,7 +47,7 @@ class XmlTestBase(unittest.TestCase):
self
.
assertEquals
(
attrs
.
getNames
(),
[])
self
.
assertEquals
(
attrs
.
getQNames
(),
[])
self
.
assertEquals
(
len
(
attrs
),
0
)
self
.
assert
False
((
ns_uri
,
"attr"
)
in
attrs
)
self
.
assert
NotIn
((
ns_uri
,
"attr"
),
attrs
)
self
.
assertEquals
(
list
(
attrs
.
keys
()),
[])
self
.
assertEquals
(
attrs
.
get
((
ns_uri
,
"attr"
)),
None
)
self
.
assertEquals
(
attrs
.
get
((
ns_uri
,
"attr"
),
25
),
25
)
...
...
Lib/test/test_site.py
View file @
b58e0bd8
...
...
@@ -63,14 +63,14 @@ class HelperFunctionsTests(unittest.TestCase):
dir_set
=
site
.
_init_pathinfo
()
for
entry
in
[
site
.
makepath
(
path
)[
1
]
for
path
in
sys
.
path
if
path
and
os
.
path
.
isdir
(
path
)]:
self
.
assert
True
(
entry
in
dir_set
,
"%s from sys.path not found in set returned "
"by _init_pathinfo(): %s"
%
(
entry
,
dir_set
))
self
.
assert
In
(
entry
,
dir_set
,
"%s from sys.path not found in set returned "
"by _init_pathinfo(): %s"
%
(
entry
,
dir_set
))
def
pth_file_tests
(
self
,
pth_file
):
"""Contain common code for testing results of reading a .pth file"""
self
.
assert
True
(
pth_file
.
imported
in
sys
.
modules
,
"%s not in sys.modules"
%
pth_file
.
imported
)
self
.
assert
In
(
pth_file
.
imported
,
sys
.
modules
,
"%s not in sys.modules"
%
pth_file
.
imported
)
self
.
assertIn
(
site
.
makepath
(
pth_file
.
good_dir_path
)[
0
],
sys
.
path
)
self
.
assertFalse
(
os
.
path
.
exists
(
pth_file
.
bad_dir_path
))
...
...
Lib/test/test_strptime.py
View file @
b58e0bd8
...
...
@@ -36,8 +36,8 @@ class LocaleTime_Tests(unittest.TestCase):
"""
strftime_output
=
time
.
strftime
(
directive
,
self
.
time_tuple
).
lower
()
comparison
=
testing
[
self
.
time_tuple
[
tuple_position
]]
self
.
assert
True
(
strftime_output
in
testing
,
"%s: not found in tuple"
%
error_msg
)
self
.
assert
In
(
strftime_output
,
testing
,
"%s: not found in tuple"
%
error_msg
)
self
.
assertTrue
(
comparison
==
strftime_output
,
"%s: position within tuple incorrect; %s != %s"
%
(
error_msg
,
comparison
,
strftime_output
))
...
...
@@ -61,8 +61,8 @@ class LocaleTime_Tests(unittest.TestCase):
def
test_am_pm
(
self
):
# Make sure AM/PM representation done properly
strftime_output
=
time
.
strftime
(
"%p"
,
self
.
time_tuple
).
lower
()
self
.
assert
True
(
strftime_output
in
self
.
LT_ins
.
am_pm
,
"AM/PM representation not in tuple"
)
self
.
assert
In
(
strftime_output
,
self
.
LT_ins
.
am_pm
,
"AM/PM representation not in tuple"
)
if
self
.
time_tuple
[
3
]
<
12
:
position
=
0
else
:
position
=
1
self
.
assertTrue
(
strftime_output
==
self
.
LT_ins
.
am_pm
[
position
],
...
...
@@ -72,7 +72,7 @@ class LocaleTime_Tests(unittest.TestCase):
# Make sure timezone is correct
timezone
=
time
.
strftime
(
"%Z"
,
self
.
time_tuple
).
lower
()
if
timezone
:
self
.
assertTrue
(
timezone
in
self
.
LT_ins
.
timezone
[
0
]
or
\
self
.
assertTrue
(
timezone
in
self
.
LT_ins
.
timezone
[
0
]
or
timezone
in
self
.
LT_ins
.
timezone
[
1
],
"timezone %s not found in %s"
%
(
timezone
,
self
.
LT_ins
.
timezone
))
...
...
@@ -133,9 +133,9 @@ class TimeRETests(unittest.TestCase):
# Make sure any characters in the format string that might be taken as
# regex syntax is escaped.
pattern_string
=
self
.
time_re
.
pattern
(
"
\
d+
"
)
self.assert
True(r"
\\
d
\
+
" in
pattern_string,
"
%
s
does
not
have
re
characters
escaped
properly
" %
pattern_string)
self.assert
In(r"
\\
d
\
+
",
pattern_string,
"
%
s
does
not
have
re
characters
escaped
properly
" %
pattern_string)
def test_compile(self):
# Check that compiled regex is correct
...
...
Lib/test/test_sys.py
View file @
b58e0bd8
...
...
@@ -388,8 +388,7 @@ class SysModuleTest(unittest.TestCase):
self
.
assertTrue
(
isinstance
(
vi
.
major
,
int
))
self
.
assertTrue
(
isinstance
(
vi
.
minor
,
int
))
self
.
assertTrue
(
isinstance
(
vi
.
micro
,
int
))
self
.
assertTrue
(
vi
.
releaselevel
in
(
"alpha"
,
"beta"
,
"candidate"
,
"final"
))
self
.
assertIn
(
vi
.
releaselevel
,
(
"alpha"
,
"beta"
,
"candidate"
,
"final"
))
self
.
assertTrue
(
isinstance
(
vi
.
serial
,
int
))
self
.
assertEqual
(
vi
[
0
],
vi
.
major
)
self
.
assertEqual
(
vi
[
1
],
vi
.
minor
)
...
...
Lib/test/test_tempfile.py
View file @
b58e0bd8
...
...
@@ -113,7 +113,7 @@ class test__RandomNameSequence(TC):
for
i
in
range
(
TEST_FILES
):
s
=
next
(
r
)
self
.
nameCheck
(
s
,
''
,
''
,
''
)
self
.
assert
False
(
s
in
dict
)
self
.
assert
NotIn
(
s
,
dict
)
dict
[
s
]
=
1
def
supports_iter
(
self
):
...
...
Lib/test/test_threading.py
View file @
b58e0bd8
...
...
@@ -350,7 +350,7 @@ class ThreadTests(BaseTestCase):
t.start()
t.join()
l = enum()
self.assert
False(t in
l,
self.assert
NotIn(t,
l,
"
#1703448 triggered after %d trials: %s" % (i, l))
finally
:
sys
.
setswitchinterval
(
old_interval
)
...
...
Lib/test/test_traceback.py
View file @
b58e0bd8
...
...
@@ -131,7 +131,7 @@ class SyntaxTracebackCases(unittest.TestCase):
err_line
=
"raise RuntimeError('{0}')"
.
format
(
message_ascii
)
err_msg
=
"RuntimeError: {0}"
.
format
(
message_ascii
)
self
.
assert
True
((
"line %s"
%
lineno
)
in
stdout
[
1
],
self
.
assert
In
((
"line %s"
%
lineno
),
stdout
[
1
],
"Invalid line number: {0!r} instead of {1}"
.
format
(
stdout
[
1
],
lineno
))
self
.
assertTrue
(
stdout
[
2
].
endswith
(
err_line
),
...
...
@@ -271,7 +271,7 @@ class BaseExceptionReportingTests:
self
.
assertEquals
(
len
(
blocks
),
3
)
self
.
assertEquals
(
blocks
[
1
],
cause_message
)
self
.
check_zero_div
(
blocks
[
0
])
self
.
assert
_
(
'inner_raise() # Marker'
in
blocks
[
2
])
self
.
assert
In
(
'inner_raise() # Marker'
,
blocks
[
2
])
def
test_cause_recursive
(
self
):
def
inner_raise
():
...
...
Lib/test/test_unittest.py
View file @
b58e0bd8
...
...
@@ -3035,7 +3035,7 @@ class Test_Assertions(TestCase):
try
:
self
.
assertRaises
(
KeyError
,
lambda
:
None
)
except
self
.
failureException
as
e
:
self
.
assert
_
(
"KeyError not raised"
in
str
(
e
)
,
str
(
e
))
self
.
assert
In
(
"KeyError not raised"
,
str
(
e
))
else
:
self
.
fail
(
"assertRaises() didn't fail"
)
try
:
...
...
@@ -3052,7 +3052,7 @@ class Test_Assertions(TestCase):
with
self
.
assertRaises
(
KeyError
):
pass
except
self
.
failureException
as
e
:
self
.
assert
_
(
"KeyError not raised"
in
str
(
e
)
,
str
(
e
))
self
.
assert
In
(
"KeyError not raised"
,
str
(
e
))
else
:
self
.
fail
(
"assertRaises() didn't fail"
)
try
:
...
...
Lib/test/test_urllib.py
View file @
b58e0bd8
...
...
@@ -731,7 +731,7 @@ class urlencode_Tests(unittest.TestCase):
expect_somewhere = ["1st=1", "2nd=2", "3rd=3"]
result = urllib.parse.urlencode(given)
for expected in expect_somewhere:
self.assert
True(expected in
result,
self.assert
In(expected,
result,
"testing %s: %s not found in %s" %
(test_type, expected, result))
self.assertEqual(result.count('
&
'), 2,
...
...
@@ -778,8 +778,7 @@ class urlencode_Tests(unittest.TestCase):
result = urllib.parse.urlencode(given, True)
for value in given["sequence"]:
expect = "sequence=%s" % value
self.assertTrue(expect in result,
"%s not found in %s" % (expect, result))
self.assertIn(expect, result)
self.assertEqual(result.count('
&
'), 2,
"Expected 2 '
&
's, got %s" % result.count('
&
'))
...
...
Lib/test/test_urllib2.py
View file @
b58e0bd8
...
...
@@ -1027,10 +1027,10 @@ class HandlerTests(unittest.TestCase):
# Verify Proxy-Authorization gets tunneled to request.
# httpsconn req_headers do not have the Proxy-Authorization header but
# the req will have.
self
.
assert
False
((
"Proxy-Authorization"
,
"FooBar"
)
in
self
.
assert
NotIn
((
"Proxy-Authorization"
,
"FooBar"
),
https_handler
.
httpconn
.
req_headers
)
self
.
assert
True
((
"User-Agent"
,
"Grail"
)
in
https_handler
.
httpconn
.
req_headers
)
self
.
assert
In
((
"User-Agent"
,
"Grail"
),
https_handler
.
httpconn
.
req_headers
)
self
.
assertIsNotNone
(
req
.
_tunnel_host
)
self
.
assertEqual
(
req
.
get_host
(),
"proxy.example.com:3128"
)
self
.
assertEqual
(
req
.
get_header
(
"Proxy-authorization"
),
"FooBar"
)
...
...
Lib/test/test_weakref.py
View file @
b58e0bd8
...
...
@@ -169,8 +169,7 @@ class ReferencesTestCase(TestBase):
p
[:]
=
[
2
,
3
]
self
.
assertEqual
(
len
(
L
),
2
)
self
.
assertEqual
(
len
(
p
),
2
)
self
.
assertTrue
(
3
in
p
,
"proxy didn't support __contains__() properly"
)
self
.
assertIn
(
3
,
p
,
"proxy didn't support __contains__() properly"
)
p
[
1
]
=
5
self
.
assertEqual
(
L
[
1
],
5
)
self
.
assertEqual
(
p
[
1
],
5
)
...
...
@@ -961,13 +960,13 @@ class MappingTestCase(TestBase):
# weakref'ed objects and then return a new key/value pair corresponding
# to the destroyed object.
with
testcontext
()
as
(
k
,
v
):
self
.
assert
False
(
k
in
dict
)
self
.
assert
NotIn
(
k
,
dict
)
with
testcontext
()
as
(
k
,
v
):
self
.
assertRaises
(
KeyError
,
dict
.
__delitem__
,
k
)
self
.
assert
False
(
k
in
dict
)
self
.
assert
NotIn
(
k
,
dict
)
with
testcontext
()
as
(
k
,
v
):
self
.
assertRaises
(
KeyError
,
dict
.
pop
,
k
)
self
.
assert
False
(
k
in
dict
)
self
.
assert
NotIn
(
k
,
dict
)
with
testcontext
()
as
(
k
,
v
):
dict
[
k
]
=
v
self
.
assertEqual
(
dict
[
k
],
v
)
...
...
@@ -1118,14 +1117,12 @@ class MappingTestCase(TestBase):
weakdict
.
update
(
dict
)
self
.
assertEqual
(
len
(
weakdict
),
len
(
dict
))
for
k
in
weakdict
.
keys
():
self
.
assertTrue
(
k
in
dict
,
"mysterious new key appeared in weak dict"
)
self
.
assertIn
(
k
,
dict
,
"mysterious new key appeared in weak dict"
)
v
=
dict
.
get
(
k
)
self
.
assertTrue
(
v
is
weakdict
[
k
])
self
.
assertTrue
(
v
is
weakdict
.
get
(
k
))
for
k
in
dict
.
keys
():
self
.
assertTrue
(
k
in
weakdict
,
"original key disappeared in weak dict"
)
self
.
assertIn
(
k
,
weakdict
,
"original key disappeared in weak dict"
)
v
=
dict
[
k
]
self
.
assertTrue
(
v
is
weakdict
[
k
])
self
.
assertTrue
(
v
is
weakdict
.
get
(
k
))
...
...
Lib/test/test_weakset.py
View file @
b58e0bd8
...
...
@@ -35,7 +35,7 @@ class TestWeakSet(unittest.TestCase):
for
method
in
dir
(
set
):
if
method
==
'test_c_api'
or
method
.
startswith
(
'_'
):
continue
self
.
assert
True
(
method
in
weaksetmethods
,
self
.
assert
In
(
method
,
weaksetmethods
,
"WeakSet missing method "
+
method
)
def
test_new_or_init
(
self
):
...
...
@@ -342,10 +342,10 @@ class TestWeakSet(unittest.TestCase):
it
=
None
# should commit all removals
with
testcontext
()
as
u
:
self
.
assert
False
(
u
in
s
)
self
.
assert
NotIn
(
u
,
s
)
with
testcontext
()
as
u
:
self
.
assertRaises
(
KeyError
,
s
.
remove
,
u
)
self
.
assert
False
(
u
in
s
)
self
.
assert
NotIn
(
u
,
s
)
with
testcontext
()
as
u
:
s
.
add
(
u
)
self
.
assertIn
(
u
,
s
)
...
...
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