|
17 | 17 | import copy |
18 | 18 | import json |
19 | 19 | import re |
| 20 | +import shutil |
20 | 21 |
|
21 | 22 | import dictdiffer |
22 | 23 | import pytest |
@@ -646,6 +647,59 @@ def test_initodict(self, ref_tree): |
646 | 647 | "section2": {"attr3": [1, 2, "a", "b"], "attr4": {"a": 1, "b": [1, 2]}}, |
647 | 648 | } |
648 | 649 |
|
| 650 | + class TestPdfComparator: |
| 651 | + """Test the PDF comparator.""" |
| 652 | + |
| 653 | + def test_diff_tempfile(self, ref_tree, res_tree_equal): |
| 654 | + """Test the custom tempfile option.""" |
| 655 | + ref_file = ref_tree / "file.pdf" |
| 656 | + res_file = res_tree_equal / "file.pdf" |
| 657 | + |
| 658 | + # Copy the initial data into a nested directory |
| 659 | + nested_ref = res_tree_equal / "nested" / "ref" |
| 660 | + nested_res = res_tree_equal / "nested" / "res" |
| 661 | + shutil.copytree(res_tree_equal, nested_res) |
| 662 | + shutil.copytree(ref_tree, nested_ref) |
| 663 | + |
| 664 | + # Compute difference on initial data |
| 665 | + diff = dir_content_diff.compare_files( |
| 666 | + ref_file, |
| 667 | + res_file, |
| 668 | + dir_content_diff.PdfComparator(), |
| 669 | + tempdir=res_tree_equal, |
| 670 | + ) |
| 671 | + assert not diff |
| 672 | + assert (res_tree_equal / "diff-pdf-file.pdf" / "diff-1.png").exists() |
| 673 | + |
| 674 | + # Compute difference on nested data |
| 675 | + ref_file = nested_ref / "file.pdf" |
| 676 | + res_file = nested_res / "file.pdf" |
| 677 | + diff_nested = dir_content_diff.compare_files( |
| 678 | + ref_file, |
| 679 | + res_file, |
| 680 | + dir_content_diff.PdfComparator(), |
| 681 | + tempdir=nested_res.parent, |
| 682 | + ) |
| 683 | + assert not diff_nested |
| 684 | + assert (nested_res.parent / "diff-pdf-file.pdf" / "diff-1.png").exists() |
| 685 | + |
| 686 | + # Compare files with different names and with existing tempdir |
| 687 | + other_res_file = res_file.with_name("other_file.pdf") |
| 688 | + shutil.copyfile(res_file, other_res_file) |
| 689 | + (res_tree_equal / "diff-pdf-other_file.pdf").mkdir() |
| 690 | + other_diff = dir_content_diff.compare_files( |
| 691 | + ref_file, |
| 692 | + other_res_file, |
| 693 | + dir_content_diff.PdfComparator(), |
| 694 | + tempdir=res_tree_equal, |
| 695 | + ) |
| 696 | + assert not other_diff |
| 697 | + assert (res_tree_equal / "diff-pdf-other_file.pdf").exists() |
| 698 | + assert not list((res_tree_equal / "diff-pdf-other_file.pdf").iterdir()) |
| 699 | + assert ( |
| 700 | + res_tree_equal / "diff-pdf-other_file.pdf_1" / "diff-1.png" |
| 701 | + ).exists() |
| 702 | + |
649 | 703 |
|
650 | 704 | class TestRegistry: |
651 | 705 | """Test the internal registry.""" |
|
0 commit comments