Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- .venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_240216.model.v2 +3 -0
- .venv/lib/python3.11/site-packages/numpy/lib/tests/__pycache__/test_io.cpython-311.pyc +3 -0
- .venv/lib/python3.11/site-packages/numpy/lib/tests/data/py3-objarr.npy +3 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/_base_connection.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/_collections.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/_request_methods.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/_version.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/connection.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/connectionpool.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/exceptions.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/fields.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/filepost.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/poolmanager.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/__pycache__/response.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/connection.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/proxy.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/request.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/response.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/retry.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/ssl_match_hostname.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/ssltransport.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/timeout.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/url.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/util.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/urllib3/util/__pycache__/wait.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestBuffer.py +105 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestCmdLine.py +579 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestFlowControl.py +68 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestMemView.py +71 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.py +289 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestScanning.py +136 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestStringEncoding.py +44 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestTreeFragment.py +63 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestTreePath.py +93 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestVisitor.py +61 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/Utils.py +36 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__init__.py +1 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__pycache__/TestMemView.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__pycache__/TestTreePath.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__pycache__/TestVisitor.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/__pycache__/Dataclass.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/__pycache__/TreePath.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/networkx/algorithms/__pycache__/communicability_alg.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/networkx/algorithms/__pycache__/core.cpython-311.pyc +0 -0
- tuning-competition-baseline/.venv/lib/python3.11/site-packages/networkx/algorithms/__pycache__/distance_measures.cpython-311.pyc +0 -0
.gitattributes
CHANGED
|
@@ -395,3 +395,5 @@ tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cudnn/lib/
|
|
| 395 |
.venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_241114.model.v7 filter=lfs diff=lfs merge=lfs -text
|
| 396 |
.venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_241114.model.v7m1 filter=lfs diff=lfs merge=lfs -text
|
| 397 |
.venv/lib/python3.11/site-packages/mistral_common/data/tokenizer.model.v1 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 395 |
.venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_241114.model.v7 filter=lfs diff=lfs merge=lfs -text
|
| 396 |
.venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_241114.model.v7m1 filter=lfs diff=lfs merge=lfs -text
|
| 397 |
.venv/lib/python3.11/site-packages/mistral_common/data/tokenizer.model.v1 filter=lfs diff=lfs merge=lfs -text
|
| 398 |
+
.venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_240216.model.v2 filter=lfs diff=lfs merge=lfs -text
|
| 399 |
+
.venv/lib/python3.11/site-packages/numpy/lib/tests/__pycache__/test_io.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
.venv/lib/python3.11/site-packages/mistral_common/data/mistral_instruct_tokenizer_240216.model.v2
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37f00374dea48658ee8f5d0f21895b9bc55cb0103939607c8185bfd1c6ca1f89
|
| 3 |
+
size 587404
|
.venv/lib/python3.11/site-packages/numpy/lib/tests/__pycache__/test_io.cpython-311.pyc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2010346e0e3cb10ca0cd2e7e3c16b408172831251b537634fb7f258b2742caff
|
| 3 |
+
size 203055
|
.venv/lib/python3.11/site-packages/numpy/lib/tests/data/py3-objarr.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a534d587c7b3a7e97000addf920bdd294f00ae9e4d30ace7543f8ce84c7fb80d
|
| 3 |
+
size 341
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (7.66 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/_base_connection.cpython-311.pyc
ADDED
|
Binary file (7.1 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/_collections.cpython-311.pyc
ADDED
|
Binary file (26 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/_request_methods.cpython-311.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/_version.cpython-311.pyc
ADDED
|
Binary file (638 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/connection.cpython-311.pyc
ADDED
|
Binary file (38 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/connectionpool.cpython-311.pyc
ADDED
|
Binary file (41.3 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/exceptions.cpython-311.pyc
ADDED
|
Binary file (19.6 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/fields.cpython-311.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/filepost.cpython-311.pyc
ADDED
|
Binary file (3.87 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/poolmanager.cpython-311.pyc
ADDED
|
Binary file (25.5 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/__pycache__/response.cpython-311.pyc
ADDED
|
Binary file (54.9 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/connection.cpython-311.pyc
ADDED
|
Binary file (5.04 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/proxy.cpython-311.pyc
ADDED
|
Binary file (1.28 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/request.cpython-311.pyc
ADDED
|
Binary file (9.03 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/response.cpython-311.pyc
ADDED
|
Binary file (3.35 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/retry.cpython-311.pyc
ADDED
|
Binary file (21.2 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/ssl_match_hostname.cpython-311.pyc
ADDED
|
Binary file (6.25 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/ssltransport.cpython-311.pyc
ADDED
|
Binary file (14.3 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/timeout.cpython-311.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/url.cpython-311.pyc
ADDED
|
Binary file (17.8 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/util.cpython-311.pyc
ADDED
|
Binary file (2.17 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/urllib3/util/__pycache__/wait.cpython-311.pyc
ADDED
|
Binary file (3.74 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestBuffer.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 *
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestBufferParsing(CythonTest):
|
| 9 |
+
# First, we only test the raw parser, i.e.
|
| 10 |
+
# the number and contents of arguments are NOT checked.
|
| 11 |
+
# However "dtype"/the first positional argument is special-cased
|
| 12 |
+
# to parse a type argument rather than an expression
|
| 13 |
+
|
| 14 |
+
def parse(self, s):
|
| 15 |
+
return self.should_not_fail(lambda: self.fragment(s)).root
|
| 16 |
+
|
| 17 |
+
def not_parseable(self, expected_error, s):
|
| 18 |
+
e = self.should_fail(lambda: self.fragment(s), Errors.CompileError)
|
| 19 |
+
self.assertEqual(expected_error, e.message_only)
|
| 20 |
+
|
| 21 |
+
def test_basic(self):
|
| 22 |
+
t = self.parse(u"cdef object[float, 4, ndim=2, foo=foo] x")
|
| 23 |
+
bufnode = t.stats[0].base_type
|
| 24 |
+
self.assertTrue(isinstance(bufnode, TemplatedTypeNode))
|
| 25 |
+
self.assertEqual(2, len(bufnode.positional_args))
|
| 26 |
+
# print bufnode.dump()
|
| 27 |
+
# should put more here...
|
| 28 |
+
|
| 29 |
+
def test_type_pos(self):
|
| 30 |
+
self.parse(u"cdef object[short unsigned int, 3] x")
|
| 31 |
+
|
| 32 |
+
def test_type_keyword(self):
|
| 33 |
+
self.parse(u"cdef object[foo=foo, dtype=short unsigned int] x")
|
| 34 |
+
|
| 35 |
+
def test_pos_after_key(self):
|
| 36 |
+
self.not_parseable("Non-keyword arg following keyword arg",
|
| 37 |
+
u"cdef object[foo=1, 2] x")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# See also tests/error/e_bufaccess.pyx and tets/run/bufaccess.pyx
|
| 41 |
+
# THESE TESTS ARE NOW DISABLED, the code they test was pretty much
|
| 42 |
+
# refactored away
|
| 43 |
+
class TestBufferOptions(CythonTest):
|
| 44 |
+
# Tests the full parsing of the options within the brackets
|
| 45 |
+
|
| 46 |
+
def nonfatal_error(self, error):
|
| 47 |
+
# We're passing self as context to transform to trap this
|
| 48 |
+
self.error = error
|
| 49 |
+
self.assertTrue(self.expect_error)
|
| 50 |
+
|
| 51 |
+
def parse_opts(self, opts, expect_error=False):
|
| 52 |
+
assert opts != ""
|
| 53 |
+
s = u"def f():\n cdef object[%s] x" % opts
|
| 54 |
+
self.expect_error = expect_error
|
| 55 |
+
root = self.fragment(s, pipeline=[NormalizeTree(self), PostParse(self)]).root
|
| 56 |
+
if not expect_error:
|
| 57 |
+
vardef = root.stats[0].body.stats[0]
|
| 58 |
+
assert isinstance(vardef, CVarDefNode) # use normal assert as this is to validate the test code
|
| 59 |
+
buftype = vardef.base_type
|
| 60 |
+
self.assertTrue(isinstance(buftype, TemplatedTypeNode))
|
| 61 |
+
self.assertTrue(isinstance(buftype.base_type_node, CSimpleBaseTypeNode))
|
| 62 |
+
self.assertEqual(u"object", buftype.base_type_node.name)
|
| 63 |
+
return buftype
|
| 64 |
+
else:
|
| 65 |
+
self.assertTrue(len(root.stats[0].body.stats) == 0)
|
| 66 |
+
|
| 67 |
+
def non_parse(self, expected_err, opts):
|
| 68 |
+
self.parse_opts(opts, expect_error=True)
|
| 69 |
+
# e = self.should_fail(lambda: self.parse_opts(opts))
|
| 70 |
+
self.assertEqual(expected_err, self.error.message_only)
|
| 71 |
+
|
| 72 |
+
def __test_basic(self):
|
| 73 |
+
buf = self.parse_opts(u"unsigned short int, 3")
|
| 74 |
+
self.assertTrue(isinstance(buf.dtype_node, CSimpleBaseTypeNode))
|
| 75 |
+
self.assertTrue(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1)
|
| 76 |
+
self.assertEqual(3, buf.ndim)
|
| 77 |
+
|
| 78 |
+
def __test_dict(self):
|
| 79 |
+
buf = self.parse_opts(u"ndim=3, dtype=unsigned short int")
|
| 80 |
+
self.assertTrue(isinstance(buf.dtype_node, CSimpleBaseTypeNode))
|
| 81 |
+
self.assertTrue(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1)
|
| 82 |
+
self.assertEqual(3, buf.ndim)
|
| 83 |
+
|
| 84 |
+
def __test_ndim(self):
|
| 85 |
+
self.parse_opts(u"int, 2")
|
| 86 |
+
self.non_parse(ERR_BUF_NDIM, u"int, 'a'")
|
| 87 |
+
self.non_parse(ERR_BUF_NDIM, u"int, -34")
|
| 88 |
+
|
| 89 |
+
def __test_use_DEF(self):
|
| 90 |
+
t = self.fragment(u"""
|
| 91 |
+
DEF ndim = 3
|
| 92 |
+
def f():
|
| 93 |
+
cdef object[int, ndim] x
|
| 94 |
+
cdef object[ndim=ndim, dtype=int] y
|
| 95 |
+
""", pipeline=[NormalizeTree(self), PostParse(self)]).root
|
| 96 |
+
stats = t.stats[0].body.stats
|
| 97 |
+
self.assertTrue(stats[0].base_type.ndim == 3)
|
| 98 |
+
self.assertTrue(stats[1].base_type.ndim == 3)
|
| 99 |
+
|
| 100 |
+
# add exotic and impossible combinations as they come along...
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
if __name__ == '__main__':
|
| 104 |
+
import unittest
|
| 105 |
+
unittest.main()
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestCmdLine.py
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import re
|
| 4 |
+
from unittest import TestCase
|
| 5 |
+
try:
|
| 6 |
+
from unittest.mock import patch, Mock
|
| 7 |
+
except ImportError: # Py2
|
| 8 |
+
from mock import patch, Mock
|
| 9 |
+
try:
|
| 10 |
+
from StringIO import StringIO
|
| 11 |
+
except ImportError:
|
| 12 |
+
from io import StringIO # doesn't accept 'str' in Py2
|
| 13 |
+
|
| 14 |
+
from .. import Options
|
| 15 |
+
from ..CmdLine import parse_command_line
|
| 16 |
+
|
| 17 |
+
from .Utils import backup_Options, restore_Options, check_global_options
|
| 18 |
+
|
| 19 |
+
unpatched_exists = os.path.exists
|
| 20 |
+
|
| 21 |
+
def patched_exists(path):
|
| 22 |
+
# avoid the Cython command raising a file not found error
|
| 23 |
+
if path in (
|
| 24 |
+
'source.pyx',
|
| 25 |
+
os.path.join('/work/dir', 'source.pyx'),
|
| 26 |
+
os.path.join('my_working_path', 'source.pyx'),
|
| 27 |
+
'file.pyx',
|
| 28 |
+
'file1.pyx',
|
| 29 |
+
'file2.pyx',
|
| 30 |
+
'file3.pyx',
|
| 31 |
+
'foo.pyx',
|
| 32 |
+
'bar.pyx',
|
| 33 |
+
):
|
| 34 |
+
return True
|
| 35 |
+
return unpatched_exists(path)
|
| 36 |
+
|
| 37 |
+
@patch('os.path.exists', new=Mock(side_effect=patched_exists))
|
| 38 |
+
class CmdLineParserTest(TestCase):
|
| 39 |
+
def setUp(self):
|
| 40 |
+
self._options_backup = backup_Options()
|
| 41 |
+
|
| 42 |
+
def tearDown(self):
|
| 43 |
+
restore_Options(self._options_backup)
|
| 44 |
+
|
| 45 |
+
def check_default_global_options(self, white_list=[]):
|
| 46 |
+
self.assertEqual(check_global_options(self._options_backup, white_list), "")
|
| 47 |
+
|
| 48 |
+
def check_default_options(self, options, white_list=[]):
|
| 49 |
+
default_options = Options.CompilationOptions(Options.default_options)
|
| 50 |
+
no_value = object()
|
| 51 |
+
for name in default_options.__dict__.keys():
|
| 52 |
+
if name not in white_list:
|
| 53 |
+
self.assertEqual(getattr(options, name, no_value), getattr(default_options, name), msg="error in option " + name)
|
| 54 |
+
|
| 55 |
+
def test_short_options(self):
|
| 56 |
+
options, sources = parse_command_line([
|
| 57 |
+
'-V', '-l', '-+', '-t', '-v', '-v', '-v', '-p', '-D', '-a', '-3',
|
| 58 |
+
])
|
| 59 |
+
self.assertFalse(sources)
|
| 60 |
+
self.assertTrue(options.show_version)
|
| 61 |
+
self.assertTrue(options.use_listing_file)
|
| 62 |
+
self.assertTrue(options.cplus)
|
| 63 |
+
self.assertTrue(options.timestamps)
|
| 64 |
+
self.assertTrue(options.verbose >= 3)
|
| 65 |
+
self.assertTrue(Options.embed_pos_in_docstring)
|
| 66 |
+
self.assertFalse(Options.docstrings)
|
| 67 |
+
self.assertTrue(Options.annotate)
|
| 68 |
+
self.assertEqual(options.language_level, 3)
|
| 69 |
+
|
| 70 |
+
options, sources = parse_command_line([
|
| 71 |
+
'-f', '-2', 'source.pyx',
|
| 72 |
+
])
|
| 73 |
+
self.assertTrue(sources)
|
| 74 |
+
self.assertTrue(len(sources) == 1)
|
| 75 |
+
self.assertFalse(options.timestamps)
|
| 76 |
+
self.assertEqual(options.language_level, 2)
|
| 77 |
+
|
| 78 |
+
def test_long_options(self):
|
| 79 |
+
options, sources = parse_command_line([
|
| 80 |
+
'--version', '--create-listing', '--cplus', '--embed', '--timestamps',
|
| 81 |
+
'--verbose', '--verbose', '--verbose',
|
| 82 |
+
'--embed-positions', '--no-docstrings', '--annotate', '--lenient',
|
| 83 |
+
])
|
| 84 |
+
self.assertFalse(sources)
|
| 85 |
+
self.assertTrue(options.show_version)
|
| 86 |
+
self.assertTrue(options.use_listing_file)
|
| 87 |
+
self.assertTrue(options.cplus)
|
| 88 |
+
self.assertEqual(Options.embed, 'main')
|
| 89 |
+
self.assertTrue(options.timestamps)
|
| 90 |
+
self.assertTrue(options.verbose >= 3)
|
| 91 |
+
self.assertTrue(Options.embed_pos_in_docstring)
|
| 92 |
+
self.assertFalse(Options.docstrings)
|
| 93 |
+
self.assertTrue(Options.annotate)
|
| 94 |
+
self.assertFalse(Options.error_on_unknown_names)
|
| 95 |
+
self.assertFalse(Options.error_on_uninitialized)
|
| 96 |
+
|
| 97 |
+
options, sources = parse_command_line([
|
| 98 |
+
'--force', 'source.pyx',
|
| 99 |
+
])
|
| 100 |
+
self.assertTrue(sources)
|
| 101 |
+
self.assertTrue(len(sources) == 1)
|
| 102 |
+
self.assertFalse(options.timestamps)
|
| 103 |
+
|
| 104 |
+
def test_options_with_values(self):
|
| 105 |
+
options, sources = parse_command_line([
|
| 106 |
+
'--embed=huhu',
|
| 107 |
+
'-I/test/include/dir1', '--include-dir=/test/include/dir2',
|
| 108 |
+
'--include-dir', '/test/include/dir3',
|
| 109 |
+
'--working=/work/dir',
|
| 110 |
+
'source.pyx',
|
| 111 |
+
'--output-file=/output/dir',
|
| 112 |
+
'--pre-import=/pre/import',
|
| 113 |
+
'--cleanup=3',
|
| 114 |
+
'--annotate-coverage=cov.xml',
|
| 115 |
+
'--gdb-outdir=/gdb/outdir',
|
| 116 |
+
'--directive=wraparound=false',
|
| 117 |
+
])
|
| 118 |
+
self.assertEqual(sources, ['source.pyx'])
|
| 119 |
+
self.assertEqual(Options.embed, 'huhu')
|
| 120 |
+
self.assertEqual(options.include_path, ['/test/include/dir1', '/test/include/dir2', '/test/include/dir3'])
|
| 121 |
+
self.assertEqual(options.working_path, '/work/dir')
|
| 122 |
+
self.assertEqual(options.output_file, '/output/dir')
|
| 123 |
+
self.assertEqual(Options.pre_import, '/pre/import')
|
| 124 |
+
self.assertEqual(Options.generate_cleanup_code, 3)
|
| 125 |
+
self.assertTrue(Options.annotate)
|
| 126 |
+
self.assertEqual(Options.annotate_coverage_xml, 'cov.xml')
|
| 127 |
+
self.assertTrue(options.gdb_debug)
|
| 128 |
+
self.assertEqual(options.output_dir, '/gdb/outdir')
|
| 129 |
+
self.assertEqual(options.compiler_directives['wraparound'], False)
|
| 130 |
+
|
| 131 |
+
def test_embed_before_positional(self):
|
| 132 |
+
options, sources = parse_command_line([
|
| 133 |
+
'--embed',
|
| 134 |
+
'source.pyx',
|
| 135 |
+
])
|
| 136 |
+
self.assertEqual(sources, ['source.pyx'])
|
| 137 |
+
self.assertEqual(Options.embed, 'main')
|
| 138 |
+
|
| 139 |
+
def test_two_embeds(self):
|
| 140 |
+
options, sources = parse_command_line([
|
| 141 |
+
'--embed', '--embed=huhu',
|
| 142 |
+
'source.pyx',
|
| 143 |
+
])
|
| 144 |
+
self.assertEqual(sources, ['source.pyx'])
|
| 145 |
+
self.assertEqual(Options.embed, 'huhu')
|
| 146 |
+
|
| 147 |
+
def test_two_embeds2(self):
|
| 148 |
+
options, sources = parse_command_line([
|
| 149 |
+
'--embed=huhu', '--embed',
|
| 150 |
+
'source.pyx',
|
| 151 |
+
])
|
| 152 |
+
self.assertEqual(sources, ['source.pyx'])
|
| 153 |
+
self.assertEqual(Options.embed, 'main')
|
| 154 |
+
|
| 155 |
+
def test_no_annotate(self):
|
| 156 |
+
options, sources = parse_command_line([
|
| 157 |
+
'--embed=huhu', 'source.pyx'
|
| 158 |
+
])
|
| 159 |
+
self.assertFalse(Options.annotate)
|
| 160 |
+
|
| 161 |
+
def test_annotate_short(self):
|
| 162 |
+
options, sources = parse_command_line([
|
| 163 |
+
'-a',
|
| 164 |
+
'source.pyx',
|
| 165 |
+
])
|
| 166 |
+
self.assertEqual(Options.annotate, 'default')
|
| 167 |
+
|
| 168 |
+
def test_annotate_long(self):
|
| 169 |
+
options, sources = parse_command_line([
|
| 170 |
+
'--annotate',
|
| 171 |
+
'source.pyx',
|
| 172 |
+
])
|
| 173 |
+
self.assertEqual(Options.annotate, 'default')
|
| 174 |
+
|
| 175 |
+
def test_annotate_fullc(self):
|
| 176 |
+
options, sources = parse_command_line([
|
| 177 |
+
'--annotate-fullc',
|
| 178 |
+
'source.pyx',
|
| 179 |
+
])
|
| 180 |
+
self.assertEqual(Options.annotate, 'fullc')
|
| 181 |
+
|
| 182 |
+
def test_short_w(self):
|
| 183 |
+
options, sources = parse_command_line([
|
| 184 |
+
'-w', 'my_working_path',
|
| 185 |
+
'source.pyx'
|
| 186 |
+
])
|
| 187 |
+
self.assertEqual(options.working_path, 'my_working_path')
|
| 188 |
+
self.check_default_global_options()
|
| 189 |
+
self.check_default_options(options, ['working_path'])
|
| 190 |
+
|
| 191 |
+
def test_short_o(self):
|
| 192 |
+
options, sources = parse_command_line([
|
| 193 |
+
'-o', 'my_output',
|
| 194 |
+
'source.pyx'
|
| 195 |
+
])
|
| 196 |
+
self.assertEqual(options.output_file, 'my_output')
|
| 197 |
+
self.check_default_global_options()
|
| 198 |
+
self.check_default_options(options, ['output_file'])
|
| 199 |
+
|
| 200 |
+
def test_short_z(self):
|
| 201 |
+
options, sources = parse_command_line([
|
| 202 |
+
'-z', 'my_preimport',
|
| 203 |
+
'source.pyx'
|
| 204 |
+
])
|
| 205 |
+
self.assertEqual(Options.pre_import, 'my_preimport')
|
| 206 |
+
self.check_default_global_options(['pre_import'])
|
| 207 |
+
self.check_default_options(options)
|
| 208 |
+
|
| 209 |
+
def test_convert_range(self):
|
| 210 |
+
options, sources = parse_command_line([
|
| 211 |
+
'--convert-range',
|
| 212 |
+
'source.pyx'
|
| 213 |
+
])
|
| 214 |
+
self.assertEqual(Options.convert_range, True)
|
| 215 |
+
self.check_default_global_options(['convert_range'])
|
| 216 |
+
self.check_default_options(options)
|
| 217 |
+
|
| 218 |
+
def test_line_directives(self):
|
| 219 |
+
options, sources = parse_command_line([
|
| 220 |
+
'--line-directives',
|
| 221 |
+
'source.pyx'
|
| 222 |
+
])
|
| 223 |
+
self.assertEqual(options.emit_linenums, True)
|
| 224 |
+
self.check_default_global_options()
|
| 225 |
+
self.check_default_options(options, ['emit_linenums'])
|
| 226 |
+
|
| 227 |
+
def test_no_c_in_traceback(self):
|
| 228 |
+
options, sources = parse_command_line([
|
| 229 |
+
'--no-c-in-traceback',
|
| 230 |
+
'source.pyx'
|
| 231 |
+
])
|
| 232 |
+
self.assertEqual(options.c_line_in_traceback, False)
|
| 233 |
+
self.check_default_global_options()
|
| 234 |
+
self.check_default_options(options, ['c_line_in_traceback'])
|
| 235 |
+
|
| 236 |
+
def test_gdb(self):
|
| 237 |
+
options, sources = parse_command_line([
|
| 238 |
+
'--gdb',
|
| 239 |
+
'source.pyx'
|
| 240 |
+
])
|
| 241 |
+
self.assertEqual(options.gdb_debug, True)
|
| 242 |
+
self.assertEqual(options.output_dir, os.curdir)
|
| 243 |
+
self.check_default_global_options()
|
| 244 |
+
self.check_default_options(options, ['gdb_debug', 'output_dir'])
|
| 245 |
+
|
| 246 |
+
def test_3str(self):
|
| 247 |
+
options, sources = parse_command_line([
|
| 248 |
+
'--3str',
|
| 249 |
+
'source.pyx'
|
| 250 |
+
])
|
| 251 |
+
self.assertEqual(options.language_level, '3str')
|
| 252 |
+
self.check_default_global_options()
|
| 253 |
+
self.check_default_options(options, ['language_level'])
|
| 254 |
+
|
| 255 |
+
def test_capi_reexport_cincludes(self):
|
| 256 |
+
options, sources = parse_command_line([
|
| 257 |
+
'--capi-reexport-cincludes',
|
| 258 |
+
'source.pyx'
|
| 259 |
+
])
|
| 260 |
+
self.assertEqual(options.capi_reexport_cincludes, True)
|
| 261 |
+
self.check_default_global_options()
|
| 262 |
+
self.check_default_options(options, ['capi_reexport_cincludes'])
|
| 263 |
+
|
| 264 |
+
def test_fast_fail(self):
|
| 265 |
+
options, sources = parse_command_line([
|
| 266 |
+
'--fast-fail',
|
| 267 |
+
'source.pyx'
|
| 268 |
+
])
|
| 269 |
+
self.assertEqual(Options.fast_fail, True)
|
| 270 |
+
self.check_default_global_options(['fast_fail'])
|
| 271 |
+
self.check_default_options(options)
|
| 272 |
+
|
| 273 |
+
def test_cimport_from_pyx(self):
|
| 274 |
+
options, sources = parse_command_line([
|
| 275 |
+
'--cimport-from-pyx',
|
| 276 |
+
'source.pyx'
|
| 277 |
+
])
|
| 278 |
+
self.assertEqual(Options.cimport_from_pyx, True)
|
| 279 |
+
self.check_default_global_options(['cimport_from_pyx'])
|
| 280 |
+
self.check_default_options(options)
|
| 281 |
+
|
| 282 |
+
def test_Werror(self):
|
| 283 |
+
options, sources = parse_command_line([
|
| 284 |
+
'-Werror',
|
| 285 |
+
'source.pyx'
|
| 286 |
+
])
|
| 287 |
+
self.assertEqual(Options.warning_errors, True)
|
| 288 |
+
self.check_default_global_options(['warning_errors'])
|
| 289 |
+
self.check_default_options(options)
|
| 290 |
+
|
| 291 |
+
def test_warning_errors(self):
|
| 292 |
+
options, sources = parse_command_line([
|
| 293 |
+
'--warning-errors',
|
| 294 |
+
'source.pyx'
|
| 295 |
+
])
|
| 296 |
+
self.assertEqual(Options.warning_errors, True)
|
| 297 |
+
self.check_default_global_options(['warning_errors'])
|
| 298 |
+
self.check_default_options(options)
|
| 299 |
+
|
| 300 |
+
def test_Wextra(self):
|
| 301 |
+
options, sources = parse_command_line([
|
| 302 |
+
'-Wextra',
|
| 303 |
+
'source.pyx'
|
| 304 |
+
])
|
| 305 |
+
self.assertEqual(options.compiler_directives, Options.extra_warnings)
|
| 306 |
+
self.check_default_global_options()
|
| 307 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 308 |
+
|
| 309 |
+
def test_warning_extra(self):
|
| 310 |
+
options, sources = parse_command_line([
|
| 311 |
+
'--warning-extra',
|
| 312 |
+
'source.pyx'
|
| 313 |
+
])
|
| 314 |
+
self.assertEqual(options.compiler_directives, Options.extra_warnings)
|
| 315 |
+
self.check_default_global_options()
|
| 316 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 317 |
+
|
| 318 |
+
def test_old_style_globals(self):
|
| 319 |
+
options, sources = parse_command_line([
|
| 320 |
+
'--old-style-globals',
|
| 321 |
+
'source.pyx'
|
| 322 |
+
])
|
| 323 |
+
self.assertEqual(Options.old_style_globals, True)
|
| 324 |
+
self.check_default_global_options(['old_style_globals'])
|
| 325 |
+
self.check_default_options(options)
|
| 326 |
+
|
| 327 |
+
def test_directive_multiple(self):
|
| 328 |
+
options, source = parse_command_line([
|
| 329 |
+
'-X', 'cdivision=True',
|
| 330 |
+
'-X', 'c_string_type=bytes',
|
| 331 |
+
'source.pyx'
|
| 332 |
+
])
|
| 333 |
+
self.assertEqual(options.compiler_directives['cdivision'], True)
|
| 334 |
+
self.assertEqual(options.compiler_directives['c_string_type'], 'bytes')
|
| 335 |
+
self.check_default_global_options()
|
| 336 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 337 |
+
|
| 338 |
+
def test_directive_multiple_v2(self):
|
| 339 |
+
options, source = parse_command_line([
|
| 340 |
+
'-X', 'cdivision=True,c_string_type=bytes',
|
| 341 |
+
'source.pyx'
|
| 342 |
+
])
|
| 343 |
+
self.assertEqual(options.compiler_directives['cdivision'], True)
|
| 344 |
+
self.assertEqual(options.compiler_directives['c_string_type'], 'bytes')
|
| 345 |
+
self.check_default_global_options()
|
| 346 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 347 |
+
|
| 348 |
+
def test_directive_value_yes(self):
|
| 349 |
+
options, source = parse_command_line([
|
| 350 |
+
'-X', 'cdivision=YeS',
|
| 351 |
+
'source.pyx'
|
| 352 |
+
])
|
| 353 |
+
self.assertEqual(options.compiler_directives['cdivision'], True)
|
| 354 |
+
self.check_default_global_options()
|
| 355 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 356 |
+
|
| 357 |
+
def test_directive_value_no(self):
|
| 358 |
+
options, source = parse_command_line([
|
| 359 |
+
'-X', 'cdivision=no',
|
| 360 |
+
'source.pyx'
|
| 361 |
+
])
|
| 362 |
+
self.assertEqual(options.compiler_directives['cdivision'], False)
|
| 363 |
+
self.check_default_global_options()
|
| 364 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 365 |
+
|
| 366 |
+
def test_directive_value_invalid(self):
|
| 367 |
+
self.assertRaises(ValueError, parse_command_line, [
|
| 368 |
+
'-X', 'cdivision=sadfasd',
|
| 369 |
+
'source.pyx'
|
| 370 |
+
])
|
| 371 |
+
|
| 372 |
+
def test_directive_key_invalid(self):
|
| 373 |
+
self.assertRaises(ValueError, parse_command_line, [
|
| 374 |
+
'-X', 'abracadabra',
|
| 375 |
+
'source.pyx'
|
| 376 |
+
])
|
| 377 |
+
|
| 378 |
+
def test_directive_no_value(self):
|
| 379 |
+
self.assertRaises(ValueError, parse_command_line, [
|
| 380 |
+
'-X', 'cdivision',
|
| 381 |
+
'source.pyx'
|
| 382 |
+
])
|
| 383 |
+
|
| 384 |
+
def test_compile_time_env_short(self):
|
| 385 |
+
options, source = parse_command_line([
|
| 386 |
+
'-E', 'MYSIZE=10',
|
| 387 |
+
'source.pyx'
|
| 388 |
+
])
|
| 389 |
+
self.assertEqual(options.compile_time_env['MYSIZE'], 10)
|
| 390 |
+
self.check_default_global_options()
|
| 391 |
+
self.check_default_options(options, ['compile_time_env'])
|
| 392 |
+
|
| 393 |
+
def test_compile_time_env_long(self):
|
| 394 |
+
options, source = parse_command_line([
|
| 395 |
+
'--compile-time-env', 'MYSIZE=10',
|
| 396 |
+
'source.pyx'
|
| 397 |
+
])
|
| 398 |
+
self.assertEqual(options.compile_time_env['MYSIZE'], 10)
|
| 399 |
+
self.check_default_global_options()
|
| 400 |
+
self.check_default_options(options, ['compile_time_env'])
|
| 401 |
+
|
| 402 |
+
def test_compile_time_env_multiple(self):
|
| 403 |
+
options, source = parse_command_line([
|
| 404 |
+
'-E', 'MYSIZE=10', '-E', 'ARRSIZE=11',
|
| 405 |
+
'source.pyx'
|
| 406 |
+
])
|
| 407 |
+
self.assertEqual(options.compile_time_env['MYSIZE'], 10)
|
| 408 |
+
self.assertEqual(options.compile_time_env['ARRSIZE'], 11)
|
| 409 |
+
self.check_default_global_options()
|
| 410 |
+
self.check_default_options(options, ['compile_time_env'])
|
| 411 |
+
|
| 412 |
+
def test_compile_time_env_multiple_v2(self):
|
| 413 |
+
options, source = parse_command_line([
|
| 414 |
+
'-E', 'MYSIZE=10,ARRSIZE=11',
|
| 415 |
+
'source.pyx'
|
| 416 |
+
])
|
| 417 |
+
self.assertEqual(options.compile_time_env['MYSIZE'], 10)
|
| 418 |
+
self.assertEqual(options.compile_time_env['ARRSIZE'], 11)
|
| 419 |
+
self.check_default_global_options()
|
| 420 |
+
self.check_default_options(options, ['compile_time_env'])
|
| 421 |
+
|
| 422 |
+
def test_option_first(self):
|
| 423 |
+
options, sources = parse_command_line(['-V', 'file.pyx'])
|
| 424 |
+
self.assertEqual(sources, ['file.pyx'])
|
| 425 |
+
|
| 426 |
+
def test_file_inbetween(self):
|
| 427 |
+
options, sources = parse_command_line(['-V', 'file.pyx', '-a'])
|
| 428 |
+
self.assertEqual(sources, ['file.pyx'])
|
| 429 |
+
|
| 430 |
+
def test_option_trailing(self):
|
| 431 |
+
options, sources = parse_command_line(['file.pyx', '-V'])
|
| 432 |
+
self.assertEqual(sources, ['file.pyx'])
|
| 433 |
+
|
| 434 |
+
def test_multiple_files(self):
|
| 435 |
+
options, sources = parse_command_line([
|
| 436 |
+
'file1.pyx', '-V',
|
| 437 |
+
'file2.pyx', '-a',
|
| 438 |
+
'file3.pyx'
|
| 439 |
+
])
|
| 440 |
+
self.assertEqual(sources, ['file1.pyx', 'file2.pyx', 'file3.pyx'])
|
| 441 |
+
|
| 442 |
+
def test_debug_flags(self):
|
| 443 |
+
options, sources = parse_command_line([
|
| 444 |
+
'--debug-disposal-code', '--debug-coercion',
|
| 445 |
+
'file3.pyx'
|
| 446 |
+
])
|
| 447 |
+
from Cython.Compiler import DebugFlags
|
| 448 |
+
for name in ['debug_disposal_code', 'debug_temp_alloc', 'debug_coercion']:
|
| 449 |
+
self.assertEqual(getattr(DebugFlags, name), name in ['debug_disposal_code', 'debug_coercion'])
|
| 450 |
+
setattr(DebugFlags, name, 0) # restore original value
|
| 451 |
+
|
| 452 |
+
def test_gdb_overwrites_gdb_outdir(self):
|
| 453 |
+
options, sources = parse_command_line([
|
| 454 |
+
'--gdb-outdir=my_dir', '--gdb',
|
| 455 |
+
'file3.pyx'
|
| 456 |
+
])
|
| 457 |
+
self.assertEqual(options.gdb_debug, True)
|
| 458 |
+
self.assertEqual(options.output_dir, os.curdir)
|
| 459 |
+
self.check_default_global_options()
|
| 460 |
+
self.check_default_options(options, ['gdb_debug', 'output_dir'])
|
| 461 |
+
|
| 462 |
+
def test_gdb_first(self):
|
| 463 |
+
options, sources = parse_command_line([
|
| 464 |
+
'--gdb', '--gdb-outdir=my_dir',
|
| 465 |
+
'file3.pyx'
|
| 466 |
+
])
|
| 467 |
+
self.assertEqual(options.gdb_debug, True)
|
| 468 |
+
self.assertEqual(options.output_dir, 'my_dir')
|
| 469 |
+
self.check_default_global_options()
|
| 470 |
+
self.check_default_options(options, ['gdb_debug', 'output_dir'])
|
| 471 |
+
|
| 472 |
+
def test_coverage_overwrites_annotation(self):
|
| 473 |
+
options, sources = parse_command_line([
|
| 474 |
+
'--annotate-fullc', '--annotate-coverage=my.xml',
|
| 475 |
+
'file3.pyx'
|
| 476 |
+
])
|
| 477 |
+
self.assertEqual(Options.annotate, True)
|
| 478 |
+
self.assertEqual(Options.annotate_coverage_xml, 'my.xml')
|
| 479 |
+
self.check_default_global_options(['annotate', 'annotate_coverage_xml'])
|
| 480 |
+
self.check_default_options(options)
|
| 481 |
+
|
| 482 |
+
def test_coverage_first(self):
|
| 483 |
+
options, sources = parse_command_line([
|
| 484 |
+
'--annotate-coverage=my.xml', '--annotate-fullc',
|
| 485 |
+
'file3.pyx'
|
| 486 |
+
])
|
| 487 |
+
self.assertEqual(Options.annotate, 'fullc')
|
| 488 |
+
self.assertEqual(Options.annotate_coverage_xml, 'my.xml')
|
| 489 |
+
self.check_default_global_options(['annotate', 'annotate_coverage_xml'])
|
| 490 |
+
self.check_default_options(options)
|
| 491 |
+
|
| 492 |
+
def test_annotate_first_fullc_second(self):
|
| 493 |
+
options, sources = parse_command_line([
|
| 494 |
+
'--annotate', '--annotate-fullc',
|
| 495 |
+
'file3.pyx'
|
| 496 |
+
])
|
| 497 |
+
self.assertEqual(Options.annotate, 'fullc')
|
| 498 |
+
self.check_default_global_options(['annotate'])
|
| 499 |
+
self.check_default_options(options)
|
| 500 |
+
|
| 501 |
+
def test_annotate_fullc_first(self):
|
| 502 |
+
options, sources = parse_command_line([
|
| 503 |
+
'--annotate-fullc', '--annotate',
|
| 504 |
+
'file3.pyx'
|
| 505 |
+
])
|
| 506 |
+
self.assertEqual(Options.annotate, 'default')
|
| 507 |
+
self.check_default_global_options(['annotate'])
|
| 508 |
+
self.check_default_options(options)
|
| 509 |
+
|
| 510 |
+
def test_warning_extra_dont_overwrite(self):
|
| 511 |
+
options, sources = parse_command_line([
|
| 512 |
+
'-X', 'cdivision=True',
|
| 513 |
+
'--warning-extra',
|
| 514 |
+
'-X', 'c_string_type=bytes',
|
| 515 |
+
'source.pyx'
|
| 516 |
+
])
|
| 517 |
+
self.assertTrue(len(options.compiler_directives), len(Options.extra_warnings) + 1)
|
| 518 |
+
self.check_default_global_options()
|
| 519 |
+
self.check_default_options(options, ['compiler_directives'])
|
| 520 |
+
|
| 521 |
+
def test_module_name(self):
|
| 522 |
+
options, sources = parse_command_line([
|
| 523 |
+
'source.pyx'
|
| 524 |
+
])
|
| 525 |
+
self.assertEqual(options.module_name, None)
|
| 526 |
+
self.check_default_global_options()
|
| 527 |
+
self.check_default_options(options)
|
| 528 |
+
options, sources = parse_command_line([
|
| 529 |
+
'--module-name', 'foo.bar',
|
| 530 |
+
'source.pyx'
|
| 531 |
+
])
|
| 532 |
+
self.assertEqual(options.module_name, 'foo.bar')
|
| 533 |
+
self.check_default_global_options()
|
| 534 |
+
self.check_default_options(options, ['module_name'])
|
| 535 |
+
|
| 536 |
+
def test_errors(self):
|
| 537 |
+
def error(args, regex=None):
|
| 538 |
+
old_stderr = sys.stderr
|
| 539 |
+
stderr = sys.stderr = StringIO()
|
| 540 |
+
try:
|
| 541 |
+
self.assertRaises(SystemExit, parse_command_line, list(args))
|
| 542 |
+
finally:
|
| 543 |
+
sys.stderr = old_stderr
|
| 544 |
+
msg = stderr.getvalue()
|
| 545 |
+
err_msg = 'Message "{}"'.format(msg.strip())
|
| 546 |
+
self.assertTrue(msg.startswith('usage: '),
|
| 547 |
+
'%s does not start with "usage :"' % err_msg)
|
| 548 |
+
self.assertTrue(': error: ' in msg,
|
| 549 |
+
'%s does not contain ": error :"' % err_msg)
|
| 550 |
+
if regex:
|
| 551 |
+
self.assertTrue(re.search(regex, msg),
|
| 552 |
+
'%s does not match search "%s"' %
|
| 553 |
+
(err_msg, regex))
|
| 554 |
+
|
| 555 |
+
error(['-1'],
|
| 556 |
+
'unknown option -1')
|
| 557 |
+
error(['-I'],
|
| 558 |
+
'argument -I/--include-dir: expected one argument')
|
| 559 |
+
error(['--version=-a'],
|
| 560 |
+
"argument -V/--version: ignored explicit argument '-a'")
|
| 561 |
+
error(['--version=--annotate=true'],
|
| 562 |
+
"argument -V/--version: ignored explicit argument "
|
| 563 |
+
"'--annotate=true'")
|
| 564 |
+
error(['--working'],
|
| 565 |
+
"argument -w/--working: expected one argument")
|
| 566 |
+
error(['--verbose=1'],
|
| 567 |
+
"argument -v/--verbose: ignored explicit argument '1'")
|
| 568 |
+
error(['--cleanup'],
|
| 569 |
+
"argument --cleanup: expected one argument")
|
| 570 |
+
error(['--debug-disposal-code-wrong-name', 'file3.pyx'],
|
| 571 |
+
"unknown option --debug-disposal-code-wrong-name")
|
| 572 |
+
error(['--module-name', 'foo.pyx'],
|
| 573 |
+
"Need at least one source file")
|
| 574 |
+
error(['--module-name', 'foo.bar'],
|
| 575 |
+
"Need at least one source file")
|
| 576 |
+
error(['--module-name', 'foo.bar', 'foo.pyx', 'bar.pyx'],
|
| 577 |
+
"Only one source file allowed when using --module-name")
|
| 578 |
+
error(['--module-name', 'foo.bar', '--timestamps', 'foo.pyx'],
|
| 579 |
+
"Cannot use --module-name with --timestamps")
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestFlowControl.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from __future__ import absolute_import
|
| 3 |
+
|
| 4 |
+
from copy import deepcopy
|
| 5 |
+
from unittest import TestCase
|
| 6 |
+
|
| 7 |
+
from Cython.Compiler.FlowControl import (
|
| 8 |
+
NameAssignment, StaticAssignment, Argument, NameDeletion)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class FakeType(object):
|
| 12 |
+
is_pyobject = True
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class FakeNode(object):
|
| 16 |
+
pos = ('filename.pyx', 1, 2)
|
| 17 |
+
cf_state = None
|
| 18 |
+
type = FakeType()
|
| 19 |
+
|
| 20 |
+
def infer_type(self, scope):
|
| 21 |
+
return self.type
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class FakeEntry(object):
|
| 25 |
+
type = FakeType()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class TestGraph(TestCase):
|
| 29 |
+
def test_deepcopy(self):
|
| 30 |
+
lhs, rhs = FakeNode(), FakeNode()
|
| 31 |
+
entry = FakeEntry()
|
| 32 |
+
entry.pos = lhs.pos
|
| 33 |
+
|
| 34 |
+
name_ass = NameAssignment(lhs, rhs, entry)
|
| 35 |
+
ass = deepcopy(name_ass)
|
| 36 |
+
self.assertTrue(ass.lhs)
|
| 37 |
+
self.assertTrue(ass.rhs)
|
| 38 |
+
self.assertTrue(ass.entry)
|
| 39 |
+
self.assertEqual(ass.pos, name_ass.pos)
|
| 40 |
+
self.assertFalse(ass.is_arg)
|
| 41 |
+
self.assertFalse(ass.is_deletion)
|
| 42 |
+
|
| 43 |
+
static_ass = StaticAssignment(entry)
|
| 44 |
+
ass = deepcopy(static_ass)
|
| 45 |
+
self.assertTrue(ass.lhs)
|
| 46 |
+
self.assertTrue(ass.rhs)
|
| 47 |
+
self.assertTrue(ass.entry)
|
| 48 |
+
self.assertEqual(ass.pos, static_ass.pos)
|
| 49 |
+
self.assertFalse(ass.is_arg)
|
| 50 |
+
self.assertFalse(ass.is_deletion)
|
| 51 |
+
|
| 52 |
+
arg_ass = Argument(lhs, rhs, entry)
|
| 53 |
+
ass = deepcopy(arg_ass)
|
| 54 |
+
self.assertTrue(ass.lhs)
|
| 55 |
+
self.assertTrue(ass.rhs)
|
| 56 |
+
self.assertTrue(ass.entry)
|
| 57 |
+
self.assertEqual(ass.pos, arg_ass.pos)
|
| 58 |
+
self.assertTrue(ass.is_arg)
|
| 59 |
+
self.assertFalse(ass.is_deletion)
|
| 60 |
+
|
| 61 |
+
name_del = NameDeletion(lhs, entry)
|
| 62 |
+
ass = deepcopy(name_del)
|
| 63 |
+
self.assertTrue(ass.lhs)
|
| 64 |
+
self.assertTrue(ass.rhs)
|
| 65 |
+
self.assertTrue(ass.entry)
|
| 66 |
+
self.assertEqual(ass.pos, name_del.pos)
|
| 67 |
+
self.assertFalse(ass.is_arg)
|
| 68 |
+
self.assertTrue(ass.is_deletion)
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestMemView.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 *
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestMemviewParsing(CythonTest):
|
| 9 |
+
|
| 10 |
+
def parse(self, s):
|
| 11 |
+
return self.should_not_fail(lambda: self.fragment(s)).root
|
| 12 |
+
|
| 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)
|
| 16 |
+
|
| 17 |
+
def test_default_1dim(self):
|
| 18 |
+
self.parse(u"cdef int[:] x")
|
| 19 |
+
self.parse(u"cdef short int[:] x")
|
| 20 |
+
|
| 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")
|
| 25 |
+
|
| 26 |
+
def test_zero_offset(self):
|
| 27 |
+
self.parse(u"cdef long double[0:] x")
|
| 28 |
+
self.parse(u"cdef int[0:] x")
|
| 29 |
+
|
| 30 |
+
def test_zero_offset_ndim(self):
|
| 31 |
+
self.parse(u"cdef int[0:,0:,0:,0:] x")
|
| 32 |
+
|
| 33 |
+
def test_def_arg(self):
|
| 34 |
+
self.parse(u"def foo(int[:,:] x): pass")
|
| 35 |
+
|
| 36 |
+
def test_cdef_arg(self):
|
| 37 |
+
self.parse(u"cdef foo(int[:,:] x): pass")
|
| 38 |
+
|
| 39 |
+
def test_general_slice(self):
|
| 40 |
+
self.parse(u'cdef float[::ptr, ::direct & contig, 0::full & strided] x')
|
| 41 |
+
|
| 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")
|
| 47 |
+
|
| 48 |
+
def test_basic(self):
|
| 49 |
+
t = self.parse(u"cdef int[:] x")
|
| 50 |
+
memv_node = t.stats[0].base_type
|
| 51 |
+
self.assertTrue(isinstance(memv_node, MemoryViewSliceTypeNode))
|
| 52 |
+
|
| 53 |
+
# we also test other similar declarations (buffers, anonymous C arrays)
|
| 54 |
+
# since the parsing has to distinguish between them.
|
| 55 |
+
|
| 56 |
+
def disable_test_no_buf_arg(self): # TODO
|
| 57 |
+
self.not_parseable(u"Expected ']'",
|
| 58 |
+
u"cdef extern foo(object[int, ndim=2])")
|
| 59 |
+
|
| 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]")
|
| 68 |
+
|
| 69 |
+
if __name__ == '__main__':
|
| 70 |
+
import unittest
|
| 71 |
+
unittest.main()
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestParseTreeTransforms.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os.path
|
| 2 |
+
import unittest
|
| 3 |
+
|
| 4 |
+
from Cython.TestUtils import TransformTest
|
| 5 |
+
from Cython.Compiler.ParseTreeTransforms import *
|
| 6 |
+
from Cython.Compiler.ParseTreeTransforms import _calculate_pickle_checksums
|
| 7 |
+
from Cython.Compiler.Nodes import *
|
| 8 |
+
from Cython.Compiler import Main, Symtab, Options
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestNormalizeTree(TransformTest):
|
| 12 |
+
def test_parserbehaviour_is_what_we_coded_for(self):
|
| 13 |
+
t = self.fragment(u"if x: y").root
|
| 14 |
+
self.assertLines(u"""
|
| 15 |
+
(root): StatListNode
|
| 16 |
+
stats[0]: IfStatNode
|
| 17 |
+
if_clauses[0]: IfClauseNode
|
| 18 |
+
condition: NameNode
|
| 19 |
+
body: ExprStatNode
|
| 20 |
+
expr: NameNode
|
| 21 |
+
""", self.treetypes(t))
|
| 22 |
+
|
| 23 |
+
def test_wrap_singlestat(self):
|
| 24 |
+
t = self.run_pipeline([NormalizeTree(None)], u"if x: y")
|
| 25 |
+
self.assertLines(u"""
|
| 26 |
+
(root): StatListNode
|
| 27 |
+
stats[0]: IfStatNode
|
| 28 |
+
if_clauses[0]: IfClauseNode
|
| 29 |
+
condition: NameNode
|
| 30 |
+
body: StatListNode
|
| 31 |
+
stats[0]: ExprStatNode
|
| 32 |
+
expr: NameNode
|
| 33 |
+
""", self.treetypes(t))
|
| 34 |
+
|
| 35 |
+
def test_wrap_multistat(self):
|
| 36 |
+
t = self.run_pipeline([NormalizeTree(None)], u"""
|
| 37 |
+
if z:
|
| 38 |
+
x
|
| 39 |
+
y
|
| 40 |
+
""")
|
| 41 |
+
self.assertLines(u"""
|
| 42 |
+
(root): StatListNode
|
| 43 |
+
stats[0]: IfStatNode
|
| 44 |
+
if_clauses[0]: IfClauseNode
|
| 45 |
+
condition: NameNode
|
| 46 |
+
body: StatListNode
|
| 47 |
+
stats[0]: ExprStatNode
|
| 48 |
+
expr: NameNode
|
| 49 |
+
stats[1]: ExprStatNode
|
| 50 |
+
expr: NameNode
|
| 51 |
+
""", self.treetypes(t))
|
| 52 |
+
|
| 53 |
+
def test_statinexpr(self):
|
| 54 |
+
t = self.run_pipeline([NormalizeTree(None)], u"""
|
| 55 |
+
a, b = x, y
|
| 56 |
+
""")
|
| 57 |
+
self.assertLines(u"""
|
| 58 |
+
(root): StatListNode
|
| 59 |
+
stats[0]: SingleAssignmentNode
|
| 60 |
+
lhs: TupleNode
|
| 61 |
+
args[0]: NameNode
|
| 62 |
+
args[1]: NameNode
|
| 63 |
+
rhs: TupleNode
|
| 64 |
+
args[0]: NameNode
|
| 65 |
+
args[1]: NameNode
|
| 66 |
+
""", self.treetypes(t))
|
| 67 |
+
|
| 68 |
+
def test_wrap_offagain(self):
|
| 69 |
+
t = self.run_pipeline([NormalizeTree(None)], u"""
|
| 70 |
+
x
|
| 71 |
+
y
|
| 72 |
+
if z:
|
| 73 |
+
x
|
| 74 |
+
""")
|
| 75 |
+
self.assertLines(u"""
|
| 76 |
+
(root): StatListNode
|
| 77 |
+
stats[0]: ExprStatNode
|
| 78 |
+
expr: NameNode
|
| 79 |
+
stats[1]: ExprStatNode
|
| 80 |
+
expr: NameNode
|
| 81 |
+
stats[2]: IfStatNode
|
| 82 |
+
if_clauses[0]: IfClauseNode
|
| 83 |
+
condition: NameNode
|
| 84 |
+
body: StatListNode
|
| 85 |
+
stats[0]: ExprStatNode
|
| 86 |
+
expr: NameNode
|
| 87 |
+
""", self.treetypes(t))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_pass_eliminated(self):
|
| 91 |
+
t = self.run_pipeline([NormalizeTree(None)], u"pass")
|
| 92 |
+
self.assertTrue(len(t.stats) == 0)
|
| 93 |
+
|
| 94 |
+
class TestWithTransform(object): # (TransformTest): # Disabled!
|
| 95 |
+
|
| 96 |
+
def test_simplified(self):
|
| 97 |
+
t = self.run_pipeline([WithTransform(None)], u"""
|
| 98 |
+
with x:
|
| 99 |
+
y = z ** 3
|
| 100 |
+
""")
|
| 101 |
+
|
| 102 |
+
self.assertCode(u"""
|
| 103 |
+
|
| 104 |
+
$0_0 = x
|
| 105 |
+
$0_2 = $0_0.__exit__
|
| 106 |
+
$0_0.__enter__()
|
| 107 |
+
$0_1 = True
|
| 108 |
+
try:
|
| 109 |
+
try:
|
| 110 |
+
$1_0 = None
|
| 111 |
+
y = z ** 3
|
| 112 |
+
except:
|
| 113 |
+
$0_1 = False
|
| 114 |
+
if (not $0_2($1_0)):
|
| 115 |
+
raise
|
| 116 |
+
finally:
|
| 117 |
+
if $0_1:
|
| 118 |
+
$0_2(None, None, None)
|
| 119 |
+
|
| 120 |
+
""", t)
|
| 121 |
+
|
| 122 |
+
def test_basic(self):
|
| 123 |
+
t = self.run_pipeline([WithTransform(None)], u"""
|
| 124 |
+
with x as y:
|
| 125 |
+
y = z ** 3
|
| 126 |
+
""")
|
| 127 |
+
self.assertCode(u"""
|
| 128 |
+
|
| 129 |
+
$0_0 = x
|
| 130 |
+
$0_2 = $0_0.__exit__
|
| 131 |
+
$0_3 = $0_0.__enter__()
|
| 132 |
+
$0_1 = True
|
| 133 |
+
try:
|
| 134 |
+
try:
|
| 135 |
+
$1_0 = None
|
| 136 |
+
y = $0_3
|
| 137 |
+
y = z ** 3
|
| 138 |
+
except:
|
| 139 |
+
$0_1 = False
|
| 140 |
+
if (not $0_2($1_0)):
|
| 141 |
+
raise
|
| 142 |
+
finally:
|
| 143 |
+
if $0_1:
|
| 144 |
+
$0_2(None, None, None)
|
| 145 |
+
|
| 146 |
+
""", t)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class TestInterpretCompilerDirectives(TransformTest):
|
| 150 |
+
"""
|
| 151 |
+
This class tests the parallel directives AST-rewriting and importing.
|
| 152 |
+
"""
|
| 153 |
+
|
| 154 |
+
# Test the parallel directives (c)importing
|
| 155 |
+
|
| 156 |
+
import_code = u"""
|
| 157 |
+
cimport cython.parallel
|
| 158 |
+
cimport cython.parallel as par
|
| 159 |
+
from cython cimport parallel as par2
|
| 160 |
+
from cython cimport parallel
|
| 161 |
+
|
| 162 |
+
from cython.parallel cimport threadid as tid
|
| 163 |
+
from cython.parallel cimport threadavailable as tavail
|
| 164 |
+
from cython.parallel cimport prange
|
| 165 |
+
"""
|
| 166 |
+
|
| 167 |
+
expected_directives_dict = {
|
| 168 |
+
u'cython.parallel': u'cython.parallel',
|
| 169 |
+
u'par': u'cython.parallel',
|
| 170 |
+
u'par2': u'cython.parallel',
|
| 171 |
+
u'parallel': u'cython.parallel',
|
| 172 |
+
|
| 173 |
+
u"tid": u"cython.parallel.threadid",
|
| 174 |
+
u"tavail": u"cython.parallel.threadavailable",
|
| 175 |
+
u"prange": u"cython.parallel.prange",
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def setUp(self):
|
| 180 |
+
super(TestInterpretCompilerDirectives, self).setUp()
|
| 181 |
+
|
| 182 |
+
compilation_options = Options.CompilationOptions(Options.default_options)
|
| 183 |
+
ctx = Main.Context.from_options(compilation_options)
|
| 184 |
+
|
| 185 |
+
transform = InterpretCompilerDirectives(ctx, ctx.compiler_directives)
|
| 186 |
+
transform.module_scope = Symtab.ModuleScope('__main__', None, ctx)
|
| 187 |
+
self.pipeline = [transform]
|
| 188 |
+
|
| 189 |
+
self.debug_exception_on_error = DebugFlags.debug_exception_on_error
|
| 190 |
+
|
| 191 |
+
def tearDown(self):
|
| 192 |
+
DebugFlags.debug_exception_on_error = self.debug_exception_on_error
|
| 193 |
+
|
| 194 |
+
def test_parallel_directives_cimports(self):
|
| 195 |
+
self.run_pipeline(self.pipeline, self.import_code)
|
| 196 |
+
parallel_directives = self.pipeline[0].parallel_directives
|
| 197 |
+
self.assertEqual(parallel_directives, self.expected_directives_dict)
|
| 198 |
+
|
| 199 |
+
def test_parallel_directives_imports(self):
|
| 200 |
+
self.run_pipeline(self.pipeline,
|
| 201 |
+
self.import_code.replace(u'cimport', u'import'))
|
| 202 |
+
parallel_directives = self.pipeline[0].parallel_directives
|
| 203 |
+
self.assertEqual(parallel_directives, self.expected_directives_dict)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# TODO: Re-enable once they're more robust.
|
| 207 |
+
if False:
|
| 208 |
+
from Cython.Debugger import DebugWriter
|
| 209 |
+
from Cython.Debugger.Tests.TestLibCython import DebuggerTestCase
|
| 210 |
+
else:
|
| 211 |
+
# skip test, don't let it inherit unittest.TestCase
|
| 212 |
+
DebuggerTestCase = object
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
class TestDebugTransform(DebuggerTestCase):
|
| 216 |
+
|
| 217 |
+
def elem_hasattrs(self, elem, attrs):
|
| 218 |
+
return all(attr in elem.attrib for attr in attrs)
|
| 219 |
+
|
| 220 |
+
def test_debug_info(self):
|
| 221 |
+
try:
|
| 222 |
+
assert os.path.exists(self.debug_dest)
|
| 223 |
+
|
| 224 |
+
t = DebugWriter.etree.parse(self.debug_dest)
|
| 225 |
+
# the xpath of the standard ElementTree is primitive, don't use
|
| 226 |
+
# anything fancy
|
| 227 |
+
L = list(t.find('/Module/Globals'))
|
| 228 |
+
assert L
|
| 229 |
+
xml_globals = dict((e.attrib['name'], e.attrib['type']) for e in L)
|
| 230 |
+
self.assertEqual(len(L), len(xml_globals))
|
| 231 |
+
|
| 232 |
+
L = list(t.find('/Module/Functions'))
|
| 233 |
+
assert L
|
| 234 |
+
xml_funcs = dict((e.attrib['qualified_name'], e) for e in L)
|
| 235 |
+
self.assertEqual(len(L), len(xml_funcs))
|
| 236 |
+
|
| 237 |
+
# test globals
|
| 238 |
+
self.assertEqual('CObject', xml_globals.get('c_var'))
|
| 239 |
+
self.assertEqual('PythonObject', xml_globals.get('python_var'))
|
| 240 |
+
|
| 241 |
+
# test functions
|
| 242 |
+
funcnames = ('codefile.spam', 'codefile.ham', 'codefile.eggs',
|
| 243 |
+
'codefile.closure', 'codefile.inner')
|
| 244 |
+
required_xml_attrs = 'name', 'cname', 'qualified_name'
|
| 245 |
+
assert all(f in xml_funcs for f in funcnames)
|
| 246 |
+
spam, ham, eggs = [xml_funcs[funcname] for funcname in funcnames]
|
| 247 |
+
|
| 248 |
+
self.assertEqual(spam.attrib['name'], 'spam')
|
| 249 |
+
self.assertNotEqual('spam', spam.attrib['cname'])
|
| 250 |
+
assert self.elem_hasattrs(spam, required_xml_attrs)
|
| 251 |
+
|
| 252 |
+
# test locals of functions
|
| 253 |
+
spam_locals = list(spam.find('Locals'))
|
| 254 |
+
assert spam_locals
|
| 255 |
+
spam_locals.sort(key=lambda e: e.attrib['name'])
|
| 256 |
+
names = [e.attrib['name'] for e in spam_locals]
|
| 257 |
+
self.assertEqual(list('abcd'), names)
|
| 258 |
+
assert self.elem_hasattrs(spam_locals[0], required_xml_attrs)
|
| 259 |
+
|
| 260 |
+
# test arguments of functions
|
| 261 |
+
spam_arguments = list(spam.find('Arguments'))
|
| 262 |
+
assert spam_arguments
|
| 263 |
+
self.assertEqual(1, len(list(spam_arguments)))
|
| 264 |
+
|
| 265 |
+
# test step-into functions
|
| 266 |
+
step_into = spam.find('StepIntoFunctions')
|
| 267 |
+
spam_stepinto = [x.attrib['name'] for x in step_into]
|
| 268 |
+
assert spam_stepinto
|
| 269 |
+
self.assertEqual(2, len(spam_stepinto))
|
| 270 |
+
assert 'puts' in spam_stepinto
|
| 271 |
+
assert 'some_c_function' in spam_stepinto
|
| 272 |
+
except:
|
| 273 |
+
f = open(self.debug_dest)
|
| 274 |
+
try:
|
| 275 |
+
print(f.read())
|
| 276 |
+
finally:
|
| 277 |
+
f.close()
|
| 278 |
+
raise
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
class TestAnalyseDeclarationsTransform(unittest.TestCase):
|
| 282 |
+
def test_calculate_pickle_checksums(self):
|
| 283 |
+
checksums = _calculate_pickle_checksums(['member1', 'member2', 'member3'])
|
| 284 |
+
assert 2 <= len(checksums) <= 3, checksums # expecting ['0xc0af380' (MD5), '0x0c75bd4', '0xa7a7b94']
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
if __name__ == "__main__":
|
| 288 |
+
import unittest
|
| 289 |
+
unittest.main()
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestScanning.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import unicode_literals
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
from io import StringIO
|
| 5 |
+
import string
|
| 6 |
+
|
| 7 |
+
from .. import Scanning
|
| 8 |
+
from ..Symtab import ModuleScope
|
| 9 |
+
from ..TreeFragment import StringParseContext
|
| 10 |
+
from ..Errors import init_thread
|
| 11 |
+
|
| 12 |
+
# generate some fake code - just a bunch of lines of the form "a0 a1 ..."
|
| 13 |
+
code = []
|
| 14 |
+
for ch in string.ascii_lowercase:
|
| 15 |
+
line = " ".join(["%s%s" % (ch, n) for n in range(10)])
|
| 16 |
+
code.append(line)
|
| 17 |
+
code = "\n".join(code)
|
| 18 |
+
|
| 19 |
+
init_thread()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TestScanning(unittest.TestCase):
|
| 23 |
+
def make_scanner(self):
|
| 24 |
+
source = Scanning.StringSourceDescriptor("fake code", code)
|
| 25 |
+
buf = StringIO(code)
|
| 26 |
+
context = StringParseContext("fake context")
|
| 27 |
+
scope = ModuleScope("fake_module", None, None)
|
| 28 |
+
|
| 29 |
+
return Scanning.PyrexScanner(buf, source, scope=scope, context=context)
|
| 30 |
+
|
| 31 |
+
def test_put_back_positions(self):
|
| 32 |
+
scanner = self.make_scanner()
|
| 33 |
+
|
| 34 |
+
self.assertEqual(scanner.sy, "IDENT")
|
| 35 |
+
self.assertEqual(scanner.systring, "a0")
|
| 36 |
+
scanner.next()
|
| 37 |
+
self.assertEqual(scanner.sy, "IDENT")
|
| 38 |
+
self.assertEqual(scanner.systring, "a1")
|
| 39 |
+
a1pos = scanner.position()
|
| 40 |
+
self.assertEqual(a1pos[1:], (1, 3))
|
| 41 |
+
a2peek = scanner.peek() # shouldn't mess up the position
|
| 42 |
+
self.assertEqual(a1pos, scanner.position())
|
| 43 |
+
scanner.next()
|
| 44 |
+
self.assertEqual(a2peek, (scanner.sy, scanner.systring))
|
| 45 |
+
|
| 46 |
+
# find next line
|
| 47 |
+
while scanner.sy != "NEWLINE":
|
| 48 |
+
scanner.next()
|
| 49 |
+
|
| 50 |
+
line_sy = []
|
| 51 |
+
line_systring = []
|
| 52 |
+
line_pos = []
|
| 53 |
+
|
| 54 |
+
scanner.next()
|
| 55 |
+
while scanner.sy != "NEWLINE":
|
| 56 |
+
line_sy.append(scanner.sy)
|
| 57 |
+
line_systring.append(scanner.systring)
|
| 58 |
+
line_pos.append(scanner.position())
|
| 59 |
+
scanner.next()
|
| 60 |
+
|
| 61 |
+
for sy, systring, pos in zip(
|
| 62 |
+
line_sy[::-1], line_systring[::-1], line_pos[::-1]
|
| 63 |
+
):
|
| 64 |
+
scanner.put_back(sy, systring, pos)
|
| 65 |
+
|
| 66 |
+
n = 0
|
| 67 |
+
while scanner.sy != "NEWLINE":
|
| 68 |
+
self.assertEqual(scanner.sy, line_sy[n])
|
| 69 |
+
self.assertEqual(scanner.systring, line_systring[n])
|
| 70 |
+
self.assertEqual(scanner.position(), line_pos[n])
|
| 71 |
+
scanner.next()
|
| 72 |
+
n += 1
|
| 73 |
+
|
| 74 |
+
self.assertEqual(n, len(line_pos))
|
| 75 |
+
|
| 76 |
+
def test_tentatively_scan(self):
|
| 77 |
+
scanner = self.make_scanner()
|
| 78 |
+
with Scanning.tentatively_scan(scanner) as errors:
|
| 79 |
+
while scanner.sy != "NEWLINE":
|
| 80 |
+
scanner.next()
|
| 81 |
+
self.assertFalse(errors)
|
| 82 |
+
|
| 83 |
+
scanner.next()
|
| 84 |
+
self.assertEqual(scanner.systring, "b0")
|
| 85 |
+
pos = scanner.position()
|
| 86 |
+
with Scanning.tentatively_scan(scanner) as errors:
|
| 87 |
+
while scanner.sy != "NEWLINE":
|
| 88 |
+
scanner.next()
|
| 89 |
+
if scanner.systring == "b7":
|
| 90 |
+
scanner.error("Oh no not b7!")
|
| 91 |
+
break
|
| 92 |
+
self.assertTrue(errors)
|
| 93 |
+
self.assertEqual(scanner.systring, "b0") # state has been restored
|
| 94 |
+
self.assertEqual(scanner.position(), pos)
|
| 95 |
+
scanner.next()
|
| 96 |
+
self.assertEqual(scanner.systring, "b1") # and we can keep going again
|
| 97 |
+
scanner.next()
|
| 98 |
+
self.assertEqual(scanner.systring, "b2") # and we can keep going again
|
| 99 |
+
|
| 100 |
+
with Scanning.tentatively_scan(scanner) as error:
|
| 101 |
+
scanner.error("Something has gone wrong with the current symbol")
|
| 102 |
+
self.assertEqual(scanner.systring, "b2")
|
| 103 |
+
scanner.next()
|
| 104 |
+
self.assertEqual(scanner.systring, "b3")
|
| 105 |
+
|
| 106 |
+
# test a few combinations of nested scanning
|
| 107 |
+
sy1, systring1 = scanner.sy, scanner.systring
|
| 108 |
+
pos1 = scanner.position()
|
| 109 |
+
with Scanning.tentatively_scan(scanner):
|
| 110 |
+
scanner.next()
|
| 111 |
+
sy2, systring2 = scanner.sy, scanner.systring
|
| 112 |
+
pos2 = scanner.position()
|
| 113 |
+
with Scanning.tentatively_scan(scanner):
|
| 114 |
+
with Scanning.tentatively_scan(scanner):
|
| 115 |
+
scanner.next()
|
| 116 |
+
scanner.next()
|
| 117 |
+
scanner.error("Ooops")
|
| 118 |
+
self.assertEqual((scanner.sy, scanner.systring), (sy2, systring2))
|
| 119 |
+
self.assertEqual((scanner.sy, scanner.systring), (sy2, systring2))
|
| 120 |
+
scanner.error("eee")
|
| 121 |
+
self.assertEqual((scanner.sy, scanner.systring), (sy1, systring1))
|
| 122 |
+
with Scanning.tentatively_scan(scanner):
|
| 123 |
+
scanner.next()
|
| 124 |
+
scanner.next()
|
| 125 |
+
with Scanning.tentatively_scan(scanner):
|
| 126 |
+
scanner.next()
|
| 127 |
+
# no error - but this block should be unwound by the outer block too
|
| 128 |
+
scanner.next()
|
| 129 |
+
scanner.error("Oooops")
|
| 130 |
+
self.assertEqual((scanner.sy, scanner.systring), (sy1, systring1))
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
if __name__ == "__main__":
|
| 136 |
+
unittest.main()
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestSignatureMatching.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
|
| 3 |
+
from Cython.Compiler import PyrexTypes as pt
|
| 4 |
+
from Cython.Compiler.ExprNodes import NameNode
|
| 5 |
+
from Cython.Compiler.PyrexTypes import CFuncTypeArg
|
| 6 |
+
|
| 7 |
+
def cfunctype(*arg_types):
|
| 8 |
+
return pt.CFuncType(pt.c_int_type,
|
| 9 |
+
[ CFuncTypeArg("name", arg_type, None) for arg_type in arg_types ])
|
| 10 |
+
|
| 11 |
+
def cppclasstype(name, base_classes):
|
| 12 |
+
return pt.CppClassType(name, None, 'CPP_'+name, base_classes)
|
| 13 |
+
|
| 14 |
+
class SignatureMatcherTest(unittest.TestCase):
|
| 15 |
+
"""
|
| 16 |
+
Test the signature matching algorithm for overloaded signatures.
|
| 17 |
+
"""
|
| 18 |
+
def assertMatches(self, expected_type, arg_types, functions):
|
| 19 |
+
match = pt.best_match(arg_types, functions)
|
| 20 |
+
if expected_type is not None:
|
| 21 |
+
self.assertNotEqual(None, match)
|
| 22 |
+
self.assertEqual(expected_type, match.type)
|
| 23 |
+
|
| 24 |
+
def test_cpp_reference_single_arg(self):
|
| 25 |
+
function_types = [
|
| 26 |
+
cfunctype(pt.CReferenceType(pt.c_int_type)),
|
| 27 |
+
cfunctype(pt.CReferenceType(pt.c_long_type)),
|
| 28 |
+
cfunctype(pt.CReferenceType(pt.c_double_type)),
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
functions = [ NameNode(None, type=t) for t in function_types ]
|
| 32 |
+
self.assertMatches(function_types[0], [pt.c_int_type], functions)
|
| 33 |
+
self.assertMatches(function_types[1], [pt.c_long_type], functions)
|
| 34 |
+
self.assertMatches(function_types[2], [pt.c_double_type], functions)
|
| 35 |
+
|
| 36 |
+
def test_cpp_reference_two_args(self):
|
| 37 |
+
function_types = [
|
| 38 |
+
cfunctype(
|
| 39 |
+
pt.CReferenceType(pt.c_int_type), pt.CReferenceType(pt.c_long_type)),
|
| 40 |
+
cfunctype(
|
| 41 |
+
pt.CReferenceType(pt.c_long_type), pt.CReferenceType(pt.c_long_type)),
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
functions = [ NameNode(None, type=t) for t in function_types ]
|
| 45 |
+
self.assertMatches(function_types[0], [pt.c_int_type, pt.c_long_type], functions)
|
| 46 |
+
self.assertMatches(function_types[1], [pt.c_long_type, pt.c_long_type], functions)
|
| 47 |
+
self.assertMatches(function_types[1], [pt.c_long_type, pt.c_int_type], functions)
|
| 48 |
+
|
| 49 |
+
def test_cpp_reference_cpp_class(self):
|
| 50 |
+
classes = [ cppclasstype("Test%d" % i, []) for i in range(2) ]
|
| 51 |
+
function_types = [
|
| 52 |
+
cfunctype(pt.CReferenceType(classes[0])),
|
| 53 |
+
cfunctype(pt.CReferenceType(classes[1])),
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
functions = [ NameNode(None, type=t) for t in function_types ]
|
| 57 |
+
self.assertMatches(function_types[0], [classes[0]], functions)
|
| 58 |
+
self.assertMatches(function_types[1], [classes[1]], functions)
|
| 59 |
+
|
| 60 |
+
def test_cpp_reference_cpp_class_and_int(self):
|
| 61 |
+
classes = [ cppclasstype("Test%d" % i, []) for i in range(2) ]
|
| 62 |
+
function_types = [
|
| 63 |
+
cfunctype(pt.CReferenceType(classes[0]), pt.c_int_type),
|
| 64 |
+
cfunctype(pt.CReferenceType(classes[0]), pt.c_long_type),
|
| 65 |
+
cfunctype(pt.CReferenceType(classes[1]), pt.c_int_type),
|
| 66 |
+
cfunctype(pt.CReferenceType(classes[1]), pt.c_long_type),
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
functions = [ NameNode(None, type=t) for t in function_types ]
|
| 70 |
+
self.assertMatches(function_types[0], [classes[0], pt.c_int_type], functions)
|
| 71 |
+
self.assertMatches(function_types[1], [classes[0], pt.c_long_type], functions)
|
| 72 |
+
self.assertMatches(function_types[2], [classes[1], pt.c_int_type], functions)
|
| 73 |
+
self.assertMatches(function_types[3], [classes[1], pt.c_long_type], functions)
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestStringEncoding.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
import Cython.Compiler.StringEncoding as StringEncoding
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class StringEncodingTest(unittest.TestCase):
|
| 10 |
+
"""
|
| 11 |
+
Test the StringEncoding module.
|
| 12 |
+
"""
|
| 13 |
+
def test_string_contains_lone_surrogates(self):
|
| 14 |
+
self.assertFalse(StringEncoding.string_contains_lone_surrogates(u"abc"))
|
| 15 |
+
self.assertFalse(StringEncoding.string_contains_lone_surrogates(u"\uABCD"))
|
| 16 |
+
self.assertFalse(StringEncoding.string_contains_lone_surrogates(u"\N{SNOWMAN}"))
|
| 17 |
+
|
| 18 |
+
# This behaves differently in Py2 when freshly parsed and read from a .pyc file,
|
| 19 |
+
# but it seems to be a marshalling bug in Py2, which doesn't hurt us in Cython.
|
| 20 |
+
if sys.version_info[0] != 2:
|
| 21 |
+
self.assertTrue(StringEncoding.string_contains_lone_surrogates(u"\uD800\uDFFF"))
|
| 22 |
+
|
| 23 |
+
# In Py2 with 16bit Unicode, the following is indistinguishable from the 32bit character.
|
| 24 |
+
obfuscated_surrogate_pair = (u"\uDFFF" + "\uD800")[::-1]
|
| 25 |
+
if sys.version_info[0] == 2 and sys.maxunicode == 65565:
|
| 26 |
+
self.assertFalse(StringEncoding.string_contains_lone_surrogates(obfuscated_surrogate_pair))
|
| 27 |
+
else:
|
| 28 |
+
self.assertTrue(StringEncoding.string_contains_lone_surrogates(obfuscated_surrogate_pair))
|
| 29 |
+
|
| 30 |
+
self.assertTrue(StringEncoding.string_contains_lone_surrogates(u"\uD800"))
|
| 31 |
+
self.assertTrue(StringEncoding.string_contains_lone_surrogates(u"\uDFFF"))
|
| 32 |
+
self.assertTrue(StringEncoding.string_contains_lone_surrogates(u"\uDFFF\uD800"))
|
| 33 |
+
self.assertTrue(StringEncoding.string_contains_lone_surrogates(u"\uD800x\uDFFF"))
|
| 34 |
+
|
| 35 |
+
def test_string_contains_surrogates(self):
|
| 36 |
+
self.assertFalse(StringEncoding.string_contains_surrogates(u"abc"))
|
| 37 |
+
self.assertFalse(StringEncoding.string_contains_surrogates(u"\uABCD"))
|
| 38 |
+
self.assertFalse(StringEncoding.string_contains_surrogates(u"\N{SNOWMAN}"))
|
| 39 |
+
|
| 40 |
+
self.assertTrue(StringEncoding.string_contains_surrogates(u"\uD800"))
|
| 41 |
+
self.assertTrue(StringEncoding.string_contains_surrogates(u"\uDFFF"))
|
| 42 |
+
self.assertTrue(StringEncoding.string_contains_surrogates(u"\uD800\uDFFF"))
|
| 43 |
+
self.assertTrue(StringEncoding.string_contains_surrogates(u"\uDFFF\uD800"))
|
| 44 |
+
self.assertTrue(StringEncoding.string_contains_surrogates(u"\uD800x\uDFFF"))
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestTreeFragment.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from Cython.TestUtils import CythonTest
|
| 2 |
+
from Cython.Compiler.TreeFragment import *
|
| 3 |
+
from Cython.Compiler.Nodes import *
|
| 4 |
+
from Cython.Compiler.UtilNodes import *
|
| 5 |
+
|
| 6 |
+
class TestTreeFragments(CythonTest):
|
| 7 |
+
|
| 8 |
+
def test_basic(self):
|
| 9 |
+
F = self.fragment(u"x = 4")
|
| 10 |
+
T = F.copy()
|
| 11 |
+
self.assertCode(u"x = 4", T)
|
| 12 |
+
|
| 13 |
+
def test_copy_is_taken(self):
|
| 14 |
+
F = self.fragment(u"if True: x = 4")
|
| 15 |
+
T1 = F.root
|
| 16 |
+
T2 = F.copy()
|
| 17 |
+
self.assertEqual("x", T2.stats[0].if_clauses[0].body.lhs.name)
|
| 18 |
+
T2.stats[0].if_clauses[0].body.lhs.name = "other"
|
| 19 |
+
self.assertEqual("x", T1.stats[0].if_clauses[0].body.lhs.name)
|
| 20 |
+
|
| 21 |
+
def test_substitutions_are_copied(self):
|
| 22 |
+
T = self.fragment(u"y + y").substitute({"y": NameNode(pos=None, name="x")})
|
| 23 |
+
self.assertEqual("x", T.stats[0].expr.operand1.name)
|
| 24 |
+
self.assertEqual("x", T.stats[0].expr.operand2.name)
|
| 25 |
+
self.assertTrue(T.stats[0].expr.operand1 is not T.stats[0].expr.operand2)
|
| 26 |
+
|
| 27 |
+
def test_substitution(self):
|
| 28 |
+
F = self.fragment(u"x = 4")
|
| 29 |
+
y = NameNode(pos=None, name=u"y")
|
| 30 |
+
T = F.substitute({"x" : y})
|
| 31 |
+
self.assertCode(u"y = 4", T)
|
| 32 |
+
|
| 33 |
+
def test_exprstat(self):
|
| 34 |
+
F = self.fragment(u"PASS")
|
| 35 |
+
pass_stat = PassStatNode(pos=None)
|
| 36 |
+
T = F.substitute({"PASS" : pass_stat})
|
| 37 |
+
self.assertTrue(isinstance(T.stats[0], PassStatNode), T)
|
| 38 |
+
|
| 39 |
+
def test_pos_is_transferred(self):
|
| 40 |
+
F = self.fragment(u"""
|
| 41 |
+
x = y
|
| 42 |
+
x = u * v ** w
|
| 43 |
+
""")
|
| 44 |
+
T = F.substitute({"v" : NameNode(pos=None, name="a")})
|
| 45 |
+
v = F.root.stats[1].rhs.operand2.operand1
|
| 46 |
+
a = T.stats[1].rhs.operand2.operand1
|
| 47 |
+
self.assertEqual(v.pos, a.pos)
|
| 48 |
+
|
| 49 |
+
def test_temps(self):
|
| 50 |
+
TemplateTransform.temp_name_counter = 0
|
| 51 |
+
F = self.fragment(u"""
|
| 52 |
+
TMP
|
| 53 |
+
x = TMP
|
| 54 |
+
""")
|
| 55 |
+
T = F.substitute(temps=[u"TMP"])
|
| 56 |
+
s = T.body.stats
|
| 57 |
+
self.assertTrue(isinstance(s[0].expr, TempRefNode))
|
| 58 |
+
self.assertTrue(isinstance(s[1].rhs, TempRefNode))
|
| 59 |
+
self.assertTrue(s[0].expr.handle is s[1].rhs.handle)
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
import unittest
|
| 63 |
+
unittest.main()
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestTreePath.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
from Cython.TestUtils import TransformTest
|
| 3 |
+
from Cython.Compiler.TreePath import find_first, find_all
|
| 4 |
+
from Cython.Compiler import Nodes, ExprNodes
|
| 5 |
+
|
| 6 |
+
class TestTreePath(TransformTest):
|
| 7 |
+
_tree = None
|
| 8 |
+
|
| 9 |
+
def _build_tree(self):
|
| 10 |
+
if self._tree is None:
|
| 11 |
+
self._tree = self.run_pipeline([], u"""
|
| 12 |
+
def decorator(fun): # DefNode
|
| 13 |
+
return fun # ReturnStatNode, NameNode
|
| 14 |
+
@decorator # NameNode
|
| 15 |
+
def decorated(): # DefNode
|
| 16 |
+
pass
|
| 17 |
+
""")
|
| 18 |
+
return self._tree
|
| 19 |
+
|
| 20 |
+
def test_node_path(self):
|
| 21 |
+
t = self._build_tree()
|
| 22 |
+
self.assertEqual(2, len(find_all(t, "//DefNode")))
|
| 23 |
+
self.assertEqual(2, len(find_all(t, "//NameNode")))
|
| 24 |
+
self.assertEqual(1, len(find_all(t, "//ReturnStatNode")))
|
| 25 |
+
self.assertEqual(1, len(find_all(t, "//DefNode//ReturnStatNode")))
|
| 26 |
+
|
| 27 |
+
def test_node_path_star(self):
|
| 28 |
+
t = self._build_tree()
|
| 29 |
+
self.assertEqual(10, len(find_all(t, "//*")))
|
| 30 |
+
self.assertEqual(8, len(find_all(t, "//DefNode//*")))
|
| 31 |
+
self.assertEqual(0, len(find_all(t, "//NameNode//*")))
|
| 32 |
+
|
| 33 |
+
def test_node_path_attribute(self):
|
| 34 |
+
t = self._build_tree()
|
| 35 |
+
self.assertEqual(2, len(find_all(t, "//NameNode/@name")))
|
| 36 |
+
self.assertEqual(['fun', 'decorator'], find_all(t, "//NameNode/@name"))
|
| 37 |
+
|
| 38 |
+
def test_node_path_attribute_dotted(self):
|
| 39 |
+
t = self._build_tree()
|
| 40 |
+
self.assertEqual(1, len(find_all(t, "//ReturnStatNode/@value.name")))
|
| 41 |
+
self.assertEqual(['fun'], find_all(t, "//ReturnStatNode/@value.name"))
|
| 42 |
+
|
| 43 |
+
def test_node_path_child(self):
|
| 44 |
+
t = self._build_tree()
|
| 45 |
+
self.assertEqual(1, len(find_all(t, "//DefNode/ReturnStatNode/NameNode")))
|
| 46 |
+
self.assertEqual(1, len(find_all(t, "//ReturnStatNode/NameNode")))
|
| 47 |
+
|
| 48 |
+
def test_node_path_node_predicate(self):
|
| 49 |
+
t = self._build_tree()
|
| 50 |
+
self.assertEqual(0, len(find_all(t, "//DefNode[.//ForInStatNode]")))
|
| 51 |
+
self.assertEqual(2, len(find_all(t, "//DefNode[.//NameNode]")))
|
| 52 |
+
self.assertEqual(1, len(find_all(t, "//ReturnStatNode[./NameNode]")))
|
| 53 |
+
self.assertEqual(Nodes.ReturnStatNode,
|
| 54 |
+
type(find_first(t, "//ReturnStatNode[./NameNode]")))
|
| 55 |
+
|
| 56 |
+
def test_node_path_node_predicate_step(self):
|
| 57 |
+
t = self._build_tree()
|
| 58 |
+
self.assertEqual(2, len(find_all(t, "//DefNode[.//NameNode]")))
|
| 59 |
+
self.assertEqual(8, len(find_all(t, "//DefNode[.//NameNode]//*")))
|
| 60 |
+
self.assertEqual(1, len(find_all(t, "//DefNode[.//NameNode]//ReturnStatNode")))
|
| 61 |
+
self.assertEqual(Nodes.ReturnStatNode,
|
| 62 |
+
type(find_first(t, "//DefNode[.//NameNode]//ReturnStatNode")))
|
| 63 |
+
|
| 64 |
+
def test_node_path_attribute_exists(self):
|
| 65 |
+
t = self._build_tree()
|
| 66 |
+
self.assertEqual(2, len(find_all(t, "//NameNode[@name]")))
|
| 67 |
+
self.assertEqual(ExprNodes.NameNode,
|
| 68 |
+
type(find_first(t, "//NameNode[@name]")))
|
| 69 |
+
|
| 70 |
+
def test_node_path_attribute_exists_not(self):
|
| 71 |
+
t = self._build_tree()
|
| 72 |
+
self.assertEqual(0, len(find_all(t, "//NameNode[not(@name)]")))
|
| 73 |
+
self.assertEqual(2, len(find_all(t, "//NameNode[not(@honking)]")))
|
| 74 |
+
|
| 75 |
+
def test_node_path_and(self):
|
| 76 |
+
t = self._build_tree()
|
| 77 |
+
self.assertEqual(1, len(find_all(t, "//DefNode[.//ReturnStatNode and .//NameNode]")))
|
| 78 |
+
self.assertEqual(0, len(find_all(t, "//NameNode[@honking and @name]")))
|
| 79 |
+
self.assertEqual(0, len(find_all(t, "//NameNode[@name and @honking]")))
|
| 80 |
+
self.assertEqual(2, len(find_all(t, "//DefNode[.//NameNode[@name] and @name]")))
|
| 81 |
+
|
| 82 |
+
def test_node_path_attribute_string_predicate(self):
|
| 83 |
+
t = self._build_tree()
|
| 84 |
+
self.assertEqual(1, len(find_all(t, "//NameNode[@name = 'decorator']")))
|
| 85 |
+
|
| 86 |
+
def test_node_path_recursive_predicate(self):
|
| 87 |
+
t = self._build_tree()
|
| 88 |
+
self.assertEqual(2, len(find_all(t, "//DefNode[.//NameNode[@name]]")))
|
| 89 |
+
self.assertEqual(1, len(find_all(t, "//DefNode[.//NameNode[@name = 'decorator']]")))
|
| 90 |
+
self.assertEqual(1, len(find_all(t, "//DefNode[.//ReturnStatNode[./NameNode[@name = 'fun']]/NameNode]")))
|
| 91 |
+
|
| 92 |
+
if __name__ == '__main__':
|
| 93 |
+
unittest.main()
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestUtilityLoad.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
|
| 3 |
+
from Cython.Compiler import Code, UtilityCode
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def strip_2tup(tup):
|
| 7 |
+
return tup[0] and tup[0].strip(), tup[1] and tup[1].strip()
|
| 8 |
+
|
| 9 |
+
class TestUtilityLoader(unittest.TestCase):
|
| 10 |
+
"""
|
| 11 |
+
Test loading UtilityCodes
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
expected = "test {{loader}} prototype", "test {{loader}} impl"
|
| 15 |
+
|
| 16 |
+
required = "req {{loader}} proto", "req {{loader}} impl"
|
| 17 |
+
|
| 18 |
+
context = dict(loader='Loader')
|
| 19 |
+
|
| 20 |
+
name = "TestUtilityLoader"
|
| 21 |
+
filename = "TestUtilityLoader.c"
|
| 22 |
+
cls = Code.UtilityCode
|
| 23 |
+
|
| 24 |
+
def test_load_as_string(self):
|
| 25 |
+
got = strip_2tup(self.cls.load_as_string(self.name, self.filename))
|
| 26 |
+
self.assertEqual(got, self.expected)
|
| 27 |
+
|
| 28 |
+
def test_load(self):
|
| 29 |
+
utility = self.cls.load(self.name, from_file=self.filename)
|
| 30 |
+
got = strip_2tup((utility.proto, utility.impl))
|
| 31 |
+
self.assertEqual(got, self.expected)
|
| 32 |
+
|
| 33 |
+
required, = utility.requires
|
| 34 |
+
got = strip_2tup((required.proto, required.impl))
|
| 35 |
+
self.assertEqual(got, self.required)
|
| 36 |
+
|
| 37 |
+
utility = self.cls.load_cached(self.name, from_file=self.filename)
|
| 38 |
+
got = strip_2tup((utility.proto, utility.impl))
|
| 39 |
+
self.assertEqual(got, self.expected)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class TestTempitaUtilityLoader(TestUtilityLoader):
|
| 43 |
+
"""
|
| 44 |
+
Test loading UtilityCodes with Tempita substitution
|
| 45 |
+
"""
|
| 46 |
+
expected_tempita = (TestUtilityLoader.expected[0].replace('{{loader}}', 'Loader'),
|
| 47 |
+
TestUtilityLoader.expected[1].replace('{{loader}}', 'Loader'))
|
| 48 |
+
|
| 49 |
+
required_tempita = (TestUtilityLoader.required[0].replace('{{loader}}', 'Loader'),
|
| 50 |
+
TestUtilityLoader.required[1].replace('{{loader}}', 'Loader'))
|
| 51 |
+
|
| 52 |
+
cls = Code.TempitaUtilityCode
|
| 53 |
+
|
| 54 |
+
def test_load_as_string(self):
|
| 55 |
+
got = strip_2tup(self.cls.load_as_string(self.name, self.filename, context=self.context))
|
| 56 |
+
self.assertEqual(got, self.expected_tempita)
|
| 57 |
+
|
| 58 |
+
def test_load(self):
|
| 59 |
+
utility = self.cls.load(self.name, self.filename, context=self.context)
|
| 60 |
+
got = strip_2tup((utility.proto, utility.impl))
|
| 61 |
+
self.assertEqual(got, self.expected_tempita)
|
| 62 |
+
|
| 63 |
+
required, = utility.requires
|
| 64 |
+
got = strip_2tup((required.proto, required.impl))
|
| 65 |
+
self.assertEqual(got, self.required_tempita)
|
| 66 |
+
|
| 67 |
+
utility = self.cls.load(self.name, from_file=self.filename, context=self.context)
|
| 68 |
+
got = strip_2tup((utility.proto, utility.impl))
|
| 69 |
+
self.assertEqual(got, self.expected_tempita)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class TestCythonUtilityLoader(TestTempitaUtilityLoader):
|
| 73 |
+
"""
|
| 74 |
+
Test loading CythonUtilityCodes
|
| 75 |
+
"""
|
| 76 |
+
|
| 77 |
+
# Just change the attributes and run the same tests
|
| 78 |
+
expected = None, "test {{cy_loader}} impl"
|
| 79 |
+
expected_tempita = None, "test CyLoader impl"
|
| 80 |
+
|
| 81 |
+
required = None, "req {{cy_loader}} impl"
|
| 82 |
+
required_tempita = None, "req CyLoader impl"
|
| 83 |
+
|
| 84 |
+
context = dict(cy_loader='CyLoader')
|
| 85 |
+
|
| 86 |
+
name = "TestCyUtilityLoader"
|
| 87 |
+
filename = "TestCyUtilityLoader.pyx"
|
| 88 |
+
cls = UtilityCode.CythonUtilityCode
|
| 89 |
+
|
| 90 |
+
# Small hack to pass our tests above
|
| 91 |
+
cls.proto = None
|
| 92 |
+
|
| 93 |
+
test_load = TestUtilityLoader.test_load
|
| 94 |
+
test_load_tempita = TestTempitaUtilityLoader.test_load
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class TestUtilityCode(unittest.TestCase):
|
| 98 |
+
def test_equality(self):
|
| 99 |
+
c1 = Code.UtilityCode.load("NumpyImportUFunc", "NumpyImportArray.c")
|
| 100 |
+
c2 = Code.UtilityCode.load("NumpyImportArray", "NumpyImportArray.c")
|
| 101 |
+
c3 = Code.UtilityCode.load("pyunicode_strlen", "StringTools.c")
|
| 102 |
+
c4 = Code.UtilityCode.load("pyunicode_from_unicode", "StringTools.c")
|
| 103 |
+
c5 = Code.UtilityCode.load("IncludeStringH", "StringTools.c")
|
| 104 |
+
c6 = Code.UtilityCode.load("IncludeCppStringH", "StringTools.c")
|
| 105 |
+
|
| 106 |
+
codes = [c1, c2, c3, c4, c5, c6]
|
| 107 |
+
for m in range(len(codes)):
|
| 108 |
+
for n in range(len(codes)):
|
| 109 |
+
if n == m:
|
| 110 |
+
self.assertEqual(codes[m], codes[n])
|
| 111 |
+
else:
|
| 112 |
+
self.assertNotEqual(codes[m], codes[n])
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/TestVisitor.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from Cython.Compiler.ModuleNode import ModuleNode
|
| 2 |
+
from Cython.Compiler.Symtab import ModuleScope
|
| 3 |
+
from Cython.TestUtils import TransformTest
|
| 4 |
+
from Cython.Compiler.Visitor import MethodDispatcherTransform
|
| 5 |
+
from Cython.Compiler.ParseTreeTransforms import (
|
| 6 |
+
NormalizeTree, AnalyseDeclarationsTransform,
|
| 7 |
+
AnalyseExpressionsTransform, InterpretCompilerDirectives)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestMethodDispatcherTransform(TransformTest):
|
| 11 |
+
_tree = None
|
| 12 |
+
|
| 13 |
+
def _build_tree(self):
|
| 14 |
+
if self._tree is None:
|
| 15 |
+
context = None
|
| 16 |
+
|
| 17 |
+
def fake_module(node):
|
| 18 |
+
scope = ModuleScope('test', None, None)
|
| 19 |
+
return ModuleNode(node.pos, doc=None, body=node,
|
| 20 |
+
scope=scope, full_module_name='test',
|
| 21 |
+
directive_comments={})
|
| 22 |
+
pipeline = [
|
| 23 |
+
fake_module,
|
| 24 |
+
NormalizeTree(context),
|
| 25 |
+
InterpretCompilerDirectives(context, {}),
|
| 26 |
+
AnalyseDeclarationsTransform(context),
|
| 27 |
+
AnalyseExpressionsTransform(context),
|
| 28 |
+
]
|
| 29 |
+
self._tree = self.run_pipeline(pipeline, u"""
|
| 30 |
+
cdef bytes s = b'asdfg'
|
| 31 |
+
cdef dict d = {1:2}
|
| 32 |
+
x = s * 3
|
| 33 |
+
d.get('test')
|
| 34 |
+
""")
|
| 35 |
+
return self._tree
|
| 36 |
+
|
| 37 |
+
def test_builtin_method(self):
|
| 38 |
+
calls = [0]
|
| 39 |
+
class Test(MethodDispatcherTransform):
|
| 40 |
+
def _handle_simple_method_dict_get(self, node, func, args, unbound):
|
| 41 |
+
calls[0] += 1
|
| 42 |
+
return node
|
| 43 |
+
|
| 44 |
+
tree = self._build_tree()
|
| 45 |
+
Test(None)(tree)
|
| 46 |
+
self.assertEqual(1, calls[0])
|
| 47 |
+
|
| 48 |
+
def test_binop_method(self):
|
| 49 |
+
calls = {'bytes': 0, 'object': 0}
|
| 50 |
+
class Test(MethodDispatcherTransform):
|
| 51 |
+
def _handle_simple_method_bytes___mul__(self, node, func, args, unbound):
|
| 52 |
+
calls['bytes'] += 1
|
| 53 |
+
return node
|
| 54 |
+
def _handle_simple_method_object___mul__(self, node, func, args, unbound):
|
| 55 |
+
calls['object'] += 1
|
| 56 |
+
return node
|
| 57 |
+
|
| 58 |
+
tree = self._build_tree()
|
| 59 |
+
Test(None)(tree)
|
| 60 |
+
self.assertEqual(1, calls['bytes'])
|
| 61 |
+
self.assertEqual(0, calls['object'])
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/Utils.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
|
| 3 |
+
from .. import Options
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def backup_Options():
|
| 7 |
+
backup = {}
|
| 8 |
+
for name, value in vars(Options).items():
|
| 9 |
+
# we need a deep copy of _directive_defaults, because they can be changed
|
| 10 |
+
if name == '_directive_defaults':
|
| 11 |
+
value = copy.deepcopy(value)
|
| 12 |
+
backup[name] = value
|
| 13 |
+
return backup
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def restore_Options(backup):
|
| 17 |
+
no_value = object()
|
| 18 |
+
for name, orig_value in backup.items():
|
| 19 |
+
if getattr(Options, name, no_value) != orig_value:
|
| 20 |
+
setattr(Options, name, orig_value)
|
| 21 |
+
# strip Options from new keys that might have been added:
|
| 22 |
+
for name in vars(Options).keys():
|
| 23 |
+
if name not in backup:
|
| 24 |
+
delattr(Options, name)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def check_global_options(expected_options, white_list=[]):
|
| 28 |
+
"""
|
| 29 |
+
returns error message of "" if check Ok
|
| 30 |
+
"""
|
| 31 |
+
no_value = object()
|
| 32 |
+
for name, orig_value in expected_options.items():
|
| 33 |
+
if name not in white_list:
|
| 34 |
+
if getattr(Options, name, no_value) != orig_value:
|
| 35 |
+
return "error in option " + name
|
| 36 |
+
return ""
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# empty file
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__pycache__/TestMemView.cpython-311.pyc
ADDED
|
Binary file (5.94 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__pycache__/TestTreePath.cpython-311.pyc
ADDED
|
Binary file (9.89 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/Tests/__pycache__/TestVisitor.cpython-311.pyc
ADDED
|
Binary file (4.68 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/__pycache__/Dataclass.cpython-311.pyc
ADDED
|
Binary file (42.5 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/Cython/Compiler/__pycache__/TreePath.cpython-311.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/networkx/algorithms/__pycache__/communicability_alg.cpython-311.pyc
ADDED
|
Binary file (5.95 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/networkx/algorithms/__pycache__/core.cpython-311.pyc
ADDED
|
Binary file (20.1 kB). View file
|
|
|
tuning-competition-baseline/.venv/lib/python3.11/site-packages/networkx/algorithms/__pycache__/distance_measures.cpython-311.pyc
ADDED
|
Binary file (33.1 kB). View file
|
|
|