def test_print_results_3(self): """Test simple query""" args = Struct(**{"raw": 1, "html_unescape": 1, "bw": 0, "forcecolor": 1}) with captured_output() as (out, err): print_results([{"a": 1}], args) output = out.getvalue().strip() self.assertEqual(output, '{"a": 1}')
def test_yaml_file(self): """Test simple query""" args = Struct(**{"files": ["input.yaml"], "yamli": 1}) def openhook(a=None, b=None): test_str = "- list" return BytesIO(test_str.encode()) result = list(read_input(args, openhook=openhook)) self.assertEqual(result, ["list"])
def test_jsonl_file(self): """Test simple query""" args = Struct(**{"files": ["input.json"], "yamli": 0}) def openhook(a=None, b=None): test_str = '{"a": 1}\n{"a": 2}' return BytesIO(test_str.encode()) result = list(read_input(args, openhook=openhook)) self.assertEqual(result, [{"a": 1}, {"a": 2}])
def test_xml_string(self): """Test simple query""" args = Struct(**{"files": ["tests/test.xml"]}) result = list(read_input(args)) self.assertEqual( result, [ { "item": [ {"a": "1", "b": "2", "c": "3"}, {"a": "4", "b": "5", "c": "6"}, ] } ], )
def test_handle_broken_pipe(self): """Test simple query""" args = Struct(**{"raw": 1, "html_unescape": 1, "bw": 0, "forcecolor": 1}) with captured_output(BrokenPipeOutput) as (out, err): print_results([{"a": 1}], args)
def test_print_results_2(self): """Test simple query""" args = Struct(**{"raw": 1, "html_unescape": 1, "bw": 0, "forcecolor": 1}) print_results(["a"], args)
def test_print_result_list_3(self): """Test simple query""" args = Struct( **{"list": 1, "raw": 1, "html_unescape": 1, "bw": 0, "forcecolor": 1} ) print_results([{"a": 1}], args)
def test_csv_string(self): """Test simple query""" args = Struct(**{"files": ["tests/test.csv"]}) result = list(read_input(args)) self.assertEqual(result, [{"a": 1, "b": 2, "c": 3}, {"a": 4, "b": 5, "c": 6}])