From d934d1f44f74911bd8372a1c851c848331c37940 Mon Sep 17 00:00:00 2001 From: "Kevin W. Beam" Date: Wed, 27 Nov 2024 14:34:35 -0700 Subject: [PATCH] Applies ruff (black) code formatting rules --- tests/test_cli.py | 108 +++++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 40 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 84f36ec..b22d1c7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,53 +14,64 @@ # parameters, correctly handle their return values, and handle any exceptions # they may throw. + @pytest.fixture def cli_runner(): return CliRunner() + def test_without_subcommand(cli_runner): result = cli_runner.invoke(cli) assert result.exit_code == 0 - assert 'Usage' in result.output - assert 'Commands' in result.output - for subcommand in ['info', 'init', 'process']: + assert "Usage" in result.output + assert "Commands" in result.output + for subcommand in ["info", "init", "process"]: assert subcommand in result.output + def test_help(cli_runner): - result = cli_runner.invoke(cli, ['--help']) + result = cli_runner.invoke(cli, ["--help"]) assert result.exit_code == 0 + def test_info_requires_config(cli_runner): - result = cli_runner.invoke(cli, ['info']) + result = cli_runner.invoke(cli, ["info"]) assert result.exit_code != 0 + def test_info_with_config(cli_runner): - result = cli_runner.invoke(cli, ['info', '--config', './example/modscg.ini']) + result = cli_runner.invoke(cli, ["info", "--config", "./example/modscg.ini"]) assert result.exit_code == 0 -@patch('nsidc.metgen.config.Config.show') + +@patch("nsidc.metgen.config.Config.show") def test_info_with_config_summarizes(mock, cli_runner): - result = cli_runner.invoke(cli, ['info', '--config', './example/modscg.ini']) + result = cli_runner.invoke(cli, ["info", "--config", "./example/modscg.ini"]) assert mock.called assert result.exit_code == 0 -@patch('nsidc.metgen.metgen.process') + +@patch("nsidc.metgen.metgen.process") def test_process_requires_config(mock, cli_runner): - result = cli_runner.invoke(cli, ['process']) + result = cli_runner.invoke(cli, ["process"]) assert not mock.called assert result.exit_code != 0 -@patch('nsidc.metgen.config.validate') -@patch('nsidc.metgen.metgen.process') + +@patch("nsidc.metgen.config.validate") +@patch("nsidc.metgen.metgen.process") def test_process_with_config_calls_process(mock_validate, mock_process, cli_runner): - cli_runner.invoke(cli, ['process', '--config', './example/modscg.ini']) + cli_runner.invoke(cli, ["process", "--config", "./example/modscg.ini"]) assert mock_process.called -@patch('nsidc.metgen.config.validate') -@patch('nsidc.metgen.metgen.process') + +@patch("nsidc.metgen.config.validate") +@patch("nsidc.metgen.metgen.process") def test_process_with_granule_limit(mock_validate, mock_process, cli_runner): number_files = 2 - result = cli_runner.invoke(cli, ['process', '-n', str(number_files), '--config', './example/modscg.ini']) + result = cli_runner.invoke( + cli, ["process", "-n", str(number_files), "--config", "./example/modscg.ini"] + ) assert mock_process.called args = mock_process.call_args.args @@ -69,53 +80,70 @@ def test_process_with_granule_limit(mock_validate, mock_process, cli_runner): assert configuration.number == number_files assert result.exit_code == 0 -@patch('nsidc.metgen.config.configuration') -@patch('nsidc.metgen.metgen.process') -@patch('nsidc.metgen.config.validate') -def test_process_with_no_write_cnm(mock_validate, process_mock, configuration_mock, cli_runner): - result = cli_runner.invoke(cli, ['process', '--config', './example/modscg.ini']) + +@patch("nsidc.metgen.config.configuration") +@patch("nsidc.metgen.metgen.process") +@patch("nsidc.metgen.config.validate") +def test_process_with_no_write_cnm( + mock_validate, process_mock, configuration_mock, cli_runner +): + result = cli_runner.invoke(cli, ["process", "--config", "./example/modscg.ini"]) assert configuration_mock.called args = configuration_mock.call_args.args overrides = args[1] - assert overrides['write_cnm_file'] is None + assert overrides["write_cnm_file"] is None assert result.exit_code == 0 -@patch('nsidc.metgen.config.configuration') -@patch('nsidc.metgen.metgen.process') -@patch('nsidc.metgen.config.validate') -def test_process_with_write_cnm(mock_validate, process_mock, configuration_mock, cli_runner): - result = cli_runner.invoke(cli, ['process', '-wc', '--config', './example/modscg.ini']) + +@patch("nsidc.metgen.config.configuration") +@patch("nsidc.metgen.metgen.process") +@patch("nsidc.metgen.config.validate") +def test_process_with_write_cnm( + mock_validate, process_mock, configuration_mock, cli_runner +): + result = cli_runner.invoke( + cli, ["process", "-wc", "--config", "./example/modscg.ini"] + ) assert configuration_mock.called args = configuration_mock.call_args.args overrides = args[1] - assert overrides['write_cnm_file'] + assert overrides["write_cnm_file"] assert result.exit_code == 0 -@patch('nsidc.metgen.config.configuration') -@patch('nsidc.metgen.metgen.process') -@patch('nsidc.metgen.config.validate') -def test_process_with_no_overwrite(mock_validate, process_mock, configuration_mock, cli_runner): - result = cli_runner.invoke(cli, ['process', '--config', './example/modscg.ini']) + +@patch("nsidc.metgen.config.configuration") +@patch("nsidc.metgen.metgen.process") +@patch("nsidc.metgen.config.validate") +def test_process_with_no_overwrite( + mock_validate, process_mock, configuration_mock, cli_runner +): + result = cli_runner.invoke(cli, ["process", "--config", "./example/modscg.ini"]) assert configuration_mock.called args = configuration_mock.call_args.args overrides = args[1] - assert overrides['overwrite_ummg'] is None + assert overrides["overwrite_ummg"] is None assert result.exit_code == 0 -@patch('nsidc.metgen.config.configuration') -@patch('nsidc.metgen.metgen.process') -@patch('nsidc.metgen.config.validate') -def test_process_with_overwrite(mock_validate, process_mock, configuration_mock, cli_runner): - result = cli_runner.invoke(cli, ['process', '-o', '--config', './example/modscg.ini']) + +@patch("nsidc.metgen.config.configuration") +@patch("nsidc.metgen.metgen.process") +@patch("nsidc.metgen.config.validate") +def test_process_with_overwrite( + mock_validate, process_mock, configuration_mock, cli_runner +): + result = cli_runner.invoke( + cli, ["process", "-o", "--config", "./example/modscg.ini"] + ) assert configuration_mock.called args = configuration_mock.call_args.args overrides = args[1] - assert overrides['overwrite_ummg'] + assert overrides["overwrite_ummg"] assert result.exit_code == 0 + # TODO: When process raises an exception, cli handles it and displays a message # and has non-zero exit code