activate environment again in test

This commit is contained in:
Pablo Martin 2024-06-13 15:59:03 +02:00
parent 515a4527af
commit aa0919c790

View file

@ -78,50 +78,50 @@ def test_get_rates_dry_run_always_returns_42_as_rates():
runner = CliRunner() runner = CliRunner()
# with runner.isolated_filesystem(): with runner.isolated_filesystem():
run_result = runner.invoke( run_result = runner.invoke(
get_rates, get_rates,
[ [
"--start-date", "--start-date",
some_random_date.strftime("%Y-%m-%d"), some_random_date.strftime("%Y-%m-%d"),
"--end-date", "--end-date",
(some_random_date + datetime.timedelta(days=3)).strftime("%Y-%m-%d"), (some_random_date + datetime.timedelta(days=3)).strftime("%Y-%m-%d"),
"--currencies", "--currencies",
",".join(some_random_currencies), ",".join(some_random_currencies),
"--output", "--output",
"test_output.csv", "test_output.csv",
], ],
) )
assert run_result.exit_code == 0 assert run_result.exit_code == 0
with open("test_output.csv", newline="") as csv_file: with open("test_output.csv", newline="") as csv_file:
reader = csv.DictReader(csv_file) reader = csv.DictReader(csv_file)
rows = list(reader) rows = list(reader)
# Ensure that the output contains the correct number of rows
expected_num_rows = 36
assert (
len(rows) == expected_num_rows
), f"Expected {expected_num_rows} rows, but got {len(rows)}"
# Check that all rows have the expected rate of 42, 1/42 or 1 and the correct dates
for row in rows:
assert row["rate"] in (
"42",
"0.024",
"0.02",
"0",
"1",
), f"Expected rate to be 42, 1/42 or 1, but got {row['rate']}"
assert row["rate_date"] in [
(some_random_date + datetime.timedelta(days=i)).strftime("%Y-%m-%d")
for i in range(4)
], f"Unexpected rate_date {row['rate_date']}"
# Ensure that the output contains the correct number of rows
expected_num_rows = 36
assert ( assert (
row["from_currency"] in some_random_currencies len(rows) == expected_num_rows
), f"Unexpected from_currency {row['from_currency']}" ), f"Expected {expected_num_rows} rows, but got {len(rows)}"
assert (
row["to_currency"] in some_random_currencies # Check that all rows have the expected rate of 42, 1/42 or 1 and the correct dates
), f"Unexpected to_currency {row['to_currency']}" for row in rows:
assert row["rate"] in (
"42",
"0.024",
"0.02",
"0",
"1",
), f"Expected rate to be 42, 1/42 or 1, but got {row['rate']}"
assert row["rate_date"] in [
(some_random_date + datetime.timedelta(days=i)).strftime("%Y-%m-%d")
for i in range(4)
], f"Unexpected rate_date {row['rate_date']}"
assert (
row["from_currency"] in some_random_currencies
), f"Unexpected from_currency {row['from_currency']}"
assert (
row["to_currency"] in some_random_currencies
), f"Unexpected to_currency {row['to_currency']}"