def test_json_output_mocked(self): yaml = """ - object: foo count: 2 fields: a: b c: 3 """ stdout = StringIO() output_stream = JSONOutputStream(stdout) generate(StringIO(yaml), {}, output_stream) output_stream.close() assert json.loads(stdout.getvalue()) == [ { "_table": "foo", "a": "b", "c": 3.0, "id": 1 }, { "_table": "foo", "a": "b", "c": 3.0, "id": 2 }, ]
def test_error_generates_empty_string(self): yaml = """ - object: foo fields: bar: baz: jaz is_null: """ with StringIO() as s: output_stream = JSONOutputStream(s) with pytest.raises(exc.DataGenYamlSyntaxError): generate(StringIO(yaml), {}, output_stream) output_stream.close() assert s.getvalue() == ""
def test_json_output_real(self): yaml = """ - object: foo count: 15 fields: a: b c: 3 """ output_stream = JSONOutputStream(StringIO()) generate(StringIO(yaml), {}, output_stream) output_stream.close()
def test_stringification(self, write_row): yaml = """ - plugin: tests.test_custom_plugins_and_providers.EvalPlugin - object: OBJ fields: some_value: - EvalPlugin.add: - 1 - EvalPlugin.sub: - 5 - 3 """ with StringIO() as s: output_stream = JSONOutputStream(s) generate(StringIO(yaml), {}, output_stream) output_stream.close() assert eval(s.getvalue())[0]["some_value"] == 3
def do_output(self, yaml): with StringIO() as s: output_stream = JSONOutputStream(s) results = generate(StringIO(yaml), {}, output_stream) output_stream.close() return JSONTables(s.getvalue(), results.tables.keys())