Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove generated files in tests #2644

Merged
merged 19 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ target/
# Vscode Settings
.vscode/settings.json

*.iml

# Python
**/__pycache__/
.venv

# library generation
**/output/
**/googleapis
library_generation/test/resources/test_monorepo_postprocessing/
**/*egg-info/
**/build/
**/dist/
8 changes: 5 additions & 3 deletions library_generation/generate_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ def generate(
config_path=generation_config_yaml,
config=config,
repository_path=repository_path,
target_library_names=target_library_names.split(",")
if target_library_names is not None
else target_library_names,
target_library_names=(
target_library_names.split(",")
blakeli0 marked this conversation as resolved.
Show resolved Hide resolved
if target_library_names is not None
else target_library_names
),
)


Expand Down
1 change: 1 addition & 0 deletions library_generation/test/compare_poms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The only comparison points are: element path (e.g. project/dependencies) and element text
There is a special case for `dependency`, where the maven coordinates are prepared as well
"""

from library_generation.utils.utilities import eprint
import xml.etree.ElementTree as et
from collections import Counter
Expand Down
23 changes: 21 additions & 2 deletions library_generation/test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ class IntegrationTest(unittest.TestCase):
def setUpClass(cls) -> None:
IntegrationTest.__build_image(docker_file=build_file, cwd=repo_root_dir)

def test_entry_point_running_in_container(self):
shutil.rmtree(f"{golden_dir}", ignore_errors=True)
@classmethod
def tearDownClass(cls) -> None:
cls.__remove_docker_image()

@classmethod
def setUp(cls) -> None:
cls.__remove_generated_files()
os.makedirs(f"{golden_dir}", exist_ok=True)

def test_entry_point_running_in_container(self):
config_files = self.__get_config_files(config_dir)
for repo, config_file in config_files:
config = from_yaml(config_file)
Expand Down Expand Up @@ -168,6 +175,7 @@ def test_entry_point_running_in_container(self):
"The generated PR description does not match the expected golden file",
)
print(" PR description comparison succeed.")
self.__remove_generated_files()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the generated files after the integration test succeeds.


@classmethod
def __build_image(cls, docker_file: str, cwd: str):
Expand All @@ -176,6 +184,13 @@ def __build_image(cls, docker_file: str, cwd: str):
cwd=cwd,
)

@classmethod
def __remove_generated_files(cls):
# uncomment this line when the generated files don't owned by root.
# shutil.rmtree(f"{output_dir}", ignore_errors=True)
if os.path.isdir(f"{golden_dir}"):
shutil.rmtree(f"{golden_dir}")

@classmethod
def __pull_repo_to(cls, dest: Path, repo: str, committish: str) -> str:
shutil.rmtree(dest, ignore_errors=True)
Expand Down Expand Up @@ -323,3 +338,7 @@ def __recursive_diff_files(
cls.__recursive_diff_files(
sub_dcmp, diff_files, left_only, right_only, dirname + sub_dirname + "/"
)

@classmethod
def __remove_docker_image(cls):
subprocess.check_call(["docker", "image", "rmi", image_tag])
15 changes: 14 additions & 1 deletion library_generation/test/utilities_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
Unit tests for python scripts
"""

import shutil
import unittest
import os
import io
Expand Down Expand Up @@ -313,6 +313,7 @@ def test_generate_prerequisite_files_non_monorepo_success(self):
file_comparator.compare_files(
f"{library_path}/owlbot.py", f"{library_path}/owlbot-golden.py"
)
self.__remove_prerequisite_files(path=library_path, is_monorepo=False)

def test_generate_prerequisite_files_monorepo_success(self):
library_path = self.__setup_prerequisite_files(num_libraries=2)
Expand All @@ -328,6 +329,7 @@ def test_generate_prerequisite_files_monorepo_success(self):
file_comparator.compare_files(
f"{library_path}/owlbot.py", f"{library_path}/owlbot-golden.py"
)
self.__remove_prerequisite_files(path=library_path)

def test_prepare_repo_monorepo_success(self):
gen_config = self.__get_a_gen_config(2)
Expand Down Expand Up @@ -373,6 +375,7 @@ def test_prepare_repo_split_repo_success(self):
self.assertEqual("output", Path(repo_config.output_folder).name)
library_path = sorted([Path(key).name for key in repo_config.libraries])
self.assertEqual(["misc"], library_path)
shutil.rmtree(repo_config.output_folder)

def __setup_prerequisite_files(
self, num_libraries: int, library_type: str = "GAPIC_AUTO"
Expand Down Expand Up @@ -448,6 +451,16 @@ def __get_a_gen_config(
libraries=libraries,
)

@staticmethod
def __remove_prerequisite_files(path: str, is_monorepo: bool = True) -> None:
os.remove(f"{path}/.repo-metadata.json")
os.remove(f"{path}/owlbot.py")
if is_monorepo:
os.remove(f"{path}/.OwlBot-hermetic.yaml")
return
if os.path.isdir(f"{path}/.github"):
shutil.rmtree(f"{path}/.github", ignore_errors=True)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ def test_monorepo_postprocessing_valid_repository_success(self):
expect=f"{repository_path}/gapic-libraries-bom/pom-golden.xml",
actual=f"{repository_path}/gapic-libraries-bom/pom.xml",
)
cleanup(files)
Loading