Skip to content

Commit

Permalink
Added completed dataset fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ntlhui committed Feb 12, 2023
1 parent ef8cfe4 commit cdc5e40
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'''Data Generator for tests
'''
import datetime as dt
import json
import random
from pathlib import Path
from tempfile import TemporaryDirectory
from e4e_data_management.validator import Dataset

import pytest

from e4e_data_management.validator import Dataset

N_LINES = 1024
N_DAYS = 3
RUNS_PER_DAY = 4
Expand Down Expand Up @@ -73,23 +77,109 @@ def create_expedition() -> Path:

@pytest.fixture(name='single_validated_run')
def create_validated_run(single_run: Path) -> Path:
"""Validates the single run
Args:
single_run (Path): Run dataset
Returns:
Path: Run dataset
Yields:
Iterator[Path]: Validated dataset
"""
dataset = Dataset(single_run)
dataset.generate_manifest()
current_tz = dt.datetime.now().astimezone().tzinfo
atime = dt.datetime.fromtimestamp(
single_run.joinpath('data.txt').lstat().st_atime,
tz=current_tz
)
with open(single_run.joinpath('metadata.json'), 'w', encoding='ascii') as handle:
metadata = {
'timestamp': atime.isoformat(),
'device': "data_generator.ipynb",
'notes': "Randomly generated data",
'properties': {},
'country': 'USA',
'region': 'California',
'site': 'San Diego',
'mission': single_run.name
}
json.dump(metadata, handle, indent=4)
yield single_run

@pytest.fixture(name='single_validated_day')
def create_validated_day(single_day: Path) -> Path:
"""validates a single day
Args:
single_day (Path): Single day dataset
Returns:
Path: Validated dataset
Yields:
Iterator[Path]: Validated dataset
"""
run_folders = single_day.glob('RUN*')
current_tz = dt.datetime.now().astimezone().tzinfo
for run in run_folders:
dataset = Dataset(run)
dataset.generate_manifest()
atime = dt.datetime.fromtimestamp(
run.joinpath('data.txt').lstat().st_atime,
tz=current_tz
)
with open(run.joinpath('metadata.json'), 'w', encoding='ascii') as handle:
metadata = {
'timestamp': atime.isoformat(),
'device': "data_generator.ipynb",
'notes': "Randomly generated data",
'properties': {},
'country': 'USA',
'region': 'California',
'site': 'San Diego',
'mission': run.name
}
json.dump(metadata, handle, indent=4)
yield single_day

@pytest.fixture(name='single_validated_expedition')
def create_validated_expedition(single_expedition: Path) -> Path:
"""Completes an expedition dataset
Args:
single_expedition (Path): Expedition dataset
Returns:
Path: Completed dataset
Yields:
Iterator[Path]: Completed dataset
"""
day_folders = single_expedition.glob('ED*')
current_tz = dt.datetime.now().astimezone().tzinfo
for day in day_folders:
run_folders = day.glob('RUN*')
for run in run_folders:
Dataset(run).generate_manifest()
atime = dt.datetime.fromtimestamp(
run.joinpath('data.txt').lstat().st_atime,
tz=current_tz
)
with open(run.joinpath('metadata.json'), 'w', encoding='ascii') as handle:
metadata = {
'timestamp': atime.isoformat(),
'device': "data_generator.ipynb",
'notes': "Randomly generated data",
'properties': {},
'country': 'USA',
'region': 'California',
'site': 'San Diego',
'mission': run.name
}
json.dump(metadata, handle, indent=4)
single_expedition.joinpath('readme.md').touch()
Dataset(single_expedition).generate_manifest()
yield single_expedition

0 comments on commit cdc5e40

Please sign in to comment.