From 61460798f3f707e1eaf157660ec761537d4a20a8 Mon Sep 17 00:00:00 2001 From: rizac Date: Tue, 11 Jul 2023 14:11:17 +0200 Subject: [PATCH] fixing no time bounds from command line --- mecompute/run.py | 14 +++++++++----- test/test_workflow.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/mecompute/run.py b/mecompute/run.py index 1afe945..e7ebbc3 100644 --- a/mecompute/run.py +++ b/mecompute/run.py @@ -135,11 +135,15 @@ def cli(d_config, start, end, time_window, force_overwrite, p_config, h_template process -s 2016-01-02 -t 2 OUT_DIR """ - start, end = _get_timebounds(start, end, time_window) - dest_dir = output_dir.replace("%S%", start).replace("%E%", end) - ret = process(d_config, start, end, dest_dir, - force_overwrite=force_overwrite, p_config=p_config, - html_template=h_template) + if start is None and end is None and time_window is None: + print('No time bounds specified. Please provide -s, -e or -t', file=sys.stderr) + ret = False + else: + start, end = _get_timebounds(start, end, time_window) + dest_dir = output_dir.replace("%S%", start).replace("%E%", end) + ret = process(d_config, start, end, dest_dir, + force_overwrite=force_overwrite, p_config=p_config, + html_template=h_template) if ret: sys.exit(0) sys.exit(1) diff --git a/test/test_workflow.py b/test/test_workflow.py index cec2dd6..f216033 100644 --- a/test/test_workflow.py +++ b/test/test_workflow.py @@ -34,6 +34,19 @@ def test_proc_ess_params(mock_process, capsys): timedelta(days=days) +@patch('mecompute.run.process') +def test_proc_no_time_bounds(mock_process, capsys): + runner = CliRunner() + now = datetime.utcnow().replace(microsecond=0,hour=0, minute=0, second=0) + days = 365 + result = runner.invoke(cli, ['-f', + '-d', TEST_DOWNLOAD_CONFIG_PATH, + TEST_TMP_ROOT_DIR]) + assert not mock_process.called + assert 'no time bounds specified' in result.output.lower() + assert result.exit_code != 0 + + @pytest.mark.parametrize('params', [ ['-s', '2022-05-20T09:00:00', '-e', '2022-05-20T13:00:00'], # process all db events ])