Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / cython / src / Cython / Compiler / Tests / TestMemView.py
blobe6ca87dd4f85cb52b95589ad3151c0f40cb3e90a
1 from Cython.TestUtils import CythonTest
2 import Cython.Compiler.Errors as Errors
3 from Cython.Compiler.Nodes import *
4 from Cython.Compiler.ParseTreeTransforms import *
5 from Cython.Compiler.Buffer import *
8 class TestMemviewParsing(CythonTest):
10 def parse(self, s):
11 return self.should_not_fail(lambda: self.fragment(s)).root
13 def not_parseable(self, expected_error, s):
14 e = self.should_fail(lambda: self.fragment(s), Errors.CompileError)
15 self.assertEqual(expected_error, e.message_only)
17 def test_default_1dim(self):
18 self.parse(u"cdef int[:] x")
19 self.parse(u"cdef short int[:] x")
21 def test_default_ndim(self):
22 self.parse(u"cdef int[:,:,:,:,:] x")
23 self.parse(u"cdef unsigned long int[:,:,:,:,:] x")
24 self.parse(u"cdef unsigned int[:,:,:,:,:] x")
26 def test_zero_offset(self):
27 self.parse(u"cdef long double[0:] x")
28 self.parse(u"cdef int[0:] x")
30 def test_zero_offset_ndim(self):
31 self.parse(u"cdef int[0:,0:,0:,0:] x")
33 def test_def_arg(self):
34 self.parse(u"def foo(int[:,:] x): pass")
36 def test_cdef_arg(self):
37 self.parse(u"cdef foo(int[:,:] x): pass")
39 def test_general_slice(self):
40 self.parse(u'cdef float[::ptr, ::direct & contig, 0::full & strided] x')
42 def test_non_slice_memview(self):
43 self.not_parseable(u"An axis specification in memoryview declaration does not have a ':'.",
44 u"cdef double[:foo, bar] x")
45 self.not_parseable(u"An axis specification in memoryview declaration does not have a ':'.",
46 u"cdef double[0:foo, bar] x")
48 def test_basic(self):
49 t = self.parse(u"cdef int[:] x")
50 memv_node = t.stats[0].base_type
51 self.assert_(isinstance(memv_node, MemoryViewSliceTypeNode))
53 # we also test other similar declarations (buffers, anonymous C arrays)
54 # since the parsing has to distinguish between them.
56 def disable_test_no_buf_arg(self): # TODO
57 self.not_parseable(u"Expected ']'",
58 u"cdef extern foo(object[int, ndim=2])")
60 def disable_test_parse_sizeof(self): # TODO
61 self.parse(u"sizeof(int[NN])")
62 self.parse(u"sizeof(int[])")
63 self.parse(u"sizeof(int[][NN])")
64 self.not_parseable(u"Expected an identifier or literal",
65 u"sizeof(int[:NN])")
66 self.not_parseable(u"Expected ']'",
67 u"sizeof(foo[dtype=bar]")
69 if __name__ == '__main__':
70 import unittest
71 unittest.main()