def test_evaluate_snippet(self): json_str = _gojsonnet.evaluate_snippet( self.test_filename, self.input_snippet, import_callback=import_callback, native_callbacks=native_callbacks, ) self.assertEqual(json_str, "true\n")
def test_import(self): json_str = _gojsonnet.evaluate_snippet( self.test_filename, "import 'trivial.jsonnet'", import_callback=import_callback, native_callbacks=native_callbacks, ) self.assertEqual(json_str, "42\n")
def test_evaluate_snippet(self): json_str = _gojsonnet.evaluate_snippet( "snippet", self.input_snippet, import_callback=import_callback, native_callbacks=native_callbacks, ) self.assertEqual(json_str, self.expected_str)
def _convert(yaml_in: str, array: bool) -> dict: """ Take a YAML doc in string-form, return the result of YAML -> Jsonnet -> JSON -> json.loads() """ output = StringIO() convert_yaml(yaml_in, output, array=array) json = evaluate_snippet(src=output.getvalue(), filename="") return loads(json)
def test_double_import(self): json_str = _gojsonnet.evaluate_snippet( self.test_filename, "local x = import 'trivial.jsonnet';\n" + "local y = import 'trivial.jsonnet';\n" + "x + y", import_callback=import_callback, native_callbacks=native_callbacks, ) self.assertEqual(json_str, "84\n")
def test_flow_round_trip_single_arr(arr): original_json = dumps(arr, sort_keys=True) # Jsonnet mangles "\ud800\udc00", so we'll skip some things assume(not unicode_re.search(original_json)) # Python preserves 0.0 and 0, but Jsonnet does not. Transform float to int when it's free original_json = trailing_zero_re.sub("", original_json) # Python and Jsonnet have different ideas about rendering 1e16 assume(not sci_number_re.search(original_json)) # Very large ints aren't preserved by JSON since they become floats assume(not too_big_int_re.search(original_json)) output = StringIO() convert_yaml(yaml_data=original_json, output=output, array=False) jsonnet_json = evaluate_snippet(src=output.getvalue(), filename="") rt_json = dumps(loads(jsonnet_json), sort_keys=True) assert original_json == rt_json
def test_simple_list(): """Test that we can get a list through to JSON""" event_list = [ events.StreamStartEvent(), events.DocumentStartEvent(), events.SequenceStartEvent(None, None, None), events.ScalarEvent(None, None, None, "hello"), events.ScalarEvent(None, None, None, "world"), events.SequenceEndEvent(), events.DocumentEndEvent(), events.StreamEndEvent(), ] output = StringIO() JsonnetRenderer(event_list, output, False).render() json = evaluate_snippet(src=output.getvalue(), filename="") data = loads(json) assert len(data) == 2 assert data[0] == "hello" assert data[1] == "world"