Skip to content

Commit b35845f

Browse files
gabryspitercl
andauthored
Make ensure_project itself a fixture (#134)
* Make ensure_project itself a fixture * Update e2e/experimental/test_fetch_experiments_table as well * Add docstring to ensure_project * Update whitespace in docstring * code review notes - doc update Co-authored-by: Piotr Łusakowski <[email protected]> * Further docs update for ensure_project fixture --------- Co-authored-by: Piotr Łusakowski <[email protected]>
1 parent 587bf90 commit b35845f

File tree

5 files changed

+69
-26
lines changed

5 files changed

+69
-26
lines changed

tests/e2e/conftest.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
PATH,
3838
TEST_DATA,
3939
)
40+
from tests.e2e.data_ingestion import (
41+
IngestedProjectData,
42+
ProjectData,
43+
ingest_project,
44+
)
4045

4146

4247
@dataclass
@@ -236,3 +241,60 @@ def temp_dir():
236241

237242
def extract_pages(generator):
238243
return list(it.chain.from_iterable(i.items for i in generator))
244+
245+
246+
class EnsureProjectFunction:
247+
"""
248+
See ensure_project fixture docstring for usage details.
249+
"""
250+
251+
def __init__(self, client: AuthenticatedClient, api_token: str, workspace: str, test_execution_id: str):
252+
self.client = client
253+
self.api_token = api_token
254+
self.workspace = workspace
255+
self.test_execution_id = test_execution_id
256+
257+
def __call__(self, project_data: ProjectData, unique_key: str | None = None) -> IngestedProjectData:
258+
return ingest_project(
259+
client=self.client,
260+
api_token=self.api_token,
261+
workspace=self.workspace,
262+
unique_key=unique_key or self.test_execution_id,
263+
project_data=project_data,
264+
)
265+
266+
267+
@pytest.fixture(scope="session")
268+
def ensure_project(client, api_token, workspace, test_execution_id) -> EnsureProjectFunction:
269+
"""Fixture returning a function-like object that can be used to create or retrieve projects with specified data.
270+
271+
Arguments for the returned callable:
272+
project_data: Data to initialize the project with
273+
unique_key: [optional] A unique identifier for tagging and later filtering projects, experiments, and runs.
274+
Tests spanning multiple projects should provide a unique_key that embeds the test_execution_id
275+
plus any additional context needed for disambiguation (e.g., module name).
276+
If not provided, the unique test_execution_id will be used.
277+
278+
Returns:
279+
IngestedProjectData containing information about the created/retrieved project
280+
281+
Example:
282+
@pytest.fixture
283+
def project_gamma(ensure_project):
284+
ingested_project = ensure_project(
285+
ProjectData(
286+
project_name_base="test_project",
287+
runs=[
288+
RunData(
289+
experiment_name_base="experiment_gamma",
290+
config={"param": "value"},
291+
float_series={"metrics/accuracy": {0: 0.5, 1: 0.75, 2: 0.9}},
292+
string_series={"logs/status": {0: "started", 1: "in_progress", 2: "completed"}},
293+
histogram_series={ ... },
294+
files={ ... },
295+
)
296+
...
297+
],
298+
))
299+
"""
300+
return EnsureProjectFunction(client, api_token, workspace, test_execution_id)

tests/e2e/data_ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class IngestedProjectData:
128128
ingested_runs: list[IngestedRunData]
129129

130130

131-
def ensure_project(
131+
def ingest_project(
132132
*,
133133
client: AuthenticatedClient,
134134
api_token: str,

tests/e2e/experimental/test_fetch_experiments_table_global.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
IngestedRunData,
1717
ProjectData,
1818
RunData,
19-
ensure_project,
2019
)
2120

2221
pytestmark = pytest.mark.filterwarnings("ignore:.*fetch_.*_table.*:neptune_query.warnings.ExperimentalWarning")
@@ -248,7 +247,7 @@ def test_fetch_experiments_table_with_empty_attributes(project_1, project_2, uni
248247

249248

250249
@pytest.fixture(scope="session")
251-
def project_1(client, api_token, workspace, unique_execution_module_key) -> IngestedProjectData:
250+
def project_1(ensure_project, unique_execution_module_key) -> IngestedProjectData:
252251
exp_project_1_root = RunData(
253252
experiment_name_base="exp_project_1",
254253
run_id_base="run_project_1_root",
@@ -317,9 +316,6 @@ def project_1(client, api_token, workspace, unique_execution_module_key) -> Inge
317316
)
318317

319318
return ensure_project(
320-
client=client,
321-
api_token=api_token,
322-
workspace=workspace,
323319
unique_key=unique_execution_module_key,
324320
project_data=ProjectData(
325321
project_name_base="global_fetch_experiments_table_project_1",
@@ -335,7 +331,7 @@ def project_1(client, api_token, workspace, unique_execution_module_key) -> Inge
335331

336332

337333
@pytest.fixture(scope="session")
338-
def project_2(client, api_token, workspace, unique_execution_module_key) -> IngestedProjectData:
334+
def project_2(ensure_project, unique_execution_module_key) -> IngestedProjectData:
339335
exp_project_2_root = RunData(
340336
experiment_name_base="exp_project_2",
341337
run_id_base="run_project_2_root",
@@ -404,9 +400,6 @@ def project_2(client, api_token, workspace, unique_execution_module_key) -> Inge
404400
)
405401

406402
return ensure_project(
407-
client=client,
408-
api_token=api_token,
409-
workspace=workspace,
410403
unique_key=unique_execution_module_key,
411404
project_data=ProjectData(
412405
project_name_base="global_fetch_experiments_table_project_2",

tests/e2e/experimental/test_fetch_runs_table_global.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
IngestedRunData,
1717
ProjectData,
1818
RunData,
19-
ensure_project,
2019
)
2120

2221
pytestmark = pytest.mark.filterwarnings("ignore:.*fetch_.*_table.*:neptune_query.warnings.ExperimentalWarning")
@@ -243,11 +242,8 @@ def test_fetch_runs_table_with_empty_attributes(project_1, project_2, unique_exe
243242

244243

245244
@pytest.fixture(scope="session")
246-
def project_1(client, api_token, workspace, unique_execution_module_key) -> IngestedProjectData:
245+
def project_1(ensure_project, unique_execution_module_key) -> IngestedProjectData:
247246
return ensure_project(
248-
client=client,
249-
api_token=api_token,
250-
workspace=workspace,
251247
unique_key=unique_execution_module_key,
252248
project_data=ProjectData(
253249
project_name_base="project_1",
@@ -298,11 +294,8 @@ def project_1(client, api_token, workspace, unique_execution_module_key) -> Inge
298294

299295

300296
@pytest.fixture(scope="session")
301-
def project_2(client, api_token, workspace, unique_execution_module_key) -> IngestedProjectData:
297+
def project_2(ensure_project, unique_execution_module_key) -> IngestedProjectData:
302298
return ensure_project(
303-
client=client,
304-
api_token=api_token,
305-
workspace=workspace,
306299
unique_key=unique_execution_module_key,
307300
project_data=ProjectData(
308301
project_name_base="project_2",

tests/e2e/internal/retrieval/test_series.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
IngestionHistogram,
2828
ProjectData,
2929
RunData,
30-
ensure_project,
3130
step_to_timestamp,
3231
)
3332

@@ -75,13 +74,9 @@ def __eq__(self, other: NQInternalHistogram) -> bool:
7574

7675

7776
@pytest.fixture(scope="session")
78-
def project_1(client, api_token, workspace, test_execution_id) -> IngestedProjectData:
77+
def project_1(ensure_project) -> IngestedProjectData:
7978
return ensure_project(
80-
client=client,
81-
api_token=api_token,
82-
workspace=workspace,
83-
unique_key=test_execution_id,
84-
project_data=ProjectData(
79+
ProjectData(
8580
project_name_base="project_404",
8681
runs=[
8782
RunData(

0 commit comments

Comments
 (0)