Skip to content

Commit 3ab2087

Browse files
committed
formatted
1 parent c56202b commit 3ab2087

File tree

2 files changed

+56
-23
lines changed

2 files changed

+56
-23
lines changed

hermetic_build/library_generation/owlbot/src/fix_poms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,12 @@ def main(versions_file, monorepo):
619619
if dependency_module not in versions_txt_modules:
620620
# These should already be in existing_modules if loaded from versions.txt
621621
if dependency_module in existing_modules:
622-
versions_txt_modules[dependency_module] = existing_modules[dependency_module]
622+
versions_txt_modules[dependency_module] = existing_modules[
623+
dependency_module
624+
]
623625
# This else block should ideally not be reached in the monorepo case.
624626
else:
625-
versions_txt_modules[dependency_module] = module.Module(
627+
versions_txt_modules[dependency_module] = module.Module(
626628
group_id=__proto_group_id(group_id),
627629
artifact_id=dependency_module,
628630
version=main_module.version,

hermetic_build/library_generation/tests/owlbot/fix_poms_unit_tests.py

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def setUp(self):
3232
def tearDown(self):
3333
os.chdir(self.start_dir)
3434

35-
3635
def test_update_poms_group_id_does_not_start_with_google_correctly(self):
3736
ad_manager_resource = os.path.join(resources_dir, "java-admanager")
3837
versions_file = os.path.join(ad_manager_resource, "versions.txt")
@@ -46,7 +45,6 @@ def test_update_poms_group_id_does_not_start_with_google_correctly(self):
4645
for sub_dir in sub_dirs:
4746
self.__remove_file_in_subdir(ad_manager_resource, sub_dir)
4847

49-
5048
def test_add_new_library(self):
5149
# Setup test environment in a structure similar to a real repo
5250
repo_dir = os.path.join(self.temp_dir, "google-cloud-java")
@@ -56,13 +54,17 @@ def test_add_new_library(self):
5654
new_library_path = os.path.join(repo_dir, new_library_dir_name)
5755

5856
# Copy test resources to the temporary directory
59-
shutil.copytree(os.path.join(source_resource_dir, "java-newapi"), new_library_path)
57+
shutil.copytree(
58+
os.path.join(source_resource_dir, "java-newapi"), new_library_path
59+
)
6060

6161
# Modify the .repo-metadata.json in the temporary new library folder
6262
repo_metadata_path = os.path.join(new_library_path, ".repo-metadata.json")
6363
with open(repo_metadata_path, "r") as f:
6464
repo_metadata_content = f.read()
65-
repo_metadata_content = repo_metadata_content.replace("google-cloud-newfolder", "google-cloud-newapi")
65+
repo_metadata_content = repo_metadata_content.replace(
66+
"google-cloud-newfolder", "google-cloud-newapi"
67+
)
6668
with open(repo_metadata_path, "w") as f:
6769
f.write(repo_metadata_content)
6870

@@ -78,7 +80,11 @@ def test_add_new_library(self):
7880

7981
# Get initial state of versions.txt (excluding comments and empty lines)
8082
with open(dest_versions_file, "r") as f:
81-
initial_active_lines = [line.strip() for line in f if line.strip() and not line.strip().startswith("#")]
83+
initial_active_lines = [
84+
line.strip()
85+
for line in f
86+
if line.strip() and not line.strip().startswith("#")
87+
]
8288

8389
# Execute the main function from fix_poms.py
8490
main(dest_versions_file, "true")
@@ -87,20 +93,36 @@ def test_add_new_library(self):
8793
with open(dest_versions_file, "r") as f:
8894
updated_versions_content = f.readlines()
8995

90-
updated_active_lines = [line.strip() for line in updated_versions_content if line.strip() and not line.strip().startswith("#")]
96+
updated_active_lines = [
97+
line.strip()
98+
for line in updated_versions_content
99+
if line.strip() and not line.strip().startswith("#")
100+
]
91101

92-
self.assertEqual(len(initial_active_lines) + 1, len(updated_active_lines),
93-
"A single line should have been added to versions.txt")
102+
self.assertEqual(
103+
len(initial_active_lines) + 1,
104+
len(updated_active_lines),
105+
"A single line should have been added to versions.txt",
106+
)
94107

95108
expected_new_line = "newapi:0.0.0:0.0.1-SNAPSHOT"
96-
self.assertTrue(any(expected_new_line in line for line in updated_active_lines),
97-
f"The new line '{expected_new_line}' was not found in versions.txt")
109+
self.assertTrue(
110+
any(expected_new_line in line for line in updated_active_lines),
111+
f"The new line '{expected_new_line}' was not found in versions.txt",
112+
)
98113

99-
filtered_updated_lines = [line for line in updated_active_lines if expected_new_line not in line]
100-
self.assertCountEqual(initial_active_lines, filtered_updated_lines,
101-
"Existing lines in versions.txt should be unaffected.")
102-
self.assertFalse(any("google-cloud-newapi" in line for line in updated_versions_content),
103-
"The artifactId 'google-cloud-newapi' should not be in versions.txt")
114+
filtered_updated_lines = [
115+
line for line in updated_active_lines if expected_new_line not in line
116+
]
117+
self.assertCountEqual(
118+
initial_active_lines,
119+
filtered_updated_lines,
120+
"Existing lines in versions.txt should be unaffected.",
121+
)
122+
self.assertFalse(
123+
any("google-cloud-newapi" in line for line in updated_versions_content),
124+
"The artifactId 'google-cloud-newapi' should not be in versions.txt",
125+
)
104126

105127
# --- Verify generated pom.xml files ---
106128
expected_poms = [
@@ -112,17 +134,26 @@ def test_add_new_library(self):
112134
]
113135
for pom_path in expected_poms:
114136
full_pom_path = os.path.join(new_library_path, pom_path)
115-
self.assertTrue(os.path.exists(full_pom_path), f"Expected POM file not found: {full_pom_path}")
137+
self.assertTrue(
138+
os.path.exists(full_pom_path),
139+
f"Expected POM file not found: {full_pom_path}",
140+
)
116141
with open(full_pom_path, "r") as f:
117142
pom_content = f.read()
118-
self.assertIn("<!-- {x-version-update:newapi:current} -->", pom_content,
119-
f"x-version-update tag in {pom_path} does not reference 'newapi'")
143+
self.assertIn(
144+
"<!-- {x-version-update:newapi:current} -->",
145+
pom_content,
146+
f"x-version-update tag in {pom_path} does not reference 'newapi'",
147+
)
120148
# Ensure the artifactId is not changed to the release_please_key
121149
if pom_path == "google-cloud-newapi/pom.xml":
122-
self.assertIn("<artifactId>google-cloud-newapi</artifactId>", pom_content)
150+
self.assertIn(
151+
"<artifactId>google-cloud-newapi</artifactId>", pom_content
152+
)
123153
if pom_path == "proto-google-cloud-newapi-v1/pom.xml":
124-
self.assertIn("<artifactId>proto-google-cloud-newapi-v1</artifactId>", pom_content)
125-
154+
self.assertIn(
155+
"<artifactId>proto-google-cloud-newapi-v1</artifactId>", pom_content
156+
)
126157

127158
@classmethod
128159
def __copy__golden(cls, base_dir: str, subdir: str):

0 commit comments

Comments
 (0)