Skip to content

Commit

Permalink
Added tests for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ntlhui committed Mar 12, 2023
1 parent 1f2ec04 commit 9dbf3e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
23 changes: 19 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
MockAppFixture = namedtuple('MockAppFixture', ['mock', 'app', 'root'])
DataFixture = namedtuple('DataFixture', ['path', 'n_files', 'file_size'])

@pytest.fixture(name='test_app')
def create_test_app() -> MockAppFixture:

@pytest.fixture(name='test_bare_app')
def create_test_bare_app() -> MockAppFixture:
"""Creates a mock test app
Yields:
TestFixture: Mock, app, and root directory
Returns:
MockAppFixture: Mock app
"""
with TemporaryDirectory() as temp_dir:
root_dir = Path(temp_dir)
Expand All @@ -33,9 +35,22 @@ def create_test_app() -> MockAppFixture:

mock = Mock(app)
mock.load.return_value = mock
mock.dirs = app.dirs
mock.dataset_dir = app.dataset_dir
with patch('e4e_data_management.cli.DataManager', mock):
yield MockAppFixture(mock, app, root_dir)

@pytest.fixture(name='test_app')
def create_test_app(test_bare_app: Tuple[Mock, DataManager, Path]) -> MockAppFixture:
"""Creates a mock test app
Yields:
TestFixture: Mock, app, and root directory
"""
_, app, root_dir = test_bare_app
app.dataset_dir = root_dir
yield test_bare_app

N_FILES = 128
FILE_SIZE = 1024
@pytest.fixture(name='test_data')
Expand Down
15 changes: 11 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@
from typing import Tuple
from unittest.mock import Mock, patch

import appdirs
import pytest

from e4e_data_management.cli import main
from e4e_data_management.core import DataManager
from e4e_data_management.metadata import Metadata


def test_init_dataset(test_app: Tuple[Mock, DataManager, Path]):
def test_init_dataset(test_bare_app: Tuple[Mock, DataManager, Path]):
"""Tests initialize dataset
"""
mock, _, _ = test_app
mock, _, _ = test_bare_app
args = split('e4edm init_dataset --date 2023-03-02 --project "TEST" --location "San Diego"')
with patch('sys.argv', args):
main()
mock.initialize_dataset.assert_called_once_with(
date=dt.date(2023, 3, 2),
project='TEST',
location='San Diego',
directory=Path('.')
directory=Path(appdirs.user_data_dir(
appname='E4EDataManagement',
appauthor='Engineers for Exploration'
))
)

def test_init_dataset_today(test_app: Tuple[Mock, DataManager, Path]):
Expand All @@ -43,7 +47,10 @@ def test_init_dataset_today(test_app: Tuple[Mock, DataManager, Path]):
date=dt.date.today(),
project='TEST',
location='Location',
directory=Path('.')
directory=Path(appdirs.user_data_dir(
appname='E4EDataManagement',
appauthor='Engineers for Exploration'
))
)

def test_init_mission(test_app: Tuple[Mock, DataManager, Path]):
Expand Down

0 comments on commit 9dbf3e6

Please sign in to comment.