@@ -44,10 +44,19 @@ def test_ns() -> str:
44
44
45
45
46
46
@pytest .fixture
47
- def ns (test_ns : str ) -> runtime .Namespace :
47
+ def test_ns_sym (test_ns : str ) -> sym .Symbol :
48
+ return sym .symbol (test_ns )
49
+
50
+
51
+ @pytest .fixture
52
+ def ns (test_ns : str , test_ns_sym : sym .Symbol ) -> runtime .Namespace :
48
53
runtime .init_ns_var (which_ns = runtime .CORE_NS )
54
+ runtime .Namespace .get_or_create (test_ns_sym )
49
55
with runtime .ns_bindings (test_ns ) as ns :
50
- yield ns
56
+ try :
57
+ yield ns
58
+ finally :
59
+ runtime .Namespace .remove (test_ns_sym )
51
60
52
61
53
62
@pytest .fixture
@@ -902,7 +911,7 @@ def test_macro_expansion(ns: runtime.Namespace):
902
911
903
912
904
913
class TestIf :
905
- def test_if_number_of_elems (self , ns : runtime . Namespace ):
914
+ def test_if_number_of_elems (self ):
906
915
with pytest .raises (compiler .CompilerException ):
907
916
lcompile ("(if)" )
908
917
@@ -925,7 +934,7 @@ def test_if(self, ns: runtime.Namespace):
925
934
"""
926
935
assert "YELLING" == lcompile (code )
927
936
928
- def test_truthiness (self , ns : runtime . Namespace ):
937
+ def test_truthiness (self ):
929
938
# Valid false values
930
939
assert kw .keyword ("b" ) == lcompile ("(if false :a :b)" )
931
940
assert kw .keyword ("b" ) == lcompile ("(if nil :a :b)" )
@@ -1007,7 +1016,7 @@ def test_import_module_must_exist(self, ns: runtime.Namespace):
1007
1016
with pytest .raises (ImportError ):
1008
1017
lcompile ("(import* real.fake.module)" )
1009
1018
1010
- def test_import_resolves_within_do_block (self ):
1019
+ def test_import_resolves_within_do_block (self , ns : runtime . Namespace ):
1011
1020
import time
1012
1021
1013
1022
assert time .perf_counter == lcompile ("(do (import* time)) time/perf-counter" )
@@ -1041,6 +1050,16 @@ def test_multi_import(self, ns: runtime.Namespace):
1041
1050
)
1042
1051
)
1043
1052
1053
+ def test_nested_imports_visible_with_parent (self , ns : runtime .Namespace ):
1054
+ import collections .abc
1055
+
1056
+ assert [collections .OrderedDict , collections .abc .Sized ] == lcompile (
1057
+ """
1058
+ (import* collections collections.abc)
1059
+ #py [collections/OrderedDict collections.abc/Sized]
1060
+ """
1061
+ )
1062
+
1044
1063
1045
1064
class TestPythonInterop :
1046
1065
def test_interop_is_valid_type (self , ns : runtime .Namespace ):
@@ -1368,22 +1387,22 @@ def test_loop_with_recur(self, ns: runtime.Namespace):
1368
1387
1369
1388
1370
1389
class TestQuote :
1371
- def test_quoted_list (self , ns : runtime . Namespace ):
1390
+ def test_quoted_list (self ):
1372
1391
assert lcompile ("'()" ) == llist .l ()
1373
1392
assert lcompile ("'(str)" ) == llist .l (sym .symbol ("str" ))
1374
1393
assert lcompile ("'(str 3)" ) == llist .l (sym .symbol ("str" ), 3 )
1375
1394
assert lcompile ("'(str 3 :feet-deep)" ) == llist .l (
1376
1395
sym .symbol ("str" ), 3 , kw .keyword ("feet-deep" )
1377
1396
)
1378
1397
1379
- def test_quoted_map (self , ns : runtime . Namespace ):
1398
+ def test_quoted_map (self ):
1380
1399
assert lcompile ("'{}" ) == lmap .Map .empty ()
1381
1400
assert lcompile ("'{:a 2}" ) == lmap .map ({kw .keyword ("a" ): 2 })
1382
1401
assert lcompile ('\' {:a 2 "str" s}' ) == lmap .map (
1383
1402
{kw .keyword ("a" ): 2 , "str" : sym .symbol ("s" )}
1384
1403
)
1385
1404
1386
- def test_quoted_set (self , ns : runtime . Namespace ):
1405
+ def test_quoted_set (self ):
1387
1406
assert lcompile ("'#{}" ) == lset .Set .empty ()
1388
1407
assert lcompile ("'#{:a 2}" ) == lset .s (kw .keyword ("a" ), 2 )
1389
1408
assert lcompile ('\' #{:a 2 "str"}' ) == lset .s (kw .keyword ("a" ), 2 , "str" )
@@ -1650,7 +1669,7 @@ def test_set_cannot_assign_fn_arg_local(self):
1650
1669
with pytest .raises (compiler .CompilerException ):
1651
1670
lcompile ("(fn [a b] (set! a :c))" )
1652
1671
1653
- def test_set_cannot_assign_non_dynamic_var (self ):
1672
+ def test_set_cannot_assign_non_dynamic_var (self , ns : runtime . Namespace ):
1654
1673
with pytest .raises (compiler .CompilerException ):
1655
1674
lcompile (
1656
1675
"""
0 commit comments