| 167 | @pytest.mark.numpy |
| 168 | @pytest.mark.cython |
| 169 | def test_visit_strings(tmpdir): |
| 170 | with tmpdir.as_cwd(): |
| 171 | # Set up temporary workspace |
| 172 | pyx_file = 'bound_function_visit_strings.pyx' |
| 173 | shutil.copyfile(os.path.join(here, pyx_file), |
| 174 | os.path.join(str(tmpdir), pyx_file)) |
| 175 | # Create setup.py file |
| 176 | setup_code = setup_template.format(pyx_file=pyx_file, |
| 177 | compiler_opts=compiler_opts, |
| 178 | test_ld_path=test_ld_path) |
| 179 | with open('setup.py', 'w') as f: |
| 180 | f.write(setup_code) |
| 181 | |
| 182 | subprocess_env = test_util.get_modified_env_with_pythonpath() |
| 183 | |
| 184 | # Compile extension module |
| 185 | subprocess.check_call([sys.executable, 'setup.py', |
| 186 | 'build_ext', '--inplace'], |
| 187 | env=subprocess_env) |
| 188 | |
| 189 | sys.path.insert(0, str(tmpdir)) |
| 190 | mod = __import__('bound_function_visit_strings') |
| 191 | |
| 192 | strings = ['a', 'b', 'c'] |
| 193 | visited = [] |
| 194 | mod._visit_strings(strings, visited.append) |
| 195 | |
| 196 | assert visited == strings |
| 197 | |
| 198 | with pytest.raises(ValueError, match="wtf"): |
| 199 | def raise_on_b(s): |
| 200 | if s == 'b': |
| 201 | raise ValueError('wtf') |
| 202 | |
| 203 | mod._visit_strings(strings, raise_on_b) |