def test_format_accepts_encoding(): # issue20 sql = load_file('test_cp1251.sql', 'cp1251') formatted = sqlparse.format(sql, reindent=True, encoding='cp1251') if sys.version_info < (3, ): tformatted = u'insert into foo\nvalues (1); -- Песня про надежду\n' else: tformatted = 'insert into foo\nvalues (1); -- Песня про надежду\n' assert formatted == tformatted
def test_format_accepts_encoding(): # issue20 sql = load_file('test_cp1251.sql', 'cp1251') formatted = sqlparse.format(sql, reindent=True, encoding='cp1251') if sys.version_info < (3,): tformatted = u'insert into foo\nvalues (1); -- Песня про надежду\n' else: tformatted = 'insert into foo\nvalues (1); -- Песня про надежду\n' assert formatted == tformatted
def test_yaml_simple_outputfile(fixture_tmpdir, fixture_clicker): """ python3 -mas3ninja transform -c examples/simple/ninja.yaml -t examples/simple/template.j2 -o /tmp/output.json """ tmpdir = fixture_tmpdir result = fixture_clicker.invoke( cli, [ "transform", "-c", "examples/simple/ninja.yaml", "-t", "examples/simple/template.j2", "-o", f"{tmpdir}/output.json", ], ) assert result.exit_code == 0 assert format_json(load_file(f"{tmpdir}/output.json")) == format_json( load_file("examples/simple/declaration.json"))
def test_yaml_simple_longoptions(fixture_clicker): """ python3 -mas3ninja transform --configuration-file examples/simple/ninja.yaml --declaration-template examples/simple/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "--configuration-file", "examples/simple/ninja.yaml", "--declaration-template", "examples/simple/template.j2", ], ) assert result.exit_code == 0 assert format_json(result.output) == format_json( load_file("examples/simple/declaration.json"))
def test_yaml_pretty_print(fixture_clicker): """ python3 -mas3ninja transform --pretty --no-validate -c examples/yaml_datatypes/config.yaml -t examples/yaml_datatypes/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "--pretty", "--no-validate", "-c", "examples/yaml_datatypes/config.yaml", "-t", "examples/yaml_datatypes/template.j2", ], ) assert result.exit_code == 0 assert result.output == load_file("examples/yaml_datatypes/output.json")
def test_yaml_simple_configoverlay(fixture_clicker): """ python3 -mas3ninja transform -c examples/simple/ninja.yaml -c examples/simple/overlay.json -t examples/simple/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "-c", "examples/simple/ninja.yaml", "-c", "examples/simple/overlay.json", "-t", "examples/simple/template.j2", ], ) assert result.exit_code == 0 assert format_json(result.output) == format_json( load_file("examples/simple/declaration_with_overlay.json"))
def test_yaml_datatypes(fixture_clicker): """ python3 -mas3ninja transform --no-validate -c examples/yaml_datatypes/config.yaml -t examples/yaml_datatypes/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "--no-validate", "-c", "examples/yaml_datatypes/config.yaml", "-t", "examples/yaml_datatypes/template.j2", ], ) assert result.exit_code == 0 print(f"\n\nresult.output:{result.output}\n\n") assert format_json(result.output) == format_json( load_file("examples/yaml_datatypes/output.json") )
def test_begintag_2(self): sql = load_file('begintag_2.sql') stmts = sqlparse.parse(sql) self.assertEqual(len(stmts), 1) self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
def test_dashcomments(self): sql = load_file('dashcomment.sql') stmts = sqlparse.parse(sql) self.assertEqual(len(stmts), 3) self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
def test_create_function_psql2(self): sql = load_file('function_psql2.sql') stmts = sqlparse.parse(sql) self.assertEqual(len(stmts), 1) self.ndiffAssertEqual(unicode(stmts[0]), sql)