diff --git a/e4e_data_management/cli.py b/e4e_data_management/cli.py index 295032a..8b670ac 100644 --- a/e4e_data_management/cli.py +++ b/e4e_data_management/cli.py @@ -176,13 +176,12 @@ def add_files(args: List[str]): parser.add_argument( 'paths', nargs='+', - type=Path, - required=True + type=Path ) args = parser.parse_args(args=args) paths: List[Path] = args.paths - app.add(paths) + app.add(paths=paths) def main(): """Main function diff --git a/tests/conftest.py b/tests/conftest.py index 8cebb7f..51e6642 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ '''Common Test Fixtures ''' +import random from collections import namedtuple from pathlib import Path from tempfile import TemporaryDirectory @@ -11,6 +12,7 @@ AppFixture = namedtuple('AppFixture', ['app', 'root']) MockAppFixture = namedtuple('MockAppFixture', ['mock', 'app', 'root']) +DataFixture = namedtuple('DataFixture', ['path', 'n_files', 'file_size']) @pytest.fixture(name='test_app') def create_test_app() -> AppFixture: @@ -44,3 +46,21 @@ def create_mock_test_app() -> MockAppFixture: mock.load.return_value = mock with patch('e4e_data_management.cli.DataManager', mock): yield MockAppFixture(mock, app, root_dir) + +N_FILES = 128 +FILE_SIZE = 1024 +@pytest.fixture(name='test_data') +def create_test_data() -> DataFixture: + """Creates test data + + Returns: + DataFixture: Data Fixture + """ + random.seed(0) + with TemporaryDirectory() as path: + data_dir = Path(path) + for file_idx in range(N_FILES): + with open(data_dir.joinpath(f'{file_idx:04d}.bin'), 'wb') as handle: + data = random.randbytes(FILE_SIZE) + handle.write(data) + yield DataFixture(data_dir, N_FILES, FILE_SIZE) diff --git a/tests/test_cli.py b/tests/test_cli.py index aed5e4d..307b46d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -41,8 +41,7 @@ def test_init_mission(test_mock_app: Tuple[Mock, DataManager, Path]): args = split('e4edm init_mission --timestamp 2023-03-02T15:06-08:00 --device Device1 ' '--country USA --region California --site SD --name RUN001') - with patch('sys.argv', args),\ - patch('e4e_data_management.cli.DataManager', mock): + with patch('sys.argv', args): main() mock.initialize_mission.assert_called_once_with( metadata=Metadata( @@ -56,3 +55,36 @@ def test_init_mission(test_mock_app: Tuple[Mock, DataManager, Path]): notes=None ) ) + +def test_add_files(test_mock_app: Tuple[Mock, DataManager, Path], test_data: Tuple[Path, int, int]): + """Tests adding files + + Args: + test_mock_app (Tuple[Mock, DataManager, Path]): Mock App + test_data (Tuple[Path, int, int]): Test Data + """ + mock, app, root_dir = test_mock_app + data_dir, _, _ = test_data + + app.initialize_dataset( + date=dt.date(2023, 3, 2), + project='Test', + location='San Diego', + directory=root_dir + ) + app.initialize_mission( + metadata=Metadata( + timestamp=dt.datetime.fromisoformat('2023-03-02T18:35-08:00'), + country='USA', + region='California', + device='Device1', + site='SD', + mission='TAF001' + ) + ) + + bin_files = list(data_dir.rglob('*.bin'))[:2] + 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)