Cython 3.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +250 -0
  4. Cython/Build/Dependencies.py +1275 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +342 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/Tests/TestCyCache.py +119 -0
  9. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  10. Cython/Build/Tests/TestDependencies.py +133 -0
  11. Cython/Build/Tests/TestInline.py +112 -0
  12. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  13. Cython/Build/Tests/TestRecythonize.py +212 -0
  14. Cython/Build/Tests/TestStripLiterals.py +155 -0
  15. Cython/Build/Tests/__init__.py +1 -0
  16. Cython/Build/__init__.py +8 -0
  17. Cython/CodeWriter.py +811 -0
  18. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  19. Cython/Compiler/Annotate.py +326 -0
  20. Cython/Compiler/AutoDocTransforms.py +314 -0
  21. Cython/Compiler/Buffer.py +680 -0
  22. Cython/Compiler/Builtin.py +862 -0
  23. Cython/Compiler/CmdLine.py +243 -0
  24. Cython/Compiler/Code.pxd +145 -0
  25. Cython/Compiler/Code.py +3328 -0
  26. Cython/Compiler/CodeGeneration.py +33 -0
  27. Cython/Compiler/CythonScope.py +179 -0
  28. Cython/Compiler/Dataclass.py +868 -0
  29. Cython/Compiler/DebugFlags.py +21 -0
  30. Cython/Compiler/Errors.py +295 -0
  31. Cython/Compiler/ExprNodes.py +15051 -0
  32. Cython/Compiler/FlowControl.pxd +97 -0
  33. Cython/Compiler/FlowControl.py +1438 -0
  34. Cython/Compiler/FusedNode.py +998 -0
  35. Cython/Compiler/Future.py +16 -0
  36. Cython/Compiler/Interpreter.py +57 -0
  37. Cython/Compiler/Lexicon.py +340 -0
  38. Cython/Compiler/LineTable.py +114 -0
  39. Cython/Compiler/Main.py +779 -0
  40. Cython/Compiler/MatchCaseNodes.py +259 -0
  41. Cython/Compiler/MemoryView.py +860 -0
  42. Cython/Compiler/ModuleNode.py +4065 -0
  43. Cython/Compiler/Naming.py +369 -0
  44. Cython/Compiler/Nodes.py +10557 -0
  45. Cython/Compiler/Optimize.py +5269 -0
  46. Cython/Compiler/Options.py +828 -0
  47. Cython/Compiler/ParseTreeTransforms.pxd +78 -0
  48. Cython/Compiler/ParseTreeTransforms.py +4441 -0
  49. Cython/Compiler/Parsing.pxd +9 -0
  50. Cython/Compiler/Parsing.py +4797 -0
  51. Cython/Compiler/Pipeline.py +425 -0
  52. Cython/Compiler/PyrexTypes.py +5572 -0
  53. Cython/Compiler/Pythran.py +223 -0
  54. Cython/Compiler/Scanning.pxd +40 -0
  55. Cython/Compiler/Scanning.py +574 -0
  56. Cython/Compiler/StringEncoding.py +347 -0
  57. Cython/Compiler/Symtab.py +2998 -0
  58. Cython/Compiler/Tests/TestBuffer.py +105 -0
  59. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  60. Cython/Compiler/Tests/TestCmdLine.py +573 -0
  61. Cython/Compiler/Tests/TestCode.py +86 -0
  62. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  63. Cython/Compiler/Tests/TestGrammar.py +202 -0
  64. Cython/Compiler/Tests/TestMemView.py +71 -0
  65. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  66. Cython/Compiler/Tests/TestScanning.py +134 -0
  67. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  68. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  69. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  70. Cython/Compiler/Tests/TestTreePath.py +93 -0
  71. Cython/Compiler/Tests/TestTypes.py +75 -0
  72. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  73. Cython/Compiler/Tests/TestVisitor.py +61 -0
  74. Cython/Compiler/Tests/Utils.py +36 -0
  75. Cython/Compiler/Tests/__init__.py +1 -0
  76. Cython/Compiler/TreeFragment.py +278 -0
  77. Cython/Compiler/TreePath.py +290 -0
  78. Cython/Compiler/TypeInference.py +584 -0
  79. Cython/Compiler/TypeSlots.py +1181 -0
  80. Cython/Compiler/UFuncs.py +311 -0
  81. Cython/Compiler/UtilNodes.py +387 -0
  82. Cython/Compiler/UtilityCode.py +274 -0
  83. Cython/Compiler/Version.py +8 -0
  84. Cython/Compiler/Visitor.pxd +53 -0
  85. Cython/Compiler/Visitor.py +861 -0
  86. Cython/Compiler/__init__.py +1 -0
  87. Cython/Coverage.py +443 -0
  88. Cython/Debugger/Cygdb.py +179 -0
  89. Cython/Debugger/DebugWriter.py +82 -0
  90. Cython/Debugger/Tests/TestLibCython.py +275 -0
  91. Cython/Debugger/Tests/__init__.py +1 -0
  92. Cython/Debugger/Tests/cfuncs.c +8 -0
  93. Cython/Debugger/Tests/codefile +49 -0
  94. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  95. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  96. Cython/Debugger/__init__.py +1 -0
  97. Cython/Debugger/libcython.py +1549 -0
  98. Cython/Debugger/libpython.py +2821 -0
  99. Cython/Debugging.py +20 -0
  100. Cython/Distutils/__init__.py +2 -0
  101. Cython/Distutils/build_ext.py +137 -0
  102. Cython/Distutils/extension.py +96 -0
  103. Cython/Distutils/old_build_ext.py +351 -0
  104. Cython/Includes/cpython/__init__.pxd +173 -0
  105. Cython/Includes/cpython/array.pxd +174 -0
  106. Cython/Includes/cpython/bool.pxd +37 -0
  107. Cython/Includes/cpython/buffer.pxd +112 -0
  108. Cython/Includes/cpython/bytearray.pxd +33 -0
  109. Cython/Includes/cpython/bytes.pxd +200 -0
  110. Cython/Includes/cpython/cellobject.pxd +35 -0
  111. Cython/Includes/cpython/ceval.pxd +8 -0
  112. Cython/Includes/cpython/codecs.pxd +121 -0
  113. Cython/Includes/cpython/complex.pxd +55 -0
  114. Cython/Includes/cpython/contextvars.pxd +141 -0
  115. Cython/Includes/cpython/conversion.pxd +36 -0
  116. Cython/Includes/cpython/datetime.pxd +384 -0
  117. Cython/Includes/cpython/descr.pxd +26 -0
  118. Cython/Includes/cpython/dict.pxd +187 -0
  119. Cython/Includes/cpython/exc.pxd +263 -0
  120. Cython/Includes/cpython/fileobject.pxd +57 -0
  121. Cython/Includes/cpython/float.pxd +47 -0
  122. Cython/Includes/cpython/function.pxd +65 -0
  123. Cython/Includes/cpython/genobject.pxd +25 -0
  124. Cython/Includes/cpython/getargs.pxd +12 -0
  125. Cython/Includes/cpython/instance.pxd +25 -0
  126. Cython/Includes/cpython/iterator.pxd +36 -0
  127. Cython/Includes/cpython/iterobject.pxd +24 -0
  128. Cython/Includes/cpython/list.pxd +92 -0
  129. Cython/Includes/cpython/long.pxd +149 -0
  130. Cython/Includes/cpython/longintrepr.pxd +19 -0
  131. Cython/Includes/cpython/mapping.pxd +63 -0
  132. Cython/Includes/cpython/marshal.pxd +66 -0
  133. Cython/Includes/cpython/mem.pxd +120 -0
  134. Cython/Includes/cpython/memoryview.pxd +50 -0
  135. Cython/Includes/cpython/method.pxd +49 -0
  136. Cython/Includes/cpython/module.pxd +208 -0
  137. Cython/Includes/cpython/number.pxd +258 -0
  138. Cython/Includes/cpython/object.pxd +433 -0
  139. Cython/Includes/cpython/pycapsule.pxd +143 -0
  140. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  141. Cython/Includes/cpython/pyport.pxd +8 -0
  142. Cython/Includes/cpython/pystate.pxd +95 -0
  143. Cython/Includes/cpython/pythread.pxd +53 -0
  144. Cython/Includes/cpython/ref.pxd +67 -0
  145. Cython/Includes/cpython/sequence.pxd +134 -0
  146. Cython/Includes/cpython/set.pxd +119 -0
  147. Cython/Includes/cpython/slice.pxd +70 -0
  148. Cython/Includes/cpython/time.pxd +129 -0
  149. Cython/Includes/cpython/tuple.pxd +72 -0
  150. Cython/Includes/cpython/type.pxd +53 -0
  151. Cython/Includes/cpython/unicode.pxd +639 -0
  152. Cython/Includes/cpython/version.pxd +32 -0
  153. Cython/Includes/cpython/weakref.pxd +42 -0
  154. Cython/Includes/libc/__init__.pxd +1 -0
  155. Cython/Includes/libc/complex.pxd +35 -0
  156. Cython/Includes/libc/errno.pxd +127 -0
  157. Cython/Includes/libc/float.pxd +43 -0
  158. Cython/Includes/libc/limits.pxd +28 -0
  159. Cython/Includes/libc/locale.pxd +46 -0
  160. Cython/Includes/libc/math.pxd +209 -0
  161. Cython/Includes/libc/setjmp.pxd +10 -0
  162. Cython/Includes/libc/signal.pxd +64 -0
  163. Cython/Includes/libc/stddef.pxd +9 -0
  164. Cython/Includes/libc/stdint.pxd +105 -0
  165. Cython/Includes/libc/stdio.pxd +80 -0
  166. Cython/Includes/libc/stdlib.pxd +72 -0
  167. Cython/Includes/libc/string.pxd +50 -0
  168. Cython/Includes/libc/time.pxd +47 -0
  169. Cython/Includes/libcpp/__init__.pxd +4 -0
  170. Cython/Includes/libcpp/algorithm.pxd +320 -0
  171. Cython/Includes/libcpp/any.pxd +16 -0
  172. Cython/Includes/libcpp/atomic.pxd +59 -0
  173. Cython/Includes/libcpp/bit.pxd +29 -0
  174. Cython/Includes/libcpp/cast.pxd +12 -0
  175. Cython/Includes/libcpp/cmath.pxd +518 -0
  176. Cython/Includes/libcpp/complex.pxd +106 -0
  177. Cython/Includes/libcpp/deque.pxd +165 -0
  178. Cython/Includes/libcpp/execution.pxd +15 -0
  179. Cython/Includes/libcpp/forward_list.pxd +63 -0
  180. Cython/Includes/libcpp/functional.pxd +26 -0
  181. Cython/Includes/libcpp/iterator.pxd +34 -0
  182. Cython/Includes/libcpp/limits.pxd +61 -0
  183. Cython/Includes/libcpp/list.pxd +117 -0
  184. Cython/Includes/libcpp/map.pxd +252 -0
  185. Cython/Includes/libcpp/memory.pxd +115 -0
  186. Cython/Includes/libcpp/numbers.pxd +15 -0
  187. Cython/Includes/libcpp/numeric.pxd +131 -0
  188. Cython/Includes/libcpp/optional.pxd +34 -0
  189. Cython/Includes/libcpp/pair.pxd +1 -0
  190. Cython/Includes/libcpp/queue.pxd +25 -0
  191. Cython/Includes/libcpp/random.pxd +166 -0
  192. Cython/Includes/libcpp/set.pxd +228 -0
  193. Cython/Includes/libcpp/stack.pxd +11 -0
  194. Cython/Includes/libcpp/string.pxd +333 -0
  195. Cython/Includes/libcpp/typeindex.pxd +15 -0
  196. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  197. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  198. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  199. Cython/Includes/libcpp/utility.pxd +30 -0
  200. Cython/Includes/libcpp/vector.pxd +167 -0
  201. Cython/Includes/openmp.pxd +50 -0
  202. Cython/Includes/posix/__init__.pxd +1 -0
  203. Cython/Includes/posix/dlfcn.pxd +14 -0
  204. Cython/Includes/posix/fcntl.pxd +86 -0
  205. Cython/Includes/posix/ioctl.pxd +4 -0
  206. Cython/Includes/posix/mman.pxd +101 -0
  207. Cython/Includes/posix/resource.pxd +57 -0
  208. Cython/Includes/posix/select.pxd +21 -0
  209. Cython/Includes/posix/signal.pxd +73 -0
  210. Cython/Includes/posix/stat.pxd +98 -0
  211. Cython/Includes/posix/stdio.pxd +37 -0
  212. Cython/Includes/posix/stdlib.pxd +29 -0
  213. Cython/Includes/posix/strings.pxd +9 -0
  214. Cython/Includes/posix/time.pxd +71 -0
  215. Cython/Includes/posix/types.pxd +30 -0
  216. Cython/Includes/posix/uio.pxd +26 -0
  217. Cython/Includes/posix/unistd.pxd +271 -0
  218. Cython/Includes/posix/wait.pxd +38 -0
  219. Cython/Plex/Actions.pxd +24 -0
  220. Cython/Plex/Actions.py +119 -0
  221. Cython/Plex/DFA.pxd +14 -0
  222. Cython/Plex/DFA.py +164 -0
  223. Cython/Plex/Errors.py +48 -0
  224. Cython/Plex/Lexicons.py +178 -0
  225. Cython/Plex/Machines.pxd +36 -0
  226. Cython/Plex/Machines.py +238 -0
  227. Cython/Plex/Regexps.py +539 -0
  228. Cython/Plex/Scanners.pxd +47 -0
  229. Cython/Plex/Scanners.py +360 -0
  230. Cython/Plex/Transitions.pxd +14 -0
  231. Cython/Plex/Transitions.py +239 -0
  232. Cython/Plex/__init__.py +34 -0
  233. Cython/Runtime/__init__.py +1 -0
  234. Cython/Runtime/refnanny.pyx +261 -0
  235. Cython/Shadow.py +656 -0
  236. Cython/Shadow.pyi +521 -0
  237. Cython/StringIOTree.py +170 -0
  238. Cython/Tempita/__init__.py +4 -0
  239. Cython/Tempita/_looper.py +154 -0
  240. Cython/Tempita/_tempita.py +1091 -0
  241. Cython/TestUtils.py +417 -0
  242. Cython/Tests/TestCodeWriter.py +128 -0
  243. Cython/Tests/TestCythonUtils.py +202 -0
  244. Cython/Tests/TestJediTyper.py +223 -0
  245. Cython/Tests/TestShadow.py +114 -0
  246. Cython/Tests/TestStringIOTree.py +67 -0
  247. Cython/Tests/TestTestUtils.py +90 -0
  248. Cython/Tests/__init__.py +1 -0
  249. Cython/Tests/xmlrunner.py +390 -0
  250. Cython/Utility/AsyncGen.c +1263 -0
  251. Cython/Utility/Buffer.c +875 -0
  252. Cython/Utility/Builtins.c +660 -0
  253. Cython/Utility/CConvert.pyx +134 -0
  254. Cython/Utility/CMath.c +95 -0
  255. Cython/Utility/CommonStructures.c +139 -0
  256. Cython/Utility/Complex.c +378 -0
  257. Cython/Utility/Coroutine.c +2413 -0
  258. Cython/Utility/CpdefEnums.pyx +108 -0
  259. Cython/Utility/CppConvert.pyx +279 -0
  260. Cython/Utility/CppSupport.cpp +133 -0
  261. Cython/Utility/CythonFunction.c +1851 -0
  262. Cython/Utility/Dataclasses.c +185 -0
  263. Cython/Utility/Dataclasses.py +112 -0
  264. Cython/Utility/Embed.c +125 -0
  265. Cython/Utility/Exceptions.c +1017 -0
  266. Cython/Utility/ExtensionTypes.c +797 -0
  267. Cython/Utility/FunctionArguments.c +573 -0
  268. Cython/Utility/ImportExport.c +912 -0
  269. Cython/Utility/MemoryView.pyx +1478 -0
  270. Cython/Utility/MemoryView_C.c +992 -0
  271. Cython/Utility/ModuleSetupCode.c +2501 -0
  272. Cython/Utility/NumpyImportArray.c +46 -0
  273. Cython/Utility/ObjectHandling.c +3054 -0
  274. Cython/Utility/Optimize.c +1533 -0
  275. Cython/Utility/Overflow.c +404 -0
  276. Cython/Utility/Printing.c +86 -0
  277. Cython/Utility/Profile.c +660 -0
  278. Cython/Utility/StringTools.c +1206 -0
  279. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  280. Cython/Utility/TestCythonScope.pyx +75 -0
  281. Cython/Utility/TestUtilityLoader.c +12 -0
  282. Cython/Utility/TypeConversion.c +1329 -0
  283. Cython/Utility/UFuncs.pyx +50 -0
  284. Cython/Utility/UFuncs_C.c +89 -0
  285. Cython/Utility/__init__.py +28 -0
  286. Cython/Utility/arrayarray.h +143 -0
  287. Cython/Utils.py +687 -0
  288. Cython/__init__.py +10 -0
  289. Cython/__init__.pyi +7 -0
  290. Cython/py.typed +0 -0
  291. Cython-3.1.0a1.dist-info/COPYING.txt +19 -0
  292. Cython-3.1.0a1.dist-info/LICENSE.txt +176 -0
  293. Cython-3.1.0a1.dist-info/METADATA +67 -0
  294. Cython-3.1.0a1.dist-info/RECORD +301 -0
  295. Cython-3.1.0a1.dist-info/WHEEL +5 -0
  296. Cython-3.1.0a1.dist-info/entry_points.txt +4 -0
  297. Cython-3.1.0a1.dist-info/top_level.txt +3 -0
  298. cython.py +29 -0
  299. pyximport/__init__.py +4 -0
  300. pyximport/pyxbuild.py +160 -0
  301. pyximport/pyximport.py +482 -0
@@ -0,0 +1,573 @@
1
+ import os
2
+ import sys
3
+ import re
4
+ from io import StringIO
5
+ from unittest import TestCase
6
+ from unittest.mock import patch, Mock
7
+
8
+ from .. import Options
9
+ from ..CmdLine import parse_command_line
10
+
11
+ from .Utils import backup_Options, restore_Options, check_global_options
12
+
13
+ unpatched_exists = os.path.exists
14
+
15
+ def patched_exists(path):
16
+ # avoid the Cython command raising a file not found error
17
+ if path in (
18
+ 'source.pyx',
19
+ os.path.join('/work/dir', 'source.pyx'),
20
+ os.path.join('my_working_path', 'source.pyx'),
21
+ 'file.pyx',
22
+ 'file1.pyx',
23
+ 'file2.pyx',
24
+ 'file3.pyx',
25
+ 'foo.pyx',
26
+ 'bar.pyx',
27
+ ):
28
+ return True
29
+ return unpatched_exists(path)
30
+
31
+ @patch('os.path.exists', new=Mock(side_effect=patched_exists))
32
+ class CmdLineParserTest(TestCase):
33
+ def setUp(self):
34
+ self._options_backup = backup_Options()
35
+
36
+ def tearDown(self):
37
+ restore_Options(self._options_backup)
38
+
39
+ def check_default_global_options(self, white_list=[]):
40
+ self.assertEqual(check_global_options(self._options_backup, white_list), "")
41
+
42
+ def check_default_options(self, options, white_list=[]):
43
+ default_options = Options.CompilationOptions(Options.default_options)
44
+ no_value = object()
45
+ for name in default_options.__dict__.keys():
46
+ if name not in white_list:
47
+ self.assertEqual(getattr(options, name, no_value), getattr(default_options, name), msg="error in option " + name)
48
+
49
+ def test_short_options(self):
50
+ options, sources = parse_command_line([
51
+ '-V', '-l', '-+', '-t', '-v', '-v', '-v', '-p', '-D', '-a', '-3',
52
+ ])
53
+ self.assertFalse(sources)
54
+ self.assertTrue(options.show_version)
55
+ self.assertTrue(options.use_listing_file)
56
+ self.assertTrue(options.cplus)
57
+ self.assertTrue(options.timestamps)
58
+ self.assertTrue(options.verbose >= 3)
59
+ self.assertTrue(Options.embed_pos_in_docstring)
60
+ self.assertFalse(Options.docstrings)
61
+ self.assertTrue(Options.annotate)
62
+ self.assertEqual(options.language_level, 3)
63
+
64
+ options, sources = parse_command_line([
65
+ '-f', '-2', 'source.pyx',
66
+ ])
67
+ self.assertTrue(sources)
68
+ self.assertTrue(len(sources) == 1)
69
+ self.assertFalse(options.timestamps)
70
+ self.assertEqual(options.language_level, 2)
71
+
72
+ def test_long_options(self):
73
+ options, sources = parse_command_line([
74
+ '--version', '--create-listing', '--cplus', '--embed', '--timestamps',
75
+ '--verbose', '--verbose', '--verbose',
76
+ '--embed-positions', '--no-docstrings', '--annotate', '--lenient',
77
+ ])
78
+ self.assertFalse(sources)
79
+ self.assertTrue(options.show_version)
80
+ self.assertTrue(options.use_listing_file)
81
+ self.assertTrue(options.cplus)
82
+ self.assertEqual(Options.embed, 'main')
83
+ self.assertTrue(options.timestamps)
84
+ self.assertTrue(options.verbose >= 3)
85
+ self.assertTrue(Options.embed_pos_in_docstring)
86
+ self.assertFalse(Options.docstrings)
87
+ self.assertTrue(Options.annotate)
88
+ self.assertFalse(Options.error_on_unknown_names)
89
+ self.assertFalse(Options.error_on_uninitialized)
90
+
91
+ options, sources = parse_command_line([
92
+ '--force', 'source.pyx',
93
+ ])
94
+ self.assertTrue(sources)
95
+ self.assertTrue(len(sources) == 1)
96
+ self.assertFalse(options.timestamps)
97
+
98
+ def test_options_with_values(self):
99
+ options, sources = parse_command_line([
100
+ '--embed=huhu',
101
+ '-I/test/include/dir1', '--include-dir=/test/include/dir2',
102
+ '--include-dir', '/test/include/dir3',
103
+ '--working=/work/dir',
104
+ 'source.pyx',
105
+ '--output-file=/output/dir',
106
+ '--pre-import=/pre/import',
107
+ '--cleanup=3',
108
+ '--annotate-coverage=cov.xml',
109
+ '--gdb-outdir=/gdb/outdir',
110
+ '--directive=wraparound=false',
111
+ ])
112
+ self.assertEqual(sources, ['source.pyx'])
113
+ self.assertEqual(Options.embed, 'huhu')
114
+ self.assertEqual(options.include_path, ['/test/include/dir1', '/test/include/dir2', '/test/include/dir3'])
115
+ self.assertEqual(options.working_path, '/work/dir')
116
+ self.assertEqual(options.output_file, '/output/dir')
117
+ self.assertEqual(Options.pre_import, '/pre/import')
118
+ self.assertEqual(Options.generate_cleanup_code, 3)
119
+ self.assertTrue(Options.annotate)
120
+ self.assertEqual(Options.annotate_coverage_xml, 'cov.xml')
121
+ self.assertTrue(options.gdb_debug)
122
+ self.assertEqual(options.output_dir, '/gdb/outdir')
123
+ self.assertEqual(options.compiler_directives['wraparound'], False)
124
+
125
+ def test_embed_before_positional(self):
126
+ options, sources = parse_command_line([
127
+ '--embed',
128
+ 'source.pyx',
129
+ ])
130
+ self.assertEqual(sources, ['source.pyx'])
131
+ self.assertEqual(Options.embed, 'main')
132
+
133
+ def test_two_embeds(self):
134
+ options, sources = parse_command_line([
135
+ '--embed', '--embed=huhu',
136
+ 'source.pyx',
137
+ ])
138
+ self.assertEqual(sources, ['source.pyx'])
139
+ self.assertEqual(Options.embed, 'huhu')
140
+
141
+ def test_two_embeds2(self):
142
+ options, sources = parse_command_line([
143
+ '--embed=huhu', '--embed',
144
+ 'source.pyx',
145
+ ])
146
+ self.assertEqual(sources, ['source.pyx'])
147
+ self.assertEqual(Options.embed, 'main')
148
+
149
+ def test_no_annotate(self):
150
+ options, sources = parse_command_line([
151
+ '--embed=huhu', 'source.pyx'
152
+ ])
153
+ self.assertFalse(Options.annotate)
154
+
155
+ def test_annotate_short(self):
156
+ options, sources = parse_command_line([
157
+ '-a',
158
+ 'source.pyx',
159
+ ])
160
+ self.assertEqual(Options.annotate, 'default')
161
+
162
+ def test_annotate_long(self):
163
+ options, sources = parse_command_line([
164
+ '--annotate',
165
+ 'source.pyx',
166
+ ])
167
+ self.assertEqual(Options.annotate, 'default')
168
+
169
+ def test_annotate_fullc(self):
170
+ options, sources = parse_command_line([
171
+ '--annotate-fullc',
172
+ 'source.pyx',
173
+ ])
174
+ self.assertEqual(Options.annotate, 'fullc')
175
+
176
+ def test_short_w(self):
177
+ options, sources = parse_command_line([
178
+ '-w', 'my_working_path',
179
+ 'source.pyx'
180
+ ])
181
+ self.assertEqual(options.working_path, 'my_working_path')
182
+ self.check_default_global_options()
183
+ self.check_default_options(options, ['working_path'])
184
+
185
+ def test_short_o(self):
186
+ options, sources = parse_command_line([
187
+ '-o', 'my_output',
188
+ 'source.pyx'
189
+ ])
190
+ self.assertEqual(options.output_file, 'my_output')
191
+ self.check_default_global_options()
192
+ self.check_default_options(options, ['output_file'])
193
+
194
+ def test_short_z(self):
195
+ options, sources = parse_command_line([
196
+ '-z', 'my_preimport',
197
+ 'source.pyx'
198
+ ])
199
+ self.assertEqual(Options.pre_import, 'my_preimport')
200
+ self.check_default_global_options(['pre_import'])
201
+ self.check_default_options(options)
202
+
203
+ def test_convert_range(self):
204
+ options, sources = parse_command_line([
205
+ '--convert-range',
206
+ 'source.pyx'
207
+ ])
208
+ self.assertEqual(Options.convert_range, True)
209
+ self.check_default_global_options(['convert_range'])
210
+ self.check_default_options(options)
211
+
212
+ def test_line_directives(self):
213
+ options, sources = parse_command_line([
214
+ '--line-directives',
215
+ 'source.pyx'
216
+ ])
217
+ self.assertEqual(options.emit_linenums, True)
218
+ self.check_default_global_options()
219
+ self.check_default_options(options, ['emit_linenums'])
220
+
221
+ def test_no_c_in_traceback(self):
222
+ options, sources = parse_command_line([
223
+ '--no-c-in-traceback',
224
+ 'source.pyx'
225
+ ])
226
+ self.assertEqual(options.c_line_in_traceback, False)
227
+ self.check_default_global_options()
228
+ self.check_default_options(options, ['c_line_in_traceback'])
229
+
230
+ def test_gdb(self):
231
+ options, sources = parse_command_line([
232
+ '--gdb',
233
+ 'source.pyx'
234
+ ])
235
+ self.assertEqual(options.gdb_debug, True)
236
+ self.assertEqual(options.output_dir, os.curdir)
237
+ self.check_default_global_options()
238
+ self.check_default_options(options, ['gdb_debug', 'output_dir'])
239
+
240
+ def test_3str(self):
241
+ options, sources = parse_command_line([
242
+ '--3str',
243
+ 'source.pyx'
244
+ ])
245
+ self.assertEqual(options.language_level, '3')
246
+ self.check_default_global_options()
247
+ self.check_default_options(options, ['language_level'])
248
+
249
+ def test_capi_reexport_cincludes(self):
250
+ options, sources = parse_command_line([
251
+ '--capi-reexport-cincludes',
252
+ 'source.pyx'
253
+ ])
254
+ self.assertEqual(options.capi_reexport_cincludes, True)
255
+ self.check_default_global_options()
256
+ self.check_default_options(options, ['capi_reexport_cincludes'])
257
+
258
+ def test_fast_fail(self):
259
+ options, sources = parse_command_line([
260
+ '--fast-fail',
261
+ 'source.pyx'
262
+ ])
263
+ self.assertEqual(Options.fast_fail, True)
264
+ self.check_default_global_options(['fast_fail'])
265
+ self.check_default_options(options)
266
+
267
+ def test_cimport_from_pyx(self):
268
+ options, sources = parse_command_line([
269
+ '--cimport-from-pyx',
270
+ 'source.pyx'
271
+ ])
272
+ self.assertEqual(Options.cimport_from_pyx, True)
273
+ self.check_default_global_options(['cimport_from_pyx'])
274
+ self.check_default_options(options)
275
+
276
+ def test_Werror(self):
277
+ options, sources = parse_command_line([
278
+ '-Werror',
279
+ 'source.pyx'
280
+ ])
281
+ self.assertEqual(Options.warning_errors, True)
282
+ self.check_default_global_options(['warning_errors'])
283
+ self.check_default_options(options)
284
+
285
+ def test_warning_errors(self):
286
+ options, sources = parse_command_line([
287
+ '--warning-errors',
288
+ 'source.pyx'
289
+ ])
290
+ self.assertEqual(Options.warning_errors, True)
291
+ self.check_default_global_options(['warning_errors'])
292
+ self.check_default_options(options)
293
+
294
+ def test_Wextra(self):
295
+ options, sources = parse_command_line([
296
+ '-Wextra',
297
+ 'source.pyx'
298
+ ])
299
+ self.assertEqual(options.compiler_directives, Options.extra_warnings)
300
+ self.check_default_global_options()
301
+ self.check_default_options(options, ['compiler_directives'])
302
+
303
+ def test_warning_extra(self):
304
+ options, sources = parse_command_line([
305
+ '--warning-extra',
306
+ 'source.pyx'
307
+ ])
308
+ self.assertEqual(options.compiler_directives, Options.extra_warnings)
309
+ self.check_default_global_options()
310
+ self.check_default_options(options, ['compiler_directives'])
311
+
312
+ def test_old_style_globals(self):
313
+ options, sources = parse_command_line([
314
+ '--old-style-globals',
315
+ 'source.pyx'
316
+ ])
317
+ self.assertEqual(Options.old_style_globals, True)
318
+ self.check_default_global_options(['old_style_globals'])
319
+ self.check_default_options(options)
320
+
321
+ def test_directive_multiple(self):
322
+ options, source = parse_command_line([
323
+ '-X', 'cdivision=True',
324
+ '-X', 'c_string_type=bytes',
325
+ 'source.pyx'
326
+ ])
327
+ self.assertEqual(options.compiler_directives['cdivision'], True)
328
+ self.assertEqual(options.compiler_directives['c_string_type'], 'bytes')
329
+ self.check_default_global_options()
330
+ self.check_default_options(options, ['compiler_directives'])
331
+
332
+ def test_directive_multiple_v2(self):
333
+ options, source = parse_command_line([
334
+ '-X', 'cdivision=True,c_string_type=bytes',
335
+ 'source.pyx'
336
+ ])
337
+ self.assertEqual(options.compiler_directives['cdivision'], True)
338
+ self.assertEqual(options.compiler_directives['c_string_type'], 'bytes')
339
+ self.check_default_global_options()
340
+ self.check_default_options(options, ['compiler_directives'])
341
+
342
+ def test_directive_value_yes(self):
343
+ options, source = parse_command_line([
344
+ '-X', 'cdivision=YeS',
345
+ 'source.pyx'
346
+ ])
347
+ self.assertEqual(options.compiler_directives['cdivision'], True)
348
+ self.check_default_global_options()
349
+ self.check_default_options(options, ['compiler_directives'])
350
+
351
+ def test_directive_value_no(self):
352
+ options, source = parse_command_line([
353
+ '-X', 'cdivision=no',
354
+ 'source.pyx'
355
+ ])
356
+ self.assertEqual(options.compiler_directives['cdivision'], False)
357
+ self.check_default_global_options()
358
+ self.check_default_options(options, ['compiler_directives'])
359
+
360
+ def test_directive_value_invalid(self):
361
+ self.assertRaises(ValueError, parse_command_line, [
362
+ '-X', 'cdivision=sadfasd',
363
+ 'source.pyx'
364
+ ])
365
+
366
+ def test_directive_key_invalid(self):
367
+ self.assertRaises(ValueError, parse_command_line, [
368
+ '-X', 'abracadabra',
369
+ 'source.pyx'
370
+ ])
371
+
372
+ def test_directive_no_value(self):
373
+ self.assertRaises(ValueError, parse_command_line, [
374
+ '-X', 'cdivision',
375
+ 'source.pyx'
376
+ ])
377
+
378
+ def test_compile_time_env_short(self):
379
+ options, source = parse_command_line([
380
+ '-E', 'MYSIZE=10',
381
+ 'source.pyx'
382
+ ])
383
+ self.assertEqual(options.compile_time_env['MYSIZE'], 10)
384
+ self.check_default_global_options()
385
+ self.check_default_options(options, ['compile_time_env'])
386
+
387
+ def test_compile_time_env_long(self):
388
+ options, source = parse_command_line([
389
+ '--compile-time-env', 'MYSIZE=10',
390
+ 'source.pyx'
391
+ ])
392
+ self.assertEqual(options.compile_time_env['MYSIZE'], 10)
393
+ self.check_default_global_options()
394
+ self.check_default_options(options, ['compile_time_env'])
395
+
396
+ def test_compile_time_env_multiple(self):
397
+ options, source = parse_command_line([
398
+ '-E', 'MYSIZE=10', '-E', 'ARRSIZE=11',
399
+ 'source.pyx'
400
+ ])
401
+ self.assertEqual(options.compile_time_env['MYSIZE'], 10)
402
+ self.assertEqual(options.compile_time_env['ARRSIZE'], 11)
403
+ self.check_default_global_options()
404
+ self.check_default_options(options, ['compile_time_env'])
405
+
406
+ def test_compile_time_env_multiple_v2(self):
407
+ options, source = parse_command_line([
408
+ '-E', 'MYSIZE=10,ARRSIZE=11',
409
+ 'source.pyx'
410
+ ])
411
+ self.assertEqual(options.compile_time_env['MYSIZE'], 10)
412
+ self.assertEqual(options.compile_time_env['ARRSIZE'], 11)
413
+ self.check_default_global_options()
414
+ self.check_default_options(options, ['compile_time_env'])
415
+
416
+ def test_option_first(self):
417
+ options, sources = parse_command_line(['-V', 'file.pyx'])
418
+ self.assertEqual(sources, ['file.pyx'])
419
+
420
+ def test_file_inbetween(self):
421
+ options, sources = parse_command_line(['-V', 'file.pyx', '-a'])
422
+ self.assertEqual(sources, ['file.pyx'])
423
+
424
+ def test_option_trailing(self):
425
+ options, sources = parse_command_line(['file.pyx', '-V'])
426
+ self.assertEqual(sources, ['file.pyx'])
427
+
428
+ def test_multiple_files(self):
429
+ options, sources = parse_command_line([
430
+ 'file1.pyx', '-V',
431
+ 'file2.pyx', '-a',
432
+ 'file3.pyx'
433
+ ])
434
+ self.assertEqual(sources, ['file1.pyx', 'file2.pyx', 'file3.pyx'])
435
+
436
+ def test_debug_flags(self):
437
+ options, sources = parse_command_line([
438
+ '--debug-disposal-code', '--debug-coercion',
439
+ 'file3.pyx'
440
+ ])
441
+ from Cython.Compiler import DebugFlags
442
+ for name in ['debug_disposal_code', 'debug_temp_alloc', 'debug_coercion']:
443
+ self.assertEqual(getattr(DebugFlags, name), name in ['debug_disposal_code', 'debug_coercion'])
444
+ setattr(DebugFlags, name, 0) # restore original value
445
+
446
+ def test_gdb_overwrites_gdb_outdir(self):
447
+ options, sources = parse_command_line([
448
+ '--gdb-outdir=my_dir', '--gdb',
449
+ 'file3.pyx'
450
+ ])
451
+ self.assertEqual(options.gdb_debug, True)
452
+ self.assertEqual(options.output_dir, os.curdir)
453
+ self.check_default_global_options()
454
+ self.check_default_options(options, ['gdb_debug', 'output_dir'])
455
+
456
+ def test_gdb_first(self):
457
+ options, sources = parse_command_line([
458
+ '--gdb', '--gdb-outdir=my_dir',
459
+ 'file3.pyx'
460
+ ])
461
+ self.assertEqual(options.gdb_debug, True)
462
+ self.assertEqual(options.output_dir, 'my_dir')
463
+ self.check_default_global_options()
464
+ self.check_default_options(options, ['gdb_debug', 'output_dir'])
465
+
466
+ def test_coverage_overwrites_annotation(self):
467
+ options, sources = parse_command_line([
468
+ '--annotate-fullc', '--annotate-coverage=my.xml',
469
+ 'file3.pyx'
470
+ ])
471
+ self.assertEqual(Options.annotate, True)
472
+ self.assertEqual(Options.annotate_coverage_xml, 'my.xml')
473
+ self.check_default_global_options(['annotate', 'annotate_coverage_xml'])
474
+ self.check_default_options(options)
475
+
476
+ def test_coverage_first(self):
477
+ options, sources = parse_command_line([
478
+ '--annotate-coverage=my.xml', '--annotate-fullc',
479
+ 'file3.pyx'
480
+ ])
481
+ self.assertEqual(Options.annotate, 'fullc')
482
+ self.assertEqual(Options.annotate_coverage_xml, 'my.xml')
483
+ self.check_default_global_options(['annotate', 'annotate_coverage_xml'])
484
+ self.check_default_options(options)
485
+
486
+ def test_annotate_first_fullc_second(self):
487
+ options, sources = parse_command_line([
488
+ '--annotate', '--annotate-fullc',
489
+ 'file3.pyx'
490
+ ])
491
+ self.assertEqual(Options.annotate, 'fullc')
492
+ self.check_default_global_options(['annotate'])
493
+ self.check_default_options(options)
494
+
495
+ def test_annotate_fullc_first(self):
496
+ options, sources = parse_command_line([
497
+ '--annotate-fullc', '--annotate',
498
+ 'file3.pyx'
499
+ ])
500
+ self.assertEqual(Options.annotate, 'default')
501
+ self.check_default_global_options(['annotate'])
502
+ self.check_default_options(options)
503
+
504
+ def test_warning_extra_dont_overwrite(self):
505
+ options, sources = parse_command_line([
506
+ '-X', 'cdivision=True',
507
+ '--warning-extra',
508
+ '-X', 'c_string_type=bytes',
509
+ 'source.pyx'
510
+ ])
511
+ self.assertTrue(len(options.compiler_directives), len(Options.extra_warnings) + 1)
512
+ self.check_default_global_options()
513
+ self.check_default_options(options, ['compiler_directives'])
514
+
515
+ def test_module_name(self):
516
+ options, sources = parse_command_line([
517
+ 'source.pyx'
518
+ ])
519
+ self.assertEqual(options.module_name, None)
520
+ self.check_default_global_options()
521
+ self.check_default_options(options)
522
+ options, sources = parse_command_line([
523
+ '--module-name', 'foo.bar',
524
+ 'source.pyx'
525
+ ])
526
+ self.assertEqual(options.module_name, 'foo.bar')
527
+ self.check_default_global_options()
528
+ self.check_default_options(options, ['module_name'])
529
+
530
+ def test_errors(self):
531
+ def error(args, regex=None):
532
+ old_stderr = sys.stderr
533
+ stderr = sys.stderr = StringIO()
534
+ try:
535
+ self.assertRaises(SystemExit, parse_command_line, list(args))
536
+ finally:
537
+ sys.stderr = old_stderr
538
+ msg = stderr.getvalue()
539
+ err_msg = 'Message "{}"'.format(msg.strip())
540
+ self.assertTrue(msg.startswith('usage: '),
541
+ '%s does not start with "usage :"' % err_msg)
542
+ self.assertTrue(': error: ' in msg,
543
+ '%s does not contain ": error :"' % err_msg)
544
+ if regex:
545
+ self.assertTrue(re.search(regex, msg),
546
+ '%s does not match search "%s"' %
547
+ (err_msg, regex))
548
+
549
+ error(['-1'],
550
+ 'unknown option -1')
551
+ error(['-I'],
552
+ 'argument -I/--include-dir: expected one argument')
553
+ error(['--version=-a'],
554
+ "argument -V/--version: ignored explicit argument '-a'")
555
+ error(['--version=--annotate=true'],
556
+ "argument -V/--version: ignored explicit argument "
557
+ "'--annotate=true'")
558
+ error(['--working'],
559
+ "argument -w/--working: expected one argument")
560
+ error(['--verbose=1'],
561
+ "argument -v/--verbose: ignored explicit argument '1'")
562
+ error(['--cleanup'],
563
+ "argument --cleanup: expected one argument")
564
+ error(['--debug-disposal-code-wrong-name', 'file3.pyx'],
565
+ "unknown option --debug-disposal-code-wrong-name")
566
+ error(['--module-name', 'foo.pyx'],
567
+ "Need at least one source file")
568
+ error(['--module-name', 'foo.bar'],
569
+ "Need at least one source file")
570
+ error(['--module-name', 'foo.bar', 'foo.pyx', 'bar.pyx'],
571
+ "Only one source file allowed when using --module-name")
572
+ error(['--module-name', 'foo.bar', '--timestamps', 'foo.pyx'],
573
+ "Cannot use --module-name with --timestamps")
@@ -0,0 +1,86 @@
1
+ import textwrap
2
+ from unittest import TestCase
3
+
4
+ from ..Code import _indent_chunk
5
+
6
+ class TestIndent(TestCase):
7
+ def _test_indentations(self, chunk, expected):
8
+ for indentation in range(16):
9
+ expected_indented = textwrap.indent(expected, ' ' * indentation)
10
+ for line in expected_indented.splitlines():
11
+ # Validate before the comparison that empty lines got stripped also by textwrap.indent().
12
+ self.assertTrue(line == '' or line.strip(), repr(line))
13
+
14
+ with self.subTest(indentation=indentation):
15
+ result = _indent_chunk(chunk, indentation_length=indentation)
16
+ self.assertEqual(expected_indented, result)
17
+
18
+ def test_indent_empty(self):
19
+ self._test_indentations('', '')
20
+
21
+ def test_indent_empty_lines(self):
22
+ self._test_indentations('\n', '\n')
23
+ self._test_indentations('\n'*2, '\n'*2)
24
+ self._test_indentations('\n'*3, '\n'*3)
25
+ self._test_indentations(' \n'*2, '\n'*2)
26
+ self._test_indentations('\n \n \n \n', '\n'*4)
27
+
28
+ def test_indent_one_line(self):
29
+ self._test_indentations('abc', 'abc')
30
+
31
+ def test_indent_chunk(self):
32
+ chunk = """
33
+ x = 1
34
+ if x == 2:
35
+ print("False")
36
+ else:
37
+ print("True")
38
+ """
39
+ expected = """
40
+ x = 1
41
+ if x == 2:
42
+ print("False")
43
+ else:
44
+ print("True")
45
+ """
46
+ self._test_indentations(chunk, expected)
47
+
48
+ def test_indent_empty_line(self):
49
+ chunk = """
50
+ x = 1
51
+
52
+ if x == 2:
53
+ print("False")
54
+ else:
55
+ print("True")
56
+ """
57
+ expected = """
58
+ x = 1
59
+
60
+ if x == 2:
61
+ print("False")
62
+ else:
63
+ print("True")
64
+ """
65
+ self._test_indentations(chunk, expected)
66
+
67
+ def test_indent_empty_line_unclean(self):
68
+ lines = """
69
+ x = 1
70
+
71
+ if x == 2:
72
+ print("False")
73
+ else:
74
+ print("True")
75
+ """.splitlines(keepends=True)
76
+ lines[2] = ' \n'
77
+ chunk = ''.join(lines)
78
+ expected = """
79
+ x = 1
80
+
81
+ if x == 2:
82
+ print("False")
83
+ else:
84
+ print("True")
85
+ """
86
+ self._test_indentations(chunk, expected)