Skip to content

Commit 6b3d1a2

Browse files
test: Speed up CLI date parsing unit test (#6501)
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
1 parent a1e8b4d commit 6b3d1a2

1 file changed

Lines changed: 72 additions & 39 deletions

File tree

  • sdk/python/tests/unit/infra/offline_stores/contrib/postgres_offline_store

sdk/python/tests/unit/infra/offline_stores/contrib/postgres_offline_store/test_postgres.py

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,10 @@ def test_cli_date_combinations(self):
953953
from pathlib import Path
954954
from textwrap import dedent
955955

956-
from tests.utils.cli_repo_creator import CliRunner, get_example_repo
956+
from click.testing import CliRunner
957+
958+
from feast.cli.cli import cli
959+
from feast.feature_store import FeatureStore
957960

958961
runner = CliRunner()
959962

@@ -975,46 +978,76 @@ def test_cli_date_combinations(self):
975978
""")
976979
)
977980

978-
repo_example = repo_path / "example.py"
979-
repo_example.write_text(get_example_repo("example_feature_repo_1.py"))
980-
981-
result = runner.run(["apply"], cwd=repo_path)
982-
assert result.returncode == 0
983-
984-
# Test 1: Both dates provided - should parse correctly
985-
result = runner.run(
986-
[
987-
"get-historical-features",
988-
"--features",
989-
"driver_hourly_stats:conv_rate",
990-
"--start-date",
991-
"2023-01-01 00:00:00",
992-
"--end-date",
993-
"2023-01-07 00:00:00",
994-
],
995-
cwd=repo_path,
996-
)
981+
retrieval_job = MagicMock()
982+
retrieval_job.to_df.return_value = pd.DataFrame()
983+
984+
with patch.object(
985+
FeatureStore, "get_historical_features", return_value=retrieval_job
986+
) as mock_get_historical_features:
987+
# Test 1: Both dates provided - should parse correctly
988+
result = runner.invoke(
989+
cli,
990+
[
991+
"--chdir",
992+
str(repo_path),
993+
"get-historical-features",
994+
"--features",
995+
"driver_hourly_stats:conv_rate",
996+
"--start-date",
997+
"2023-01-01 00:00:00",
998+
"--end-date",
999+
"2023-01-07 00:00:00",
1000+
],
1001+
)
9971002

998-
# Should not fail on date parsing
999-
stderr_output = result.stderr.decode()
1000-
assert "Error parsing" not in stderr_output
1001-
assert "time data" not in stderr_output # datetime parsing errors
1002-
1003-
# Test 2: Only end date provided - should work (start_date calculated from TTL)
1004-
result = runner.run(
1005-
[
1006-
"get-historical-features",
1007-
"--features",
1008-
"driver_hourly_stats:conv_rate",
1009-
"--end-date",
1010-
"2023-01-07 00:00:00",
1011-
],
1012-
cwd=repo_path,
1013-
)
1003+
assert result.exit_code == 0, result.output
1004+
assert mock_get_historical_features.call_args.kwargs[
1005+
"start_date"
1006+
] == datetime(2023, 1, 1)
1007+
assert mock_get_historical_features.call_args.kwargs[
1008+
"end_date"
1009+
] == datetime(2023, 1, 7)
1010+
1011+
# Test 2: Only end date provided - should work (start_date calculated from TTL)
1012+
result = runner.invoke(
1013+
cli,
1014+
[
1015+
"--chdir",
1016+
str(repo_path),
1017+
"get-historical-features",
1018+
"--features",
1019+
"driver_hourly_stats:conv_rate",
1020+
"--end-date",
1021+
"2023-01-07 00:00:00",
1022+
],
1023+
)
10141024

1015-
# Should not fail on parameter validation
1016-
stderr_output = result.stderr.decode()
1017-
assert "must be provided" not in stderr_output
1025+
assert result.exit_code == 0, result.output
1026+
assert (
1027+
mock_get_historical_features.call_args.kwargs["start_date"] is None
1028+
)
1029+
assert mock_get_historical_features.call_args.kwargs[
1030+
"end_date"
1031+
] == datetime(2023, 1, 7)
1032+
1033+
# Test 3: No date or dataframe provided - should fail validation before retrieval.
1034+
result = runner.invoke(
1035+
cli,
1036+
[
1037+
"--chdir",
1038+
str(repo_path),
1039+
"get-historical-features",
1040+
"--features",
1041+
"driver_hourly_stats:conv_rate",
1042+
],
1043+
)
1044+
1045+
assert result.exit_code == 0, result.output
1046+
assert (
1047+
"Either --dataframe or --start-date and/or --end-date must be provided."
1048+
in result.output
1049+
)
1050+
assert mock_get_historical_features.call_count == 2
10181051

10191052

10201053
class TestPostgreSQLSourceQueryStringAlias:

0 commit comments

Comments
 (0)