def test_e2e_local() -> None: """ A more comprehensive than "basic" test, using local provider. 1. Create a repo. 2. Apply 3. Ingest some data to online store from parquet 4. Read from the online store to make sure it made it there. """ runner = CliRunner() with tempfile.TemporaryDirectory() as data_dir: # Generate some test data in parquet format. end_date = datetime.now().replace(microsecond=0, second=0, minute=0) start_date = end_date - timedelta(days=15) driver_entities = [1001, 1002, 1003, 1004, 1005] driver_df = driver_data.create_driver_hourly_stats_df( driver_entities, start_date, end_date) driver_stats_path = os.path.join(data_dir, "driver_stats.parquet") driver_df.to_parquet(path=driver_stats_path, allow_truncated_timestamps=True) # Note that runner takes care of running apply/teardown for us here. # We patch python code in example_feature_repo_2.py to set the path to Parquet files. with runner.local_repo( get_example_repo("example_feature_repo_2.py").replace( "%PARQUET_PATH%", driver_stats_path), "file", ) as store: assert store.repo_path is not None # feast materialize r = runner.run( [ "materialize", start_date.isoformat(), (end_date - timedelta(days=7)).isoformat(), ], cwd=Path(store.repo_path), ) assert r.returncode == 0 _assert_online_features(store, driver_df, end_date - timedelta(days=7)) # feast materialize-incremental r = runner.run( ["materialize-incremental", end_date.isoformat()], cwd=Path(store.repo_path), ) assert r.returncode == 0 _assert_online_features(store, driver_df, end_date)
def test_non_local_feature_repo() -> None: """ Test running apply on a sample repo, and make sure the infra gets created. """ runner = CliRunner() with tempfile.TemporaryDirectory() as repo_dir_name: # Construct an example repo in a temporary dir repo_path = Path(repo_dir_name) repo_config = repo_path / "feature_store.yaml" repo_config.write_text( dedent(""" project: foo registry: data/registry.db provider: local online_store: path: data/online_store.db """)) repo_example = repo_path / "example.py" repo_example.write_text( (Path(__file__).parent / "example_feature_repo_1.py").read_text()) result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) fs = FeatureStore(repo_path=str(repo_path)) assertpy.assert_that(fs.list_feature_views()).is_length(3) result = runner.run(["teardown"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0)
def test_repo_init() -> None: """ This test simply makes sure that you can run `feast apply && feast materialize` on the repo created by "feast init" without errors. """ runner = CliRunner() with tempfile.TemporaryDirectory() as repo_dir_name: repo_path = Path(repo_dir_name) result = runner.run(["init"], cwd=repo_path) assert result.returncode == 0 result = runner.run(["apply"], cwd=repo_path) assert result.returncode == 0 end_date = datetime.utcnow() start_date = end_date - timedelta(days=100) result = runner.run( ["materialize", start_date.isoformat(), end_date.isoformat()], cwd=repo_path ) assert result.returncode == 0
def test_basic() -> None: project_id = "".join( random.choice(string.ascii_lowercase + string.digits) for _ in range(10)) runner = CliRunner() with tempfile.TemporaryDirectory( ) as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name: repo_path = Path(repo_dir_name) data_path = Path(data_dir_name) repo_config = repo_path / "feature_store.yaml" repo_config.write_text( dedent(f""" project: {project_id} registry: {data_path / "registry.db"} provider: redis offline_store: type: bigquery online_store: redis_type: redis connection_string: localhost:6379,db=0 """)) repo_example = repo_path / "example.py" repo_example.write_text( (Path(__file__).parent / "example_feature_repo_1.py").read_text()) result = runner.run(["apply"], cwd=repo_path) assert result.returncode == 0 # Doing another apply should be a no op, and should not cause errors result = runner.run(["apply"], cwd=repo_path) assert result.returncode == 0 basic_rw_test( FeatureStore(repo_path=str(repo_path), config=None), view_name="driver_locations", ) result = runner.run(["teardown"], cwd=repo_path) assert result.returncode == 0
def test_workflow() -> None: """ Test running apply on a sample repo, and make sure the infra gets created. """ runner = CliRunner() with tempfile.TemporaryDirectory( ) as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name: # Construct an example repo in a temporary dir repo_path = Path(repo_dir_name) data_path = Path(data_dir_name) repo_config = repo_path / "feature_store.yaml" repo_config.write_text( dedent(f""" project: foo registry: {data_path / "registry.db"} provider: local online_store: local: path: {data_path / "online_store.db"} """)) repo_example = repo_path / "example.py" repo_example.write_text( (Path(__file__).parent / "example_feature_repo_1.py").read_text()) result = runner.run(["apply", str(repo_path)], cwd=repo_path) assert result.returncode == 0 # Doing another apply should be a no op, and should not cause errors result = runner.run(["apply", str(repo_path)], cwd=repo_path) assert result.returncode == 0 basic_rw_test( FeatureStore(repo_path=str(repo_path), config=None), view_name="driver_locations", ) result = runner.run(["teardown", str(repo_path)], cwd=repo_path) assert result.returncode == 0
def test_repo_init_with_underscore_in_project_name() -> None: """ Test `feast init` with underscore in the project name """ with tempfile.TemporaryDirectory() as temp_dir: temp_path = Path(temp_dir) runner = CliRunner() # `feast init` should fail with repo names start with underscore invalid_repo_names = ["_test", "_test_1"] for repo_name in invalid_repo_names: result = runner.run(["init", repo_name], cwd=temp_path) assert result.returncode != 0 # `feast init` should succeed with underscore in repo name valid_repo_names = ["test_1"] for repo_name in valid_repo_names: result = runner.run(["init", repo_name], cwd=temp_path) assert result.returncode == 0 # `feast apply` should fail with underscore in project name project_name = "test_1" repo_dir = temp_path / project_name data_dir = repo_dir / "data" repo_config = repo_dir / "feature_store.yaml" repo_config.write_text( dedent( f""" project: __foo registry: {data_dir / "registry.db"} provider: local online_store: path: {data_dir / "online_store.db"} """ ) ) result = runner.run(["apply"], cwd=repo_dir) assert result.returncode != 0
def test_workflow() -> None: """ Test running apply on a sample repo, and make sure the infra gets created. """ runner = CliRunner() with tempfile.TemporaryDirectory( ) as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name: # Construct an example repo in a temporary dir repo_path = Path(repo_dir_name) data_path = Path(data_dir_name) repo_config = repo_path / "feature_store.yaml" repo_config.write_text( dedent(f""" project: foo registry: {data_path / "registry.db"} provider: local online_store: path: {data_path / "online_store.db"} """)) repo_example = repo_path / "example.py" repo_example.write_text( (Path(__file__).parent / "example_feature_repo_1.py").read_text()) result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # entity & feature view list commands should succeed result = runner.run(["entities", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-views", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # entity & feature view describe commands should succeed when objects exist result = runner.run(["entities", "describe", "driver"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-views", "describe", "driver_locations"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # entity & feature view describe commands should fail when objects don't exist result = runner.run(["entities", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) result = runner.run(["feature-views", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) # Doing another apply should be a no op, and should not cause errors result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) basic_rw_test( FeatureStore(repo_path=str(repo_path), config=None), view_name="driver_locations", ) result = runner.run(["teardown"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0)