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: show difference in integration test #2684

Merged
merged 3 commits into from
Apr 23, 2024
Merged
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
24 changes: 17 additions & 7 deletions library_generation/test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import difflib
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to see that there is a native Python lib for this!

import json
from filecmp import cmp
from filecmp import dircmp
Expand Down Expand Up @@ -102,12 +103,9 @@ def test_entry_point_running_in_container(self):
print(f"Checking for differences in '{library_name}'.")
print(f" The expected library is in {golden_dir}/{library_name}.")
print(f" The actual library is in {actual_library}. ")
target_repo_dest = (
f"{repo_dest}/{library_name}" if config.is_monorepo() else repo_dest
)
compare_result = dircmp(
f"{golden_dir}/{library_name}",
target_repo_dest,
actual_library,
ignore=[".repo-metadata.json"],
)
diff_files = []
Expand All @@ -122,12 +120,24 @@ def test_entry_point_running_in_container(self):
print_file = lambda f: print(f" - {f}")
if len(diff_files) > 0:
print(" Some files (found in both folders) are differing:")
[print_file(f) for f in diff_files]
for diff_file in diff_files:
print(f"Difference in {diff_file}:")
with open(
f"{golden_dir}/{library_name}/{diff_file}"
) as expected_file:
with open(f"{actual_library}/{diff_file}") as actual_file:
[
print(line)
for line in difflib.unified_diff(
expected_file.readlines(),
actual_file.readlines(),
)
]
if len(golden_only) > 0:
print(" There were files found only in the golden dir:")
[print_file(f) for f in golden_only]
if len(generated_only) > 0:
print(" Some files were found to have differences:")
print(" There were files found only in the generated dir:")
[print_file(f) for f in generated_only]

self.assertTrue(len(golden_only) == 0)
Expand All @@ -139,7 +149,7 @@ def test_entry_point_running_in_container(self):
self.assertTrue(
self.__compare_json_files(
f"{golden_dir}/{library_name}/.repo-metadata.json",
f"{target_repo_dest}/.repo-metadata.json",
f"{actual_library}/.repo-metadata.json",
),
msg=f" The generated {library_name}/.repo-metadata.json is different from golden.",
)
Expand Down
Loading