Commit fbc84459 authored by Stefan Behnel's avatar Stefan Behnel

Fix some deprecated unittest method usages.

parent 4df5c828
...@@ -24,10 +24,10 @@ class TestInline(CythonTest): ...@@ -24,10 +24,10 @@ class TestInline(CythonTest):
self.test_kwds['lib_dir'] = lib_dir self.test_kwds['lib_dir'] = lib_dir
def test_simple(self): def test_simple(self):
self.assertEquals(inline("return 1+2", **self.test_kwds), 3) self.assertEqual(inline("return 1+2", **self.test_kwds), 3)
def test_types(self): def test_types(self):
self.assertEquals(inline(""" self.assertEqual(inline("""
cimport cython cimport cython
return cython.typeof(a), cython.typeof(b) return cython.typeof(a), cython.typeof(b)
""", a=1.0, b=[], **self.test_kwds), ('double', 'list object')) """, a=1.0, b=[], **self.test_kwds), ('double', 'list object'))
...@@ -35,13 +35,13 @@ class TestInline(CythonTest): ...@@ -35,13 +35,13 @@ class TestInline(CythonTest):
def test_locals(self): def test_locals(self):
a = 1 a = 1
b = 2 b = 2
self.assertEquals(inline("return a+b", **self.test_kwds), 3) self.assertEqual(inline("return a+b", **self.test_kwds), 3)
def test_globals(self): def test_globals(self):
self.assertEquals(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): def test_no_return(self):
self.assertEquals(inline(""" self.assertEqual(inline("""
a = 1 a = 1
cdef double b = 2 cdef double b = 2
cdef c = [] cdef c = []
...@@ -49,7 +49,7 @@ class TestInline(CythonTest): ...@@ -49,7 +49,7 @@ class TestInline(CythonTest):
def test_def_node(self): def test_def_node(self):
foo = inline("def foo(x): return x * x", **self.test_kwds)['foo'] foo = inline("def foo(x): return x * x", **self.test_kwds)['foo']
self.assertEquals(foo(7), 49) self.assertEqual(foo(7), 49)
def test_pure(self): def test_pure(self):
import cython as cy import cython as cy
...@@ -58,7 +58,7 @@ class TestInline(CythonTest): ...@@ -58,7 +58,7 @@ class TestInline(CythonTest):
c = cy.declare(cy.pointer(cy.float), &b) c = cy.declare(cy.pointer(cy.float), &b)
return b return b
""", a=3, **self.test_kwds) """, a=3, **self.test_kwds)
self.assertEquals(type(b), float) self.assertEqual(type(b), float)
def test_compiler_directives(self): def test_compiler_directives(self):
self.assertEqual( self.assertEqual(
...@@ -74,5 +74,5 @@ class TestInline(CythonTest): ...@@ -74,5 +74,5 @@ class TestInline(CythonTest):
import numpy import numpy
a = numpy.ndarray((10, 20)) a = numpy.ndarray((10, 20))
a[0,0] = 10 a[0,0] = 10
self.assertEquals(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]') self.assertEqual(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
self.assertEquals(inline("return a[0,0]", a=a, **self.test_kwds), 10.0) self.assertEqual(inline("return a[0,0]", a=a, **self.test_kwds), 10.0)
...@@ -202,11 +202,11 @@ x = sin(0.0) ...@@ -202,11 +202,11 @@ x = sin(0.0)
ip.run_cell_magic('cython', '--verbose', code) ip.run_cell_magic('cython', '--verbose', code)
ip.ex('g = f(10)') ip.ex('g = f(10)')
self.assertEqual(ip.user_ns['g'], 20.0) self.assertEqual(ip.user_ns['g'], 20.0)
self.assertEquals([verbose_log.INFO, verbose_log.DEBUG, verbose_log.INFO], self.assertEqual([verbose_log.INFO, verbose_log.DEBUG, verbose_log.INFO],
verbose_log.thresholds) verbose_log.thresholds)
with mock_distutils() as normal_log: with mock_distutils() as normal_log:
ip.run_cell_magic('cython', '', code) ip.run_cell_magic('cython', '', code)
ip.ex('g = f(10)') ip.ex('g = f(10)')
self.assertEqual(ip.user_ns['g'], 20.0) self.assertEqual(ip.user_ns['g'], 20.0)
self.assertEquals([normal_log.INFO], normal_log.thresholds) self.assertEqual([normal_log.INFO], normal_log.thresholds)
...@@ -21,7 +21,7 @@ class TestBufferParsing(CythonTest): ...@@ -21,7 +21,7 @@ class TestBufferParsing(CythonTest):
def test_basic(self): def test_basic(self):
t = self.parse(u"cdef object[float, 4, ndim=2, foo=foo] x") t = self.parse(u"cdef object[float, 4, ndim=2, foo=foo] x")
bufnode = t.stats[0].base_type bufnode = t.stats[0].base_type
self.assert_(isinstance(bufnode, TemplatedTypeNode)) self.assertTrue(isinstance(bufnode, TemplatedTypeNode))
self.assertEqual(2, len(bufnode.positional_args)) self.assertEqual(2, len(bufnode.positional_args))
# print bufnode.dump() # print bufnode.dump()
# should put more here... # should put more here...
...@@ -46,7 +46,7 @@ class TestBufferOptions(CythonTest): ...@@ -46,7 +46,7 @@ class TestBufferOptions(CythonTest):
def nonfatal_error(self, error): def nonfatal_error(self, error):
# We're passing self as context to transform to trap this # We're passing self as context to transform to trap this
self.error = error self.error = error
self.assert_(self.expect_error) self.assertTrue(self.expect_error)
def parse_opts(self, opts, expect_error=False): def parse_opts(self, opts, expect_error=False):
assert opts != "" assert opts != ""
...@@ -57,12 +57,12 @@ class TestBufferOptions(CythonTest): ...@@ -57,12 +57,12 @@ class TestBufferOptions(CythonTest):
vardef = root.stats[0].body.stats[0] vardef = root.stats[0].body.stats[0]
assert isinstance(vardef, CVarDefNode) # use normal assert as this is to validate the test code assert isinstance(vardef, CVarDefNode) # use normal assert as this is to validate the test code
buftype = vardef.base_type buftype = vardef.base_type
self.assert_(isinstance(buftype, TemplatedTypeNode)) self.assertTrue(isinstance(buftype, TemplatedTypeNode))
self.assert_(isinstance(buftype.base_type_node, CSimpleBaseTypeNode)) self.assertTrue(isinstance(buftype.base_type_node, CSimpleBaseTypeNode))
self.assertEqual(u"object", buftype.base_type_node.name) self.assertEqual(u"object", buftype.base_type_node.name)
return buftype return buftype
else: else:
self.assert_(len(root.stats[0].body.stats) == 0) self.assertTrue(len(root.stats[0].body.stats) == 0)
def non_parse(self, expected_err, opts): def non_parse(self, expected_err, opts):
self.parse_opts(opts, expect_error=True) self.parse_opts(opts, expect_error=True)
...@@ -71,14 +71,14 @@ class TestBufferOptions(CythonTest): ...@@ -71,14 +71,14 @@ class TestBufferOptions(CythonTest):
def __test_basic(self): def __test_basic(self):
buf = self.parse_opts(u"unsigned short int, 3") buf = self.parse_opts(u"unsigned short int, 3")
self.assert_(isinstance(buf.dtype_node, CSimpleBaseTypeNode)) self.assertTrue(isinstance(buf.dtype_node, CSimpleBaseTypeNode))
self.assert_(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1) self.assertTrue(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1)
self.assertEqual(3, buf.ndim) self.assertEqual(3, buf.ndim)
def __test_dict(self): def __test_dict(self):
buf = self.parse_opts(u"ndim=3, dtype=unsigned short int") buf = self.parse_opts(u"ndim=3, dtype=unsigned short int")
self.assert_(isinstance(buf.dtype_node, CSimpleBaseTypeNode)) self.assertTrue(isinstance(buf.dtype_node, CSimpleBaseTypeNode))
self.assert_(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1) self.assertTrue(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1)
self.assertEqual(3, buf.ndim) self.assertEqual(3, buf.ndim)
def __test_ndim(self): def __test_ndim(self):
...@@ -94,8 +94,8 @@ class TestBufferOptions(CythonTest): ...@@ -94,8 +94,8 @@ class TestBufferOptions(CythonTest):
cdef object[ndim=ndim, dtype=int] y cdef object[ndim=ndim, dtype=int] y
""", pipeline=[NormalizeTree(self), PostParse(self)]).root """, pipeline=[NormalizeTree(self), PostParse(self)]).root
stats = t.stats[0].body.stats stats = t.stats[0].body.stats
self.assert_(stats[0].base_type.ndim == 3) self.assertTrue(stats[0].base_type.ndim == 3)
self.assert_(stats[1].base_type.ndim == 3) self.assertTrue(stats[1].base_type.ndim == 3)
# add exotic and impossible combinations as they come along... # add exotic and impossible combinations as they come along...
......
...@@ -48,7 +48,7 @@ class TestMemviewParsing(CythonTest): ...@@ -48,7 +48,7 @@ class TestMemviewParsing(CythonTest):
def test_basic(self): def test_basic(self):
t = self.parse(u"cdef int[:] x") t = self.parse(u"cdef int[:] x")
memv_node = t.stats[0].base_type memv_node = t.stats[0].base_type
self.assert_(isinstance(memv_node, MemoryViewSliceTypeNode)) self.assertTrue(isinstance(memv_node, MemoryViewSliceTypeNode))
# we also test other similar declarations (buffers, anonymous C arrays) # we also test other similar declarations (buffers, anonymous C arrays)
# since the parsing has to distinguish between them. # since the parsing has to distinguish between them.
......
...@@ -87,7 +87,7 @@ class TestNormalizeTree(TransformTest): ...@@ -87,7 +87,7 @@ class TestNormalizeTree(TransformTest):
def test_pass_eliminated(self): def test_pass_eliminated(self):
t = self.run_pipeline([NormalizeTree(None)], u"pass") t = self.run_pipeline([NormalizeTree(None)], u"pass")
self.assert_(len(t.stats) == 0) self.assertTrue(len(t.stats) == 0)
class TestWithTransform(object): # (TransformTest): # Disabled! class TestWithTransform(object): # (TransformTest): # Disabled!
......
...@@ -23,7 +23,7 @@ class TestTreeFragments(CythonTest): ...@@ -23,7 +23,7 @@ class TestTreeFragments(CythonTest):
T = self.fragment(u"y + y").substitute({"y": NameNode(pos=None, name="x")}) 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.operand1.name)
self.assertEqual("x", T.stats[0].expr.operand2.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.assertTrue(T.stats[0].expr.operand1 is not T.stats[0].expr.operand2)
def test_substitution(self): def test_substitution(self):
F = self.fragment(u"x = 4") F = self.fragment(u"x = 4")
...@@ -35,7 +35,7 @@ class TestTreeFragments(CythonTest): ...@@ -35,7 +35,7 @@ class TestTreeFragments(CythonTest):
F = self.fragment(u"PASS") F = self.fragment(u"PASS")
pass_stat = PassStatNode(pos=None) pass_stat = PassStatNode(pos=None)
T = F.substitute({"PASS" : pass_stat}) T = F.substitute({"PASS" : pass_stat})
self.assert_(isinstance(T.stats[0], PassStatNode), T) self.assertTrue(isinstance(T.stats[0], PassStatNode), T)
def test_pos_is_transferred(self): def test_pos_is_transferred(self):
F = self.fragment(u""" F = self.fragment(u"""
...@@ -55,9 +55,9 @@ class TestTreeFragments(CythonTest): ...@@ -55,9 +55,9 @@ class TestTreeFragments(CythonTest):
""") """)
T = F.substitute(temps=[u"TMP"]) T = F.substitute(temps=[u"TMP"])
s = T.body.stats s = T.body.stats
self.assert_(isinstance(s[0].expr, TempRefNode)) self.assertTrue(isinstance(s[0].expr, TempRefNode))
self.assert_(isinstance(s[1].rhs, TempRefNode)) self.assertTrue(isinstance(s[1].rhs, TempRefNode))
self.assert_(s[0].expr.handle is s[1].rhs.handle) self.assertTrue(s[0].expr.handle is s[1].rhs.handle)
if __name__ == "__main__": if __name__ == "__main__":
import unittest import unittest
......
...@@ -27,12 +27,12 @@ class TestSequenceFunctions(unittest.TestCase): ...@@ -27,12 +27,12 @@ class TestSequenceFunctions(unittest.TestCase):
def test_choice(self): def test_choice(self):
element = random.choice(self.seq) element = random.choice(self.seq)
self.assert_(element in self.seq) self.assertTrue(element in self.seq)
def test_sample(self): def test_sample(self):
self.assertRaises(ValueError, random.sample, self.seq, 20) self.assertRaises(ValueError, random.sample, self.seq, 20)
for element in random.sample(self.seq, 5): for element in random.sample(self.seq, 5):
self.assert_(element in self.seq) self.assertTrue(element in self.seq)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports')) unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment