|
13 | 13 | # limitations under the License.
|
14 | 14 | import os
|
15 | 15 | import unittest
|
| 16 | +from unittest.mock import patch, ANY |
16 | 17 | from click.testing import CliRunner
|
17 |
| -from library_generation.cli.entry_point import generate, validate_generation_config |
| 18 | +from library_generation.cli.entry_point import ( |
| 19 | + generate, |
| 20 | + validate_generation_config, |
| 21 | + __generate_repo_and_pr_description_impl as generate_impl, |
| 22 | +) |
| 23 | +from library_generation.model.generation_config import from_yaml |
18 | 24 |
|
19 | 25 | script_dir = os.path.dirname(os.path.realpath(__file__))
|
20 | 26 | test_resource_dir = os.path.join(script_dir, "..", "resources", "test-config")
|
@@ -78,3 +84,57 @@ def test_validate_generation_config_with_duplicate_library_name_raise_file_excep
|
78 | 84 | result.output,
|
79 | 85 | "have the same library name",
|
80 | 86 | )
|
| 87 | + |
| 88 | + @patch("library_generation.cli.entry_point.generate_from_yaml") |
| 89 | + @patch("library_generation.cli.entry_point.generate_pr_descriptions") |
| 90 | + def test_generate_non_monorepo_without_changes_triggers_full_generation( |
| 91 | + self, |
| 92 | + generate_pr_descriptions, |
| 93 | + generate_from_yaml, |
| 94 | + ): |
| 95 | + """ |
| 96 | + this tests confirms the behavior of generation of non monorepos |
| 97 | + (HW libraries). generate() should call generate_from_yaml() |
| 98 | + with target_library_names=None in order to trigger the full generation |
| 99 | + """ |
| 100 | + config_path = f"{test_resource_dir}/generation_config.yaml" |
| 101 | + self.assertFalse(from_yaml(config_path).is_monorepo()) |
| 102 | + # we call the implementation method directly since click |
| 103 | + # does special handling when a method is annotated with @main.command() |
| 104 | + generate_impl( |
| 105 | + baseline_generation_config_path=config_path, |
| 106 | + current_generation_config_path=config_path, |
| 107 | + repository_path=".", |
| 108 | + ) |
| 109 | + generate_from_yaml.assert_called_with( |
| 110 | + config=ANY, repository_path=ANY, target_library_names=None |
| 111 | + ) |
| 112 | + |
| 113 | + @patch("library_generation.cli.entry_point.generate_from_yaml") |
| 114 | + @patch("library_generation.cli.entry_point.generate_pr_descriptions") |
| 115 | + def test_generate_non_monorepo_with_changes_triggers_full_generation( |
| 116 | + self, |
| 117 | + generate_pr_descriptions, |
| 118 | + generate_from_yaml, |
| 119 | + ): |
| 120 | + """ |
| 121 | + this tests confirms the behavior of generation of non monorepos |
| 122 | + (HW libraries). generate() should call generate_from_yaml() |
| 123 | + with target_library_names=None in order to trigger the full generation |
| 124 | + """ |
| 125 | + baseline_config_path = f"{test_resource_dir}/generation_config.yaml" |
| 126 | + current_config_path = ( |
| 127 | + f"{test_resource_dir}/generation_config_library_modified.yaml" |
| 128 | + ) |
| 129 | + self.assertFalse(from_yaml(current_config_path).is_monorepo()) |
| 130 | + self.assertFalse(from_yaml(baseline_config_path).is_monorepo()) |
| 131 | + # we call the implementation method directly since click |
| 132 | + # does special handling when a method is annotated with @main.command() |
| 133 | + generate_impl( |
| 134 | + baseline_generation_config_path=baseline_config_path, |
| 135 | + current_generation_config_path=current_config_path, |
| 136 | + repository_path=".", |
| 137 | + ) |
| 138 | + generate_from_yaml.assert_called_with( |
| 139 | + config=ANY, repository_path=ANY, target_library_names=None |
| 140 | + ) |
0 commit comments