diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..3014ff5 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,40 @@ +on: + push: + branches: [main] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: cache poetry install + uses: actions/cache@v4 + with: + path: ~/.local + key: poetry-1.8.3-0 + + - uses: snok/install-poetry@v1 + with: + version: 1.8.3 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: cache deps + id: cache-deps + uses: actions/cache@v4 + with: + path: .venv + key: pydeps-${{ hashFiles('**/poetry.lock') }} + + - run: poetry install --no-interaction --no-root + if: steps.cache-deps.outputs.cache-hit != 'true' + + - run: poetry install --no-interaction + + - run: poetry run pytest diff --git a/tests/test_cli.py b/tests/test_cli.py index 0a52212..4f6dce0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + from click.testing import CliRunner import pytest @@ -34,16 +36,13 @@ def test_info_with_config_summarizes(cli_runner): for key in ['auth_id', 'data_dir', 'environment', 'local_output_dir', 'kinesis_arn', 'provider', 'ummg_dir', 'version']: assert key in result.output -def test_process_requires_config(cli_runner): +@patch('nsidc.metgen.metgen.process') +def test_process_requires_config_does_not_call_process(mock, cli_runner): result = cli_runner.invoke(cli, ['process']) + assert not mock.called assert result.exit_code != 0 -def test_process_with_config(cli_runner): +@patch('nsidc.metgen.metgen.process') +def test_process_with_config_calls_process(mock, cli_runner): result = cli_runner.invoke(cli, ['process', '--config', './example/modscg.ini']) - assert result.exit_code == 0 - -def test_process_output(cli_runner): - result = cli_runner.invoke(cli, ['process', '--config', './example/modscg.ini']) - assert result.exit_code == 0 - assert 'Saved CNM message' in result.output - assert 'Processed granules' in result.output + assert mock.called