Skip to content

Commit

Permalink
Fixed naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ntlhui committed Feb 11, 2023
1 parent 153cc14 commit 1194483
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'''Metadata
'''
from __future__ import annotations

import datetime as dt
Expand All @@ -10,13 +12,15 @@


@dataclass
class Manifest:
"""Dataset Manifest
class Metadata:
"""Dataset Metadata
Raises:
RuntimeError: No timezone specified
"""
#pylint: disable=too-many-instance-attributes

timestamp: dt.datetime
device: str
country: str
Expand All @@ -31,10 +35,10 @@ def __post_init__(self):
raise RuntimeError('No timezone info specified!')

def write(self, directory: Path):
"""Writes the manifest file to the specified directory
"""Writes the metadata file to the specified directory
Args:
directory (Path): Directory in which to write the manifest file
directory (Path): Directory in which to write the metadata file
Raises:
RuntimeError: No timezone specified
Expand All @@ -55,14 +59,14 @@ def write(self, directory: Path):
json.dump(metadata, handle, indent=4)

@classmethod
def load(cls, directory: Path) -> Manifest:
"""Loads a manifest file from disk
def load(cls, directory: Path) -> Metadata:
"""Loads a metadata file from disk
Args:
directory (Path): Directory from which to load the manifest file
directory (Path): Directory from which to load the metadata file
Returns:
Manifest: Loaded manifest file
Metadata: Loaded metadata file
"""
metadata_schema = schema.Schema({
'timestamp': str,
Expand All @@ -77,7 +81,7 @@ def load(cls, directory: Path) -> Manifest:
with open(directory.joinpath('metadata.json'), 'r', encoding='ascii') as handle:
data = json.load(handle)
metadata = metadata_schema.validate(data)
return Manifest(
return Metadata(
timestamp=dt.datetime.fromisoformat(metadata['timestamp']),
device=metadata['device'],
country=metadata['country'],
Expand Down
8 changes: 4 additions & 4 deletions tests/test_manifest.py → tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import pytest

from e4e_data_management.manifest import Manifest
from e4e_data_management.metadata import Metadata


def test_manifest_serialization():
"""Testing manifest serialization
"""
manifest = Manifest(
manifest = Metadata(
timestamp=dt.datetime.now().astimezone(),
device='test',
country='USA',
Expand All @@ -33,15 +33,15 @@ def test_manifest_serialization():
root = Path(tmpdir)
manifest.write(directory=root)

new_manifest = Manifest.load(directory=root)
new_manifest = Metadata.load(directory=root)

assert manifest == new_manifest
assert new_manifest.timestamp.tzinfo is not None

def test_no_tzinfo():
"""Testing manifest serialization with no timezone
"""
manifest = Manifest(
manifest = Metadata(
timestamp=dt.datetime.now(),
device='test',
country='USA',
Expand Down

0 comments on commit 1194483

Please sign in to comment.