Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 23-e4edm-results-in-e…
Browse files Browse the repository at this point in the history
…rror-thrown
  • Loading branch information
ntlhui committed Mar 26, 2023
2 parents 09e585f + ffb5b19 commit f55af76
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
12 changes: 8 additions & 4 deletions e4e_data_management/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def initialize_dataset(self, date: dt.date, project: str, location: str, directo
raise RuntimeError('Dataset with that name already exists!')

self.active_dataset = Dataset(
root=dataset_path.absolute(),
root=dataset_path.resolve(),
day_0=date
)
self.active_dataset.create()
Expand Down Expand Up @@ -127,7 +127,7 @@ def status(self) -> str:
output = ''
if self.active_dataset:
name = self.active_dataset.name
path = self.active_dataset.root.absolute().as_posix()
path = self.active_dataset.root.resolve().as_posix()
output += f'Dataset {name} at {path} activated'
else:
output += 'No dataset active'
Expand All @@ -136,7 +136,7 @@ def status(self) -> str:
output += '\n'
if self.active_mission:
name = self.active_mission.name
path = self.active_mission.path.absolute().as_posix()
path = self.active_mission.path.resolve().as_posix()
output += f'Mission {name} at {path} activated'
else:
output += 'No mission active'
Expand All @@ -147,9 +147,13 @@ def status(self) -> str:
output += f'{len(self.active_mission.staged_files)} staged files:\n\t'
staged_files = ((f"{file.origin_path.as_posix()} -> "
f"{file.target_path.relative_to(self.active_mission.path).as_posix()}")
for file in self.active_mission.staged_files)
for file in sorted(self.active_mission.staged_files,
key=lambda x: x.target_path.name))

output += '\n\t'.join(staged_files)
if len(self.active_dataset.staged_files) > 0:
output += f'{len(self.active_dataset.staged_files)} staged dataset files:\n\t'
output += '\n\t'.join(file.as_posix() for file in self.active_dataset.staged_files)
return output

def activate(self,
Expand Down
10 changes: 5 additions & 5 deletions e4e_data_management/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, path: Path, root: Optional[Path] = None):
self.path = path
if root is None:
root = path.parent
self.__root = root
self.__root = root.resolve()

def validate(self,
manifest: Dict[str, Dict[str, Union[str, int]]],
Expand Down Expand Up @@ -176,7 +176,7 @@ class Mission:
"""
__MANIFEST_NAME = 'manifest.json'
def __init__(self, path: Path, mission_metadata: Metadata) -> None:
self.path = path
self.path = path.resolve()
self.metadata = mission_metadata
self.committed_files: List[Path] = []
self.staged_files: Set[StagedFile] = set()
Expand Down Expand Up @@ -242,7 +242,7 @@ def stage(self, paths: Iterable[Path], destination: Optional[Path] = None):
StagedFile(
origin_path=path.resolve(),
target_path=dst.joinpath(path.name).resolve(),
hash=Manifest.compute_file_hash(path.absolute())
hash=Manifest.compute_file_hash(path.resolve())
)
)
elif path.is_dir():
Expand Down Expand Up @@ -296,7 +296,7 @@ class Dataset:
VERSION = 1

def __init__(self, root: Path, day_0: dt.date):
self.root = root
self.root = root.resolve()
self.day_0: dt.date = day_0
self.last_country: Optional[str] = None
self.last_region: Optional[str] = None
Expand Down Expand Up @@ -481,7 +481,7 @@ def commit(self) -> List[Path]:
new_files: List[Path] = []
for file in added_files:
src = file
dest = self.root.joinpath(file.relative_to(root)).absolute()
dest = self.root.joinpath(file.relative_to(root)).resolve()
dest.parent.mkdir(parents=True, exist_ok=True)
copy2(src=src, dst=dest)
new_files.append(dest)
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create_test_bare_app() -> MockAppFixture:
"""
with TemporaryDirectory() as temp_dir:
root_dir = Path(temp_dir)
root_dir = Path(temp_dir).resolve()
DataManager.config_dir = root_dir
app = DataManager(
app_config_dir=root_dir
Expand Down Expand Up @@ -62,7 +62,7 @@ def create_test_data() -> DataFixture:
"""
random.seed(0)
with TemporaryDirectory() as path:
data_dir = Path(path)
data_dir = Path(path).resolve()
for file_idx in range(N_FILES):
with open(data_dir.joinpath(f'{file_idx:04d}.bin'), 'wb') as handle:
# Python 3.8 doesn't have random.randbytes, so this is the bypass
Expand All @@ -81,7 +81,7 @@ def create_test_readme() -> Path:
Path: README.md
"""
with TemporaryDirectory() as path:
readme_path = Path(path).joinpath('readme.md')
readme_path = Path(path).joinpath('readme.md').resolve()
with open(readme_path, 'w', encoding='ascii') as handle:
handle.write('readme\n')
yield readme_path
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_add_files(single_mission: Tuple[Mock, DataManager, Path],
data_dir, _, _ = test_data

bin_files = list(data_dir.rglob('*.bin'))[:2]
args = split(f'e4edm add {bin_files[0].as_posix()} {bin_files[1].as_posix()}')
args = split(f'e4edm add "{bin_files[0].as_posix()}" "{bin_files[1].as_posix()}"')
with patch('sys.argv', args):
main()
mock.add.assert_called_once_with(paths=bin_files, readme=False, destination=None)
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_add_files_end(single_mission: Tuple[Mock, DataManager, Path],

start_time = dt.datetime.now()

args = split(f'e4edm add {data_dir.as_posix()}/*.bin '
args = split(f'e4edm add "{data_dir.as_posix()}/*.bin" '
f'--end {start_time.isoformat()}')
with patch('sys.argv', args):
main()
Expand All @@ -158,7 +158,7 @@ def test_add_glob(single_mission: Tuple[Mock, DataManager, Path],
mock, _, _ = single_mission
data_dir, _, _ = test_data

args = split(f'e4edm add {data_dir.as_posix()}/*.bin')
args = split(f'e4edm add "{data_dir.as_posix()}/*.bin"')
with patch('sys.argv', args):
main()
mock.add.assert_called_once_with(paths=list(data_dir.glob('*.bin')),
Expand All @@ -179,7 +179,7 @@ def test_add_multifile(single_mission: Tuple[Mock, DataManager, Path]):
file2 = root_dir.joinpath('test2.txt')
file2.touch()

args = split(f'e4edm add {file1.as_posix()} {file2.as_posix()}')
args = split(f'e4edm add "{file1.as_posix()}" "{file2.as_posix()}"')
with patch('sys.argv', args):
main()
mock.add.assert_called_once_with(paths=[file1, file2], readme=False, destination=None)
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_add_readme(single_mission: Tuple[Mock, DataManager, Path], test_readme:
"""
mock, _, _ = single_mission

args = split(f'e4edm add --readme {test_readme.as_posix()}')
args = split(f'e4edm add --readme "{test_readme.as_posix()}"')
with patch('sys.argv', args):
main()
mock.add.assert_called_once_with(paths=[test_readme], readme=True, destination=None)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''Tests for the status output
'''
import re
from pathlib import Path
from typing import Tuple
from unittest.mock import Mock

from e4e_data_management.core import DataManager


def test_readme_staging(single_mission: Tuple[Mock, DataManager, Path], test_readme: Path):
"""Tests that a staged README file is displayed in the status output
Args:
single_mission (Tuple[Mock, DataManager, Path]): Single mission test app
test_readme (Path): Test Readme file
"""
_, app, _ = single_mission

app.add([test_readme], readme=True)

status_output = app.status()

regex = r"readme\.md|readme\.docx"

matches = re.findall(regex, status_output, re.MULTILINE | re.IGNORECASE)

assert len(matches) != 0
4 changes: 2 additions & 2 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_validation():
NotImplementedError: Unsupported platform
"""
with TemporaryDirectory() as temp_dir:
run_dir = Path(temp_dir)
run_dir = Path(temp_dir).resolve()
for file_idx in range(N_FILES):
with open(run_dir.joinpath(f'{file_idx:04d}.bin'), 'w', encoding='ascii') as handle:
for _ in range(N_BYTES):
Expand All @@ -37,7 +37,7 @@ def test_validation():
# Note: certUtil actually throws an error on empty string! So we need to bypass...
if file.lstat().st_size != 0:
output = subprocess.check_output(
['certUtil', '-hashfile', file.absolute().as_posix(), 'SHA256'])
['certUtil', '-hashfile', file.resolve().as_posix(), 'SHA256'])
cksum = output.decode().splitlines()[1].strip()
else:
cksum = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
Expand Down

0 comments on commit f55af76

Please sign in to comment.