Skip to content

Commit

Permalink
Update tests with example data
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Sep 9, 2024
1 parent 2dcfb2e commit 97c131e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import gzip
import os
import shutil
from pathlib import Path

import pytest


@pytest.fixture(scope="session", autouse=True)
def set_campaign_id():
original_campaign_id = os.environ.get("RE2FRACTIVE_CAMPAIGN_ID")
os.environ["RE2FRACTIVE_CAMPAIGN_ID"] = "tests"
yield
if original_campaign_id is not None:
os.environ["RE2FRACTIVE_CAMPAIGN_ID"] = original_campaign_id


@pytest.fixture
def trial_dataset():
from re2fractive.datasets import NaccaratoDataset
Expand All @@ -15,6 +26,14 @@ def trial_dataset():
shutil.copyfile(
Path(__file__).parent / "data" / "db.csv", data_dir / "Naccarato.csv"
)
with gzip.open(
Path(__file__).parent / "data" / "Naccarato2019.jsonl.gz", "rb"
) as gzip_in:
with open(data_dir / "Naccarato2019.jsonl.gz", "wb") as f:
shutil.copyfileobj(gzip_in, f)
shutil.copyfile(
Path(__file__).parent / "data" / "meta.json", data_dir / "meta.json"
)

dataset = NaccaratoDataset()
dataset.load()
Expand Down
Binary file added tests/data/Naccarato2019.jsonl.gz
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ctime": "2024-03-30T16:40:57.128057"}
16 changes: 8 additions & 8 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@


@pytest.mark.skipif(
not (CAMPAIGNS_DIR / CAMPAIGN_ID).exists(),
not (CAMPAIGNS_DIR / CAMPAIGN_ID / "datasets" / "Naccarato2019").exists(),
reason=f"Campaign directory does not exist for campaign {CAMPAIGN_ID}",
)
def test_naccarato():
def test_naccarato(trial_dataset):
from re2fractive.datasets import NaccaratoDataset

assert NaccaratoDataset.id == "Naccarato2019"
Expand Down Expand Up @@ -106,8 +106,8 @@ def test_naccarato():


@pytest.mark.skipif(
not (CAMPAIGNS_DIR / CAMPAIGN_ID).exists(),
reason="Campaign directory does not exist for campaign {CAMPAIGN_ID}",
not (CAMPAIGNS_DIR / CAMPAIGN_ID / "datasets" / "MP2023").exists(),
reason=f"Campaign directory does not exist for campaign {CAMPAIGN_ID}",
)
def test_mp2023():
from re2fractive.datasets import MP2023Dataset
Expand Down Expand Up @@ -185,8 +185,8 @@ def test_mp2023():


@pytest.mark.skipif(
not (CAMPAIGNS_DIR / CAMPAIGN_ID).exists(),
reason="Campaign directory does not exist for campaign {CAMPAIGN_ID}",
not (CAMPAIGNS_DIR / CAMPAIGN_ID / "datasets" / "Alexandria2024").exists(),
reason=f"Campaign directory does not exist for campaign {CAMPAIGN_ID}",
)
def test_alexandria():
from re2fractive.datasets import Alexandria2024Dataset
Expand Down Expand Up @@ -224,8 +224,8 @@ def test_alexandria():


@pytest.mark.skipif(
not (CAMPAIGNS_DIR / CAMPAIGN_ID).exists(),
reason="Campaign directory does not exist for campaign {CAMPAIGN_ID}",
not (CAMPAIGNS_DIR / CAMPAIGN_ID / "datasets" / "GNome2024").exists(),
reason=f"Campaign directory does not exist for campaign {CAMPAIGN_ID}",
)
def test_gnome():
from re2fractive.datasets import GNome2024Dataset
Expand Down

0 comments on commit 97c131e

Please sign in to comment.