diff --git a/hed/schema/schema_compare.py b/hed/schema/schema_compare.py index a229ee1a6..1cd974c04 100644 --- a/hed/schema/schema_compare.py +++ b/hed/schema/schema_compare.py @@ -120,6 +120,10 @@ def compare_differences(schema1, schema2, output='raw', attribute_filter=None, s final_string = "" if include_summary: final_string += _pretty_print_header(header_summary) + if not final_string: + return final_string + final_string = ("Overall summary:\n================\n" + final_string + \ + "\n\n\nSummary details:\n================\n\n") for section_key in sections: val1, val2, val3 = unequal_entries[section_key], not_in_1[section_key], not_in_2[section_key] type_name = SectionEntryNames[section_key] @@ -250,6 +254,7 @@ def _get_tag_name_summary(tag_dicts): def _pretty_print_header(summary_dict): + output_string = "" first_entry = True for section_key, tag_names in summary_dict.items(): @@ -264,7 +269,6 @@ def _pretty_print_header(summary_dict): output_string += "\n" first_entry = False - output_string += "\n" return output_string diff --git a/tests/schema/test_schema_compare.py b/tests/schema/test_schema_compare.py index ccc08b796..a07811425 100644 --- a/tests/schema/test_schema_compare.py +++ b/tests/schema/test_schema_compare.py @@ -143,14 +143,20 @@ def test_compare_score_lib_versions(self): schema2 = load_schema_version("score_1.1.0") not_in_schema1, not_in_schema2, unequal_entries = compare_differences(schema1, schema2, attribute_filter=HedKey.InLibrary) + + self.assertEqual(len(not_in_schema1[HedSectionKey.Tags]), 21) self.assertEqual(len(not_in_schema2[HedSectionKey.Tags]), 10) self.assertEqual(len(unequal_entries[HedSectionKey.Tags]), 61) + diff_string = compare_differences(schema1, schema1, attribute_filter=HedKey.InLibrary, output='string', + sections=None) + self.assertFalse(diff_string) diff_string = compare_differences(schema1, schema2, attribute_filter=HedKey.InLibrary, output='string', sections=None) + self.assertIsInstance(diff_string, str) - # print(diff_string) + print(diff_string) json_style_dict = compare_differences(schema1, schema2, attribute_filter=HedKey.InLibrary, output='dict', sections=None)