Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
fbc84459
Commit
fbc84459
authored
Mar 14, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some deprecated unittest method usages.
parent
4df5c828
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
31 deletions
+31
-31
Cython/Build/Tests/TestInline.py
Cython/Build/Tests/TestInline.py
+9
-9
Cython/Build/Tests/TestIpythonMagic.py
Cython/Build/Tests/TestIpythonMagic.py
+2
-2
Cython/Compiler/Tests/TestBuffer.py
Cython/Compiler/Tests/TestBuffer.py
+11
-11
Cython/Compiler/Tests/TestMemView.py
Cython/Compiler/Tests/TestMemView.py
+1
-1
Cython/Compiler/Tests/TestParseTreeTransforms.py
Cython/Compiler/Tests/TestParseTreeTransforms.py
+1
-1
Cython/Compiler/Tests/TestTreeFragment.py
Cython/Compiler/Tests/TestTreeFragment.py
+5
-5
Cython/Tests/xmlrunner.py
Cython/Tests/xmlrunner.py
+2
-2
No files found.
Cython/Build/Tests/TestInline.py
View file @
fbc84459
...
...
@@ -24,10 +24,10 @@ class TestInline(CythonTest):
self
.
test_kwds
[
'lib_dir'
]
=
lib_dir
def
test_simple
(
self
):
self
.
assertEqual
s
(
inline
(
"return 1+2"
,
**
self
.
test_kwds
),
3
)
self
.
assertEqual
(
inline
(
"return 1+2"
,
**
self
.
test_kwds
),
3
)
def
test_types
(
self
):
self
.
assertEqual
s
(
inline
(
"""
self
.
assertEqual
(
inline
(
"""
cimport cython
return cython.typeof(a), cython.typeof(b)
"""
,
a
=
1.0
,
b
=
[],
**
self
.
test_kwds
),
(
'double'
,
'list object'
))
...
...
@@ -35,13 +35,13 @@ class TestInline(CythonTest):
def
test_locals
(
self
):
a
=
1
b
=
2
self
.
assertEqual
s
(
inline
(
"return a+b"
,
**
self
.
test_kwds
),
3
)
self
.
assertEqual
(
inline
(
"return a+b"
,
**
self
.
test_kwds
),
3
)
def
test_globals
(
self
):
self
.
assertEqual
s
(
inline
(
"return global_value + 1"
,
**
self
.
test_kwds
),
global_value
+
1
)
self
.
assertEqual
(
inline
(
"return global_value + 1"
,
**
self
.
test_kwds
),
global_value
+
1
)
def
test_no_return
(
self
):
self
.
assertEqual
s
(
inline
(
"""
self
.
assertEqual
(
inline
(
"""
a = 1
cdef double b = 2
cdef c = []
...
...
@@ -49,7 +49,7 @@ class TestInline(CythonTest):
def
test_def_node
(
self
):
foo
=
inline
(
"def foo(x): return x * x"
,
**
self
.
test_kwds
)[
'foo'
]
self
.
assertEqual
s
(
foo
(
7
),
49
)
self
.
assertEqual
(
foo
(
7
),
49
)
def
test_pure
(
self
):
import
cython
as
cy
...
...
@@ -58,7 +58,7 @@ class TestInline(CythonTest):
c = cy.declare(cy.pointer(cy.float), &b)
return b
"""
,
a
=
3
,
**
self
.
test_kwds
)
self
.
assertEqual
s
(
type
(
b
),
float
)
self
.
assertEqual
(
type
(
b
),
float
)
def
test_compiler_directives
(
self
):
self
.
assertEqual
(
...
...
@@ -74,5 +74,5 @@ class TestInline(CythonTest):
import
numpy
a
=
numpy
.
ndarray
((
10
,
20
))
a
[
0
,
0
]
=
10
self
.
assertEqual
s
(
safe_type
(
a
),
'numpy.ndarray[numpy.float64_t, ndim=2]'
)
self
.
assertEqual
s
(
inline
(
"return a[0,0]"
,
a
=
a
,
**
self
.
test_kwds
),
10.0
)
self
.
assertEqual
(
safe_type
(
a
),
'numpy.ndarray[numpy.float64_t, ndim=2]'
)
self
.
assertEqual
(
inline
(
"return a[0,0]"
,
a
=
a
,
**
self
.
test_kwds
),
10.0
)
Cython/Build/Tests/TestIpythonMagic.py
View file @
fbc84459
...
...
@@ -202,11 +202,11 @@ x = sin(0.0)
ip
.
run_cell_magic
(
'cython'
,
'--verbose'
,
code
)
ip
.
ex
(
'g = f(10)'
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
20.0
)
self
.
assertEqual
s
([
verbose_log
.
INFO
,
verbose_log
.
DEBUG
,
verbose_log
.
INFO
],
self
.
assertEqual
([
verbose_log
.
INFO
,
verbose_log
.
DEBUG
,
verbose_log
.
INFO
],
verbose_log
.
thresholds
)
with
mock_distutils
()
as
normal_log
:
ip
.
run_cell_magic
(
'cython'
,
''
,
code
)
ip
.
ex
(
'g = f(10)'
)
self
.
assertEqual
(
ip
.
user_ns
[
'g'
],
20.0
)
self
.
assertEqual
s
([
normal_log
.
INFO
],
normal_log
.
thresholds
)
self
.
assertEqual
([
normal_log
.
INFO
],
normal_log
.
thresholds
)
Cython/Compiler/Tests/TestBuffer.py
View file @
fbc84459
...
...
@@ -21,7 +21,7 @@ class TestBufferParsing(CythonTest):
def
test_basic
(
self
):
t
=
self
.
parse
(
u"cdef object[float, 4, ndim=2, foo=foo] x"
)
bufnode
=
t
.
stats
[
0
].
base_type
self
.
assert
_
(
isinstance
(
bufnode
,
TemplatedTypeNode
))
self
.
assert
True
(
isinstance
(
bufnode
,
TemplatedTypeNode
))
self
.
assertEqual
(
2
,
len
(
bufnode
.
positional_args
))
# print bufnode.dump()
# should put more here...
...
...
@@ -46,7 +46,7 @@ class TestBufferOptions(CythonTest):
def
nonfatal_error
(
self
,
error
):
# We're passing self as context to transform to trap this
self
.
error
=
error
self
.
assert
_
(
self
.
expect_error
)
self
.
assert
True
(
self
.
expect_error
)
def
parse_opts
(
self
,
opts
,
expect_error
=
False
):
assert
opts
!=
""
...
...
@@ -57,12 +57,12 @@ class TestBufferOptions(CythonTest):
vardef
=
root
.
stats
[
0
].
body
.
stats
[
0
]
assert
isinstance
(
vardef
,
CVarDefNode
)
# use normal assert as this is to validate the test code
buftype
=
vardef
.
base_type
self
.
assert
_
(
isinstance
(
buftype
,
TemplatedTypeNode
))
self
.
assert
_
(
isinstance
(
buftype
.
base_type_node
,
CSimpleBaseTypeNode
))
self
.
assert
True
(
isinstance
(
buftype
,
TemplatedTypeNode
))
self
.
assert
True
(
isinstance
(
buftype
.
base_type_node
,
CSimpleBaseTypeNode
))
self
.
assertEqual
(
u"object"
,
buftype
.
base_type_node
.
name
)
return
buftype
else
:
self
.
assert
_
(
len
(
root
.
stats
[
0
].
body
.
stats
)
==
0
)
self
.
assert
True
(
len
(
root
.
stats
[
0
].
body
.
stats
)
==
0
)
def
non_parse
(
self
,
expected_err
,
opts
):
self
.
parse_opts
(
opts
,
expect_error
=
True
)
...
...
@@ -71,14 +71,14 @@ class TestBufferOptions(CythonTest):
def
__test_basic
(
self
):
buf
=
self
.
parse_opts
(
u"unsigned short int, 3"
)
self
.
assert
_
(
isinstance
(
buf
.
dtype_node
,
CSimpleBaseTypeNode
))
self
.
assert
_
(
buf
.
dtype_node
.
signed
==
0
and
buf
.
dtype_node
.
longness
==
-
1
)
self
.
assert
True
(
isinstance
(
buf
.
dtype_node
,
CSimpleBaseTypeNode
))
self
.
assert
True
(
buf
.
dtype_node
.
signed
==
0
and
buf
.
dtype_node
.
longness
==
-
1
)
self
.
assertEqual
(
3
,
buf
.
ndim
)
def
__test_dict
(
self
):
buf
=
self
.
parse_opts
(
u"ndim=3, dtype=unsigned short int"
)
self
.
assert
_
(
isinstance
(
buf
.
dtype_node
,
CSimpleBaseTypeNode
))
self
.
assert
_
(
buf
.
dtype_node
.
signed
==
0
and
buf
.
dtype_node
.
longness
==
-
1
)
self
.
assert
True
(
isinstance
(
buf
.
dtype_node
,
CSimpleBaseTypeNode
))
self
.
assert
True
(
buf
.
dtype_node
.
signed
==
0
and
buf
.
dtype_node
.
longness
==
-
1
)
self
.
assertEqual
(
3
,
buf
.
ndim
)
def
__test_ndim
(
self
):
...
...
@@ -94,8 +94,8 @@ class TestBufferOptions(CythonTest):
cdef object[ndim=ndim, dtype=int] y
"""
,
pipeline
=
[
NormalizeTree
(
self
),
PostParse
(
self
)]).
root
stats
=
t
.
stats
[
0
].
body
.
stats
self
.
assert
_
(
stats
[
0
].
base_type
.
ndim
==
3
)
self
.
assert
_
(
stats
[
1
].
base_type
.
ndim
==
3
)
self
.
assert
True
(
stats
[
0
].
base_type
.
ndim
==
3
)
self
.
assert
True
(
stats
[
1
].
base_type
.
ndim
==
3
)
# add exotic and impossible combinations as they come along...
...
...
Cython/Compiler/Tests/TestMemView.py
View file @
fbc84459
...
...
@@ -48,7 +48,7 @@ class TestMemviewParsing(CythonTest):
def
test_basic
(
self
):
t
=
self
.
parse
(
u"cdef int[:] x"
)
memv_node
=
t
.
stats
[
0
].
base_type
self
.
assert
_
(
isinstance
(
memv_node
,
MemoryViewSliceTypeNode
))
self
.
assert
True
(
isinstance
(
memv_node
,
MemoryViewSliceTypeNode
))
# we also test other similar declarations (buffers, anonymous C arrays)
# since the parsing has to distinguish between them.
...
...
Cython/Compiler/Tests/TestParseTreeTransforms.py
View file @
fbc84459
...
...
@@ -87,7 +87,7 @@ class TestNormalizeTree(TransformTest):
def
test_pass_eliminated
(
self
):
t
=
self
.
run_pipeline
([
NormalizeTree
(
None
)],
u"pass"
)
self
.
assert
_
(
len
(
t
.
stats
)
==
0
)
self
.
assert
True
(
len
(
t
.
stats
)
==
0
)
class
TestWithTransform
(
object
):
# (TransformTest): # Disabled!
...
...
Cython/Compiler/Tests/TestTreeFragment.py
View file @
fbc84459
...
...
@@ -23,7 +23,7 @@ class TestTreeFragments(CythonTest):
T
=
self
.
fragment
(
u"y + y"
).
substitute
({
"y"
:
NameNode
(
pos
=
None
,
name
=
"x"
)})
self
.
assertEqual
(
"x"
,
T
.
stats
[
0
].
expr
.
operand1
.
name
)
self
.
assertEqual
(
"x"
,
T
.
stats
[
0
].
expr
.
operand2
.
name
)
self
.
assert
_
(
T
.
stats
[
0
].
expr
.
operand1
is
not
T
.
stats
[
0
].
expr
.
operand2
)
self
.
assert
True
(
T
.
stats
[
0
].
expr
.
operand1
is
not
T
.
stats
[
0
].
expr
.
operand2
)
def
test_substitution
(
self
):
F
=
self
.
fragment
(
u"x = 4"
)
...
...
@@ -35,7 +35,7 @@ class TestTreeFragments(CythonTest):
F
=
self
.
fragment
(
u"PASS"
)
pass_stat
=
PassStatNode
(
pos
=
None
)
T
=
F
.
substitute
({
"PASS"
:
pass_stat
})
self
.
assert
_
(
isinstance
(
T
.
stats
[
0
],
PassStatNode
),
T
)
self
.
assert
True
(
isinstance
(
T
.
stats
[
0
],
PassStatNode
),
T
)
def
test_pos_is_transferred
(
self
):
F
=
self
.
fragment
(
u"""
...
...
@@ -55,9 +55,9 @@ class TestTreeFragments(CythonTest):
"""
)
T
=
F
.
substitute
(
temps
=
[
u"TMP"
])
s
=
T
.
body
.
stats
self
.
assert
_
(
isinstance
(
s
[
0
].
expr
,
TempRefNode
))
self
.
assert
_
(
isinstance
(
s
[
1
].
rhs
,
TempRefNode
))
self
.
assert
_
(
s
[
0
].
expr
.
handle
is
s
[
1
].
rhs
.
handle
)
self
.
assert
True
(
isinstance
(
s
[
0
].
expr
,
TempRefNode
))
self
.
assert
True
(
isinstance
(
s
[
1
].
rhs
,
TempRefNode
))
self
.
assert
True
(
s
[
0
].
expr
.
handle
is
s
[
1
].
rhs
.
handle
)
if
__name__
==
"__main__"
:
import
unittest
...
...
Cython/Tests/xmlrunner.py
View file @
fbc84459
...
...
@@ -27,12 +27,12 @@ class TestSequenceFunctions(unittest.TestCase):
def test_choice(self):
element = random.choice(self.seq)
self.assert
_
(element in self.seq)
self.assert
True
(element in self.seq)
def test_sample(self):
self.assertRaises(ValueError, random.sample, self.seq, 20)
for element in random.sample(self.seq, 5):
self.assert
_
(element in self.seq)
self.assert
True
(element in self.seq)
if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
...
...
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