Skip to content

Commit

Permalink
fixup! Refactor canned file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nadove-ucsc committed Apr 13, 2024
1 parent 56089a7 commit 309aa17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions test/indexer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
abstractmethod,
)
import json
import os
from pathlib import (
Path,
)
from typing import (
Generic,
Literal,
Expand Down Expand Up @@ -91,8 +93,8 @@ class CannedFileTestCase(AzulUnitTestCase):
"""

@classmethod
def _data_path(cls, module: Literal['service', 'indexer'], path: str) -> str | bytes:
return os.path.join(config.project_root, 'test', module, 'data', path)
def _data_path(cls, module: Literal['service', 'indexer']) -> Path:
return Path(config.project_root) / 'test' / module / 'data'

@classmethod
def _load_canned_file(cls,
Expand All @@ -118,7 +120,7 @@ def _load_canned_file_version(cls,
) -> Union[MutableJSONs, MutableJSON]:
suffix = '' if version is None else '.' + version
file_name = f'{uuid}{suffix}.{extension}.json'
with open(cls._data_path('indexer', file_name), 'r') as infile:
with open(cls._data_path('indexer') / file_name, 'r') as infile:
return json.load(infile)


Expand Down
5 changes: 2 additions & 3 deletions test/pfb_test_case.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import os

import fastavro

Expand All @@ -19,8 +18,8 @@ def _assert_pfb_schema(self, schema):
def to_json(records):
return json.dumps(records, indent=4, sort_keys=True)

results_file = self._data_path('service', 'pfb_manifest.schema.json')
if os.path.exists(results_file):
results_file = self._data_path('service') / 'pfb_manifest.schema.json'
if results_file.exists():
with open(results_file, 'r') as f:
expected_records = json.load(f)
self.assertEqual(expected_records, json.loads(to_json(schema)))
Expand Down

0 comments on commit 309aa17

Please sign in to comment.