MCPcopy Create free account
hub / github.com/apache/arrow / test_cython_api

Function test_cython_api

python/pyarrow/tests/test_cython.py:87–164  ·  view source on GitHub ↗

Basic test for the Cython API.

(tmpdir)

Source from the content-addressed store, hash-verified

85@pytest.mark.numpy
86@pytest.mark.cython
87def test_cython_api(tmpdir):
88 """
89 Basic test for the Cython API.
90 """
91 # Fail early if cython is not found
92 import cython # noqa
93
94 with tmpdir.as_cwd():
95 # Set up temporary workspace
96 pyx_file = 'pyarrow_cython_example.pyx'
97 shutil.copyfile(os.path.join(here, pyx_file),
98 os.path.join(str(tmpdir), pyx_file))
99 # Create setup.py file
100 setup_code = setup_template.format(pyx_file=pyx_file,
101 compiler_opts=compiler_opts,
102 test_ld_path=test_ld_path)
103 with open('setup.py', 'w') as f:
104 f.write(setup_code)
105
106 # ARROW-2263: Make environment with this pyarrow/ package first on the
107 # PYTHONPATH, for local dev environments
108 subprocess_env = test_util.get_modified_env_with_pythonpath()
109
110 # Compile extension module
111 subprocess.check_call([sys.executable, 'setup.py',
112 'build_ext', '--inplace'],
113 env=subprocess_env)
114
115 # Check basic functionality
116 orig_path = sys.path[:]
117 sys.path.insert(0, str(tmpdir))
118 try:
119 mod = __import__('pyarrow_cython_example')
120 check_cython_example_module(mod)
121 finally:
122 sys.path = orig_path
123
124 # Check the extension module is loadable from a subprocess without
125 # pyarrow imported first.
126 code = f"""if 1:
127 import sys
128 import os
129
130 try:
131 # Add dll directory was added on python 3.8
132 # and is required in order to find extra DLLs
133 # only for win32
134 for dir in {pa.get_library_dirs()}:
135 os.add_dll_directory(dir)
136 except AttributeError:
137 pass
138
139 mod = __import__('pyarrow_cython_example')
140 arr = mod.make_null_array(5)
141 assert mod.get_array_length(arr) == 5
142 assert arr.null_count == 5
143 """
144

Callers

nothing calls this directly

Calls 6

joinMethod · 0.45
formatMethod · 0.45
writeMethod · 0.45
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected