def test_exception_with_debug_flags_off(self, write_row): with named_temporary_file_path(suffix=".yml") as t: with pytest.raises(ClickException): generate_cli.callback( yaml_file=bad_sample_yaml, option={}, debug_internals=False, generate_cci_mapping_file=t, ) assert yaml.safe_load(t)
def test_cli_errors__mutex3(self): with named_temporary_file_path() as tempfile: with open(tempfile, "w") as t: t.write("") with pytest.raises(ClickException) as e: generate_cli.main( [str(sample_yaml), "--cci-mapping-file", tempfile], standalone_mode=False, ) assert "--cci-mapping-file" in str(e.value)
def test_from_cli__pluggable_output_stream(self): with named_temporary_file_path(suffix=".yml") as t: generate_cli.main( [ str(sample_yaml), "--output-format", "examples.YamlOutputStream", "--output-file", t, ], standalone_mode=False, ) assert t.exists()
def do_output(self, yaml): with named_temporary_file_path() as f: url = f"sqlite:///{f}" output_stream = SqlDbOutputStream.from_url(url) results = generate(StringIO(yaml), {}, output_stream) table_names = results.tables.keys() output_stream.close() engine = create_engine(url) with engine.connect() as connection: tables = { table_name: list(connection.execute(f"select * from {table_name}")) for table_name in table_names } return tables
def test_from_cli__explicit_format_txt(self, capsys): with named_temporary_file_path() as t: generate_cli.main( [ str(sample_yaml), "--target-number", "Account", "5", "--output-format", "txt", "--output-file", str(t), ], standalone_mode=False, ) with t.open() as f: output = f.read() assert len(re.findall(r"Account\(", output)) == 5
def do_output(self, yaml): with named_temporary_file_path() as f: path = str(f) + ".sql" output_stream = SqlTextOutputStream(path) generate(StringIO(yaml), {}, output_stream) output_stream.close() import sqlite3 con = sqlite3.connect(":memory:") with open(path, "r") as f: data = f.read() con.executescript(data) table_name_rows = con.execute("select name from sqlite_master").fetchall() table_names = [r[0] for r in table_name_rows] print(table_names) con.row_factory = sqlite3.Row tables = { table_name: con.execute(f"select * from {table_name}").fetchall() for table_name in table_names } return tables