-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Make contrib test pluggable #2654
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
83a5184
make contrib test plugable
pyalex dc0e2ee
no autouse
pyalex f4b4c59
pass request
pyalex 7f3aee3
fix fixture name
pyalex 9b10f97
publish trino fixture on package level
pyalex c8dd068
format
pyalex 49d2ef9
disable some tests for contrib tests run
pyalex 7f0ab4c
address comments
pyalex 55d9d79
Merge branch 'master' into refactor-contrib-tests
pyalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove the
PYTHONPATH
, this can be updated tofeast.infra.offline_stores.contrib.postgres_offline_store.tests
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the import logic is the same as in
FULL_REPO_CONFIGS_MODULE
. Since our working dir is repo root we're probably needsdk.python
prefix.