MCPcopy
hub / github.com/hylang/hy / test_byte_compile

Function test_byte_compile

tests/test_bin.py:231–266  ·  view source on GitHub ↗
(scenario, cmd_fmt)

Source from the content-addressed store, hash-verified

229 ],
230)
231def test_byte_compile(scenario, cmd_fmt):
232
233 modname = "tests.resources.bin.bytecompile"
234 fpath = modname.replace(".", "/") + ".hy"
235
236 if scenario == "prevent_by_option":
237 cmd_fmt.insert(1, "-B")
238
239 cmd = " ".join(cmd_fmt).format(**locals())
240
241 rm(cache_from_source(fpath))
242
243 if scenario == "prevent_by_force":
244 # Keep Hy from being able to byte-compile the module by
245 # creating a directory at the target location.
246 os.mkdir(cache_from_source(fpath))
247
248 # Whether or not we can byte-compile the module, we should be able
249 # to run it.
250 output, _ = run_cmd(cmd, dontwritebytecode=(scenario == "prevent_by_env"))
251 assert "Hello from macro" in output
252 assert "The macro returned: boink" in output
253
254 if scenario == "normal":
255 # That should've byte-compiled the module.
256 assert os.path.exists(cache_from_source(fpath))
257 elif scenario == "prevent_by_env" or scenario == "prevent_by_option":
258 # No byte-compiled version should've been created.
259 assert not os.path.exists(cache_from_source(fpath))
260
261 # When we run the same command again, and we've byte-compiled the
262 # module, the byte-compiled version should be run instead of the
263 # source, in which case the macro shouldn't be run.
264 output, _ = run_cmd(cmd)
265 assert ("Hello from macro" in output) ^ (scenario == "normal")
266 assert "The macro returned: boink" in output
267
268
269def test_module_main_file():

Callers

nothing calls this directly

Calls 3

rmFunction · 0.85
run_cmdFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected