parent
e9e7171b56
commit
4839acadf7
@ -24,9 +24,31 @@ from hy.importer import hy_parse, HyLoader, cache_from_source
|
|||||||
def test_basics():
|
def test_basics():
|
||||||
"Make sure the basics of the importer work"
|
"Make sure the basics of the importer work"
|
||||||
|
|
||||||
basic_namespace = runpy.run_path("tests/resources/importer/basic.hy",
|
assert os.path.isfile('tests/resources/__init__.py')
|
||||||
run_name='__main__')
|
resources_mod = importlib.import_module('tests.resources')
|
||||||
assert 'square' in basic_namespace
|
assert hasattr(resources_mod, 'kwtest')
|
||||||
|
|
||||||
|
assert os.path.isfile('tests/resources/bin/__init__.hy')
|
||||||
|
bin_mod = importlib.import_module('tests.resources.bin')
|
||||||
|
assert hasattr(bin_mod, '_null_fn_for_import_test')
|
||||||
|
|
||||||
|
|
||||||
|
def test_runpy():
|
||||||
|
# XXX: `runpy` won't update cached bytecode! Don't know if that's
|
||||||
|
# intentional or not.
|
||||||
|
|
||||||
|
basic_ns = runpy.run_path('tests/resources/importer/basic.hy')
|
||||||
|
assert 'square' in basic_ns
|
||||||
|
|
||||||
|
main_ns = runpy.run_path('tests/resources/bin')
|
||||||
|
assert main_ns['visited_main'] == 1
|
||||||
|
del main_ns
|
||||||
|
|
||||||
|
main_ns = runpy.run_module('tests.resources.bin')
|
||||||
|
assert main_ns['visited_main'] == 1
|
||||||
|
|
||||||
|
with pytest.raises(IOError):
|
||||||
|
runpy.run_path('tests/resources/foobarbaz.py')
|
||||||
|
|
||||||
|
|
||||||
def test_stringer():
|
def test_stringer():
|
||||||
|
2
tests/resources/bin/__main__.hy
Normal file
2
tests/resources/bin/__main__.hy
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(print "This is a __main__.hy")
|
||||||
|
(setv visited_main True)
|
@ -328,6 +328,18 @@ def test_bin_hy_module_main():
|
|||||||
assert "Hello World" in output
|
assert "Hello World" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_bin_hy_module_main_file():
|
||||||
|
output, _ = run_cmd("hy -m tests.resources.bin")
|
||||||
|
assert "This is a __main__.hy" in output
|
||||||
|
|
||||||
|
output, _ = run_cmd("hy -m .tests.resources.bin", expect=1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_bin_hy_file_main_file():
|
||||||
|
output, _ = run_cmd("hy tests/resources/bin")
|
||||||
|
assert "This is a __main__.hy" in output
|
||||||
|
|
||||||
|
|
||||||
def test_bin_hy_module_main_args():
|
def test_bin_hy_module_main_args():
|
||||||
output, _ = run_cmd("hy -m tests.resources.bin.main test 123")
|
output, _ = run_cmd("hy -m tests.resources.bin.main test 123")
|
||||||
assert "test" in output
|
assert "test" in output
|
||||||
|
Loading…
x
Reference in New Issue
Block a user