Skip to content

Commit 0dae5b8

Browse files
Feat: Add exception type before arguments (#36)
1 parent 6b8e5c8 commit 0dae5b8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

dir_content_diff/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ def compare_files(ref_file, comp_file, comparator, *args, return_raw_diffs=False
136136
exception_args = "\n".join(str(i) for i in exception.args)
137137
except Exception: # pylint: disable=broad-exception-caught
138138
exception_args = "UNKNOWN ERROR: Could not get information from the exception"
139+
exc_type = type(exception).__name__
139140
return diff_msg_formatter(
140141
ref_file,
141142
comp_file,
142-
reason="Exception raised: " + exception_args,
143+
reason=f"Exception raised: ({exc_type}) {exception_args}",
143144
diff_args=args,
144145
diff_kwargs=kwargs,
145146
load_kwargs=load_kwargs,

tests/test_base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def bad_comparator(ref_path, test_path, *args, **kwargs):
773773
assert len(res) == 1
774774
match = re.match(
775775
r"The files '\S*/ref/file\.yaml' and '\S*/res/file\.yaml' are different:\n"
776-
r"Exception raised: Bad\ncomparator",
776+
r"Exception raised: \(RuntimeError\) Bad\ncomparator",
777777
res["file.yaml"],
778778
)
779779
assert match is not None
@@ -787,10 +787,9 @@ def bad_comparator_no_str(ref_path, test_path, *args, **kwargs):
787787
res = compare_trees(ref_tree, res_tree_equal)
788788

789789
assert len(res) == 1
790-
print(res["file.yaml"])
791790
match = re.match(
792791
r"The files '\S*/ref/file\.yaml' and '\S*/res/file\.yaml' are different:\n"
793-
r"Exception raised: \(1, \('Bad\\ncomparator', 2\)\)",
792+
r"Exception raised: \(RuntimeError\) \(1, \('Bad\\ncomparator', 2\)\)",
794793
res["file.yaml"],
795794
)
796795
assert match is not None
@@ -810,10 +809,10 @@ def bad_comparator_exception_failing(ref_path, test_path, *args, **kwargs):
810809
res = compare_trees(ref_tree, res_tree_equal)
811810

812811
assert len(res) == 1
813-
print(res["file.yaml"])
814812
match = re.match(
815813
r"The files '\S*/ref/file\.yaml' and '\S*/res/file\.yaml' are different:\n"
816-
r"Exception raised: UNKNOWN ERROR: Could not get information from the exception",
814+
r"Exception raised: \(RuntimeError\) UNKNOWN ERROR: Could not get information from "
815+
r"the exception",
817816
res["file.yaml"],
818817
)
819818
assert match is not None

0 commit comments

Comments
 (0)