def test_cant_output_unknown_format():
    with pytest.raises(ValueError):
        MatchesOutput(MATCHES, out_dest="console", fmt="asc")
    with pytest.raises(ValueError):
        MatchesOutput(MATCHES, out_dest="console", fmt=None)
    with pytest.raises(ValueError):
        MatchesOutput(MATCHES, out_dest="console", fmt=[])
    with pytest.raises(ValueError):
        MatchesOutput(MATCHES, out_dest="console", fmt=object())
Beispiel #2
0
def _action_matches(in_file, in_fmt, out_dest, out_fmt):
    print("reading matches from ({})[{}]...".format(in_fmt, in_file))
    matches = MatchesInput.read_file(in_file, in_fmt)

    if out_dest != "console":
        print("got [{}] matches:".format(len(matches)))
        MatchesOutput.write_matches(matches, "console", "plain")

    print("writing [{}] matches ({}) to [{}]...\n".format(
        len(matches), out_fmt, out_dest))
    MatchesOutput.write_matches(matches, out_dest, out_fmt)
    print("Done writing matches!")
Beispiel #3
0
def _action_scenarios(in_file, in_fmt, out_dest, out_fmt):
    print("reading matches from ({})[{}]...".format(in_fmt, in_file))
    matches = MatchesInput.read_file(in_file, in_fmt)

    print("got [{}] matches:".format(len(matches)))
    MatchesOutput.write_matches(matches, "console", "plain")

    print("generating scenarios...")
    scenarios = list(ScenariosGenerator(matches).generate_scenarios())
    print("got total of [{}] scenarios".format(len(scenarios)))

    print("writing scenarios to ({})[{}]...".format(out_fmt, out_dest))
    ScenariosOutput.write_scenarios(scenarios, out_dest, out_fmt)
    print("Done writing scenarios to ({})[{}]...".format(out_fmt, out_dest))
def test_output_to_console(mock_print):

    MatchesOutput.write_matches(MATCHES, "console", "csv")
    mock_print.assert_called_with(EXPECTED_CSV)

    MatchesOutput.write_matches(MATCHES, "console", "fancy_grid")
    mock_print.assert_called_with(EXPECTED_TABLE_FANCY_GRID)

    MatchesOutput.write_matches(MATCHES, "console", "plain")
    mock_print.assert_called_with(EXPECTED_TABLE_PLAIN)
def test_write_to_file_table_plain():
    txt_file = _get_temp_file_no_ext() + ".txt"
    MatchesOutput.write_matches(MATCHES, txt_file, "plain")
    actual_text = Path(txt_file).read_text(encoding="utf-8")
    Path(txt_file).unlink()
    assert actual_text == EXPECTED_TABLE_PLAIN
def test_write_to_file_table_fancy_grid():
    txt_file = _get_temp_file_no_ext() + ".txt"
    MatchesOutput.write_matches(MATCHES, txt_file, "fancy_grid")
    actual_text = Path(txt_file).read_text(encoding="utf-8")
    Path(txt_file).unlink()
    assert actual_text == EXPECTED_TABLE_FANCY_GRID
def test_write_to_file_csv():
    csv_file = _get_temp_file_no_ext() + ".csv"
    MatchesOutput.write_matches(MATCHES, csv_file, "csv")
    actual_csv = Path(csv_file).read_text(encoding="utf-8")
    Path(csv_file).unlink()
    assert actual_csv == EXPECTED_CSV