|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import os |
| 15 | +from click.testing import CliRunner |
| 16 | +import unittest |
| 17 | + |
| 18 | +from common.cli.get_changed_libraries import create |
| 19 | + |
| 20 | +script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 21 | +test_resource_dir = os.path.join(script_dir, "..", "resources", "cli") |
| 22 | + |
| 23 | + |
| 24 | +class GetChangedLibrariesTest(unittest.TestCase): |
| 25 | + def test_entry_point_without_baseline_config_raise_system_exception(self): |
| 26 | + os.chdir(script_dir) |
| 27 | + runner = CliRunner() |
| 28 | + # noinspection PyTypeChecker |
| 29 | + result = runner.invoke(create) |
| 30 | + self.assertEqual(2, result.exit_code) |
| 31 | + self.assertEqual(SystemExit, result.exc_info[0]) |
| 32 | + |
| 33 | + def test_entry_point_without_current_config_raise_system_exception(self): |
| 34 | + os.chdir(script_dir) |
| 35 | + runner = CliRunner() |
| 36 | + # noinspection PyTypeChecker |
| 37 | + result = runner.invoke( |
| 38 | + create, ["--baseline-generation-config-path=/invalid/path/file"] |
| 39 | + ) |
| 40 | + self.assertEqual(2, result.exit_code) |
| 41 | + self.assertEqual(SystemExit, result.exc_info[0]) |
| 42 | + |
| 43 | + def test_entry_point_with_invalid_baseline_config_raise_file_exception(self): |
| 44 | + os.chdir(script_dir) |
| 45 | + runner = CliRunner() |
| 46 | + # noinspection PyTypeChecker |
| 47 | + result = runner.invoke( |
| 48 | + create, |
| 49 | + [ |
| 50 | + "--baseline-generation-config-path=/invalid/path/file", |
| 51 | + "--current-generation-config-path=/invalid/path/file", |
| 52 | + ], |
| 53 | + ) |
| 54 | + self.assertEqual(1, result.exit_code) |
| 55 | + self.assertEqual(FileNotFoundError, result.exc_info[0]) |
| 56 | + self.assertRegex(result.exception.args[0], "baseline-generation-config-path") |
| 57 | + |
| 58 | + def test_entry_point_with_invalid_current_config_raise_file_exception(self): |
| 59 | + os.chdir(script_dir) |
| 60 | + runner = CliRunner() |
| 61 | + # noinspection PyTypeChecker |
| 62 | + result = runner.invoke( |
| 63 | + create, |
| 64 | + [ |
| 65 | + f"--baseline-generation-config-path={test_resource_dir}/empty_config.yaml", |
| 66 | + "--current-generation-config-path=/invalid/path/file", |
| 67 | + ], |
| 68 | + ) |
| 69 | + self.assertEqual(1, result.exit_code) |
| 70 | + self.assertEqual(FileNotFoundError, result.exc_info[0]) |
| 71 | + self.assertRegex(result.exception.args[0], "current-generation-config-path") |
0 commit comments