-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Make contrib test pluggable (#2654)
* make contrib test plugable Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * no autouse Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * pass request Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * fix fixture name Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * publish trino fixture on package level Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * format Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * disable some tests for contrib tests run Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com> * address comments Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com>
- Loading branch information
Showing
23 changed files
with
255 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
sdk/python/feast/infra/offline_stores/contrib/contrib_repo_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sdk/python/feast/infra/offline_stores/contrib/postgres_offline_store/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .data_source import postgres_container # noqa |
122 changes: 122 additions & 0 deletions
122
sdk/python/feast/infra/offline_stores/contrib/postgres_offline_store/tests/data_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import logging | ||
from typing import Dict, Optional | ||
|
||
import pandas as pd | ||
import pytest | ||
from testcontainers.core.container import DockerContainer | ||
from testcontainers.core.waiting_utils import wait_for_logs | ||
|
||
from feast.data_source import DataSource | ||
from feast.infra.offline_stores.contrib.postgres_offline_store.postgres import ( | ||
PostgreSQLOfflineStoreConfig, | ||
PostgreSQLSource, | ||
) | ||
from feast.infra.utils.postgres.connection_utils import df_to_postgres_table | ||
from tests.integration.feature_repos.universal.data_source_creator import ( | ||
DataSourceCreator, | ||
) | ||
from tests.integration.feature_repos.universal.online_store_creator import ( | ||
OnlineStoreCreator, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
POSTGRES_USER = "test" | ||
POSTGRES_PASSWORD = "test" | ||
POSTGRES_DB = "test" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def postgres_container(): | ||
container = ( | ||
DockerContainer("postgres:latest") | ||
.with_exposed_ports(5432) | ||
.with_env("POSTGRES_USER", POSTGRES_USER) | ||
.with_env("POSTGRES_PASSWORD", POSTGRES_PASSWORD) | ||
.with_env("POSTGRES_DB", POSTGRES_DB) | ||
) | ||
|
||
container.start() | ||
|
||
log_string_to_wait_for = "database system is ready to accept connections" | ||
waited = wait_for_logs( | ||
container=container, predicate=log_string_to_wait_for, timeout=30, interval=10, | ||
) | ||
logger.info("Waited for %s seconds until postgres container was up", waited) | ||
|
||
yield container | ||
container.stop() | ||
|
||
|
||
class PostgreSQLDataSourceCreator(DataSourceCreator, OnlineStoreCreator): | ||
def __init__( | ||
self, project_name: str, fixture_request: pytest.FixtureRequest, **kwargs | ||
): | ||
super().__init__(project_name,) | ||
|
||
self.project_name = project_name | ||
self.container = fixture_request.getfixturevalue("postgres_container") | ||
if not self.container: | ||
raise RuntimeError( | ||
"In order to use this data source " | ||
"'feast.infra.offline_stores.contrib.postgres_offline_store.tests' " | ||
"must be include into pytest plugins" | ||
) | ||
|
||
self.offline_store_config = PostgreSQLOfflineStoreConfig( | ||
type="postgres", | ||
host="localhost", | ||
port=self.container.get_exposed_port(5432), | ||
database=self.container.env["POSTGRES_DB"], | ||
db_schema="public", | ||
user=self.container.env["POSTGRES_USER"], | ||
password=self.container.env["POSTGRES_PASSWORD"], | ||
) | ||
|
||
def create_data_source( | ||
self, | ||
df: pd.DataFrame, | ||
destination_name: str, | ||
suffix: Optional[str] = None, | ||
timestamp_field="ts", | ||
created_timestamp_column="created_ts", | ||
field_mapping: Dict[str, str] = None, | ||
) -> DataSource: | ||
destination_name = self.get_prefixed_table_name(destination_name) | ||
|
||
if self.offline_store_config: | ||
df_to_postgres_table(self.offline_store_config, df, destination_name) | ||
|
||
return PostgreSQLSource( | ||
name=destination_name, | ||
query=f"SELECT * FROM {destination_name}", | ||
timestamp_field=timestamp_field, | ||
created_timestamp_column=created_timestamp_column, | ||
field_mapping=field_mapping or {"ts_1": "ts"}, | ||
) | ||
|
||
def create_offline_store_config(self) -> PostgreSQLOfflineStoreConfig: | ||
assert self.offline_store_config | ||
return self.offline_store_config | ||
|
||
def get_prefixed_table_name(self, suffix: str) -> str: | ||
return f"{self.project_name}_{suffix}" | ||
|
||
def create_online_store(self) -> Dict[str, str]: | ||
assert self.container | ||
return { | ||
"type": "postgres", | ||
"host": "localhost", | ||
"port": self.container.get_exposed_port(5432), | ||
"database": POSTGRES_DB, | ||
"db_schema": "feature_store", | ||
"user": POSTGRES_USER, | ||
"password": POSTGRES_PASSWORD, | ||
} | ||
|
||
def create_saved_dataset_destination(self): | ||
# FIXME: ... | ||
return None | ||
|
||
def teardown(self): | ||
pass |
6 changes: 3 additions & 3 deletions
6
sdk/python/feast/infra/offline_stores/contrib/postgres_repo_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...python/feast/infra/offline_stores/contrib/trino_offline_store/test_config/manual_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sdk/python/feast/infra/offline_stores/contrib/trino_offline_store/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .data_source import trino_container # noqa |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.