@@ -32,7 +32,7 @@ def try_path(dir, rel):
32
32
if not os .path .isfile (full_path ):
33
33
return full_path , None
34
34
with open (full_path ) as f :
35
- return full_path , f .read ()
35
+ return full_path , f .read (). encode ()
36
36
37
37
38
38
def import_callback (dir , rel ):
@@ -68,11 +68,10 @@ def return_types():
68
68
69
69
class JsonnetTests (unittest .TestCase ):
70
70
def setUp (self ):
71
- self .input_filename = os .path .join (
72
- os .path .dirname (__file__ ),
73
- "test.jsonnet" ,
74
- )
75
- self .expected_str = "true\n "
71
+ base_dir = os .path .join (os .path .dirname (__file__ ), "testdata" )
72
+ self .input_filename = os .path .join (base_dir , "basic_check.jsonnet" )
73
+ self .trivial_filename = os .path .join (base_dir , "trivial.jsonnet" )
74
+ self .test_filename = os .path .join (base_dir , "test.jsonnet" )
76
75
with open (self .input_filename , "r" ) as infile :
77
76
self .input_snippet = infile .read ()
78
77
@@ -82,16 +81,37 @@ def test_evaluate_file(self):
82
81
import_callback = import_callback ,
83
82
native_callbacks = native_callbacks ,
84
83
)
85
- self .assertEqual (json_str , self . expected_str )
84
+ self .assertEqual (json_str , "true \n " )
86
85
87
86
def test_evaluate_snippet (self ):
88
87
json_str = _jsonnet .evaluate_snippet (
89
- "snippet" ,
88
+ self . test_filename ,
90
89
self .input_snippet ,
91
90
import_callback = import_callback ,
92
91
native_callbacks = native_callbacks ,
93
92
)
94
- self .assertEqual (json_str , self .expected_str )
93
+ self .assertEqual (json_str , "true\n " )
94
+
95
+ def test_import (self ):
96
+ json_str = _jsonnet .evaluate_snippet (
97
+ self .test_filename ,
98
+ "import 'trivial.jsonnet'" ,
99
+ import_callback = import_callback ,
100
+ native_callbacks = native_callbacks ,
101
+ )
102
+ self .assertEqual (json_str , "42\n " )
103
+
104
+ def test_double_import (self ):
105
+ json_str = _jsonnet .evaluate_snippet (
106
+ self .test_filename ,
107
+ "local x = import 'trivial.jsonnet';\n " +
108
+ "local y = import 'trivial.jsonnet';\n " +
109
+ "x + y" ,
110
+ import_callback = import_callback ,
111
+ native_callbacks = native_callbacks ,
112
+ )
113
+ self .assertEqual (json_str , "84\n " )
114
+
95
115
96
116
if __name__ == '__main__' :
97
117
unittest .main ()
0 commit comments