From 86f0e6d99c54e6dd35ebfee882bf9bad65f3d642 Mon Sep 17 00:00:00 2001 From: juk0de Date: Mon, 5 Feb 2024 07:56:57 +0100 Subject: [PATCH] glossary test: added testcases for 'to_str()' --- tests/test_glossary.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_glossary.py b/tests/test_glossary.py index 7291545..c1ac1ed 100644 --- a/tests/test_glossary.py +++ b/tests/test_glossary.py @@ -125,3 +125,44 @@ class TestGlossary(unittest.TestCase): glossary.to_file(file_path) assert glossary.file_path is not None self.assertEqual(glossary.file_path.suffix, glossary_suffix) + + def test_to_str_with_id(self) -> None: + # Create a Glossary instance with an ID + glossary_with_id = Glossary(name="TestGlossary", source_lang="en", target_lang="fr", + desc="A simple test glossary", ID="1001", entries={"one": "un"}) + glossary_str = glossary_with_id.to_str() + self.assertIn("TestGlossary (ID: 1001):", glossary_str) + self.assertIn("- A simple test glossary", glossary_str) + self.assertIn("- Languages: en -> fr", glossary_str) + self.assertIn("- Entries: 1", glossary_str) + + def test_to_str_with_id_and_entries(self) -> None: + # Create a Glossary instance with an ID and include entries + glossary_with_entries = Glossary(name="TestGlossaryWithEntries", source_lang="en", target_lang="fr", + desc="Another test glossary", ID="2002", + entries={"hello": "salut", "goodbye": "au revoir"}) + glossary_str_with_entries = glossary_with_entries.to_str(with_entries=True) + self.assertIn("TestGlossaryWithEntries (ID: 2002):", glossary_str_with_entries) + self.assertIn("- Entries:", glossary_str_with_entries) + self.assertIn(" hello : salut", glossary_str_with_entries) + self.assertIn(" goodbye : au revoir", glossary_str_with_entries) + + def test_to_str_without_id(self) -> None: + # Create a Glossary instance without an ID + glossary_without_id = Glossary(name="TestGlossaryNoID", source_lang="en", target_lang="fr", + desc="A test glossary without an ID", ID=None, entries={"yes": "oui"}) + glossary_str_no_id = glossary_without_id.to_str() + self.assertIn("TestGlossaryNoID (ID: None):", glossary_str_no_id) + self.assertIn("- A test glossary without an ID", glossary_str_no_id) + self.assertIn("- Languages: en -> fr", glossary_str_no_id) + self.assertIn("- Entries: 1", glossary_str_no_id) + + def test_to_str_without_id_and_no_entries(self) -> None: + # Create a Glossary instance without an ID and no entries + glossary_no_id_no_entries = Glossary(name="EmptyGlossary", source_lang="en", target_lang="fr", + desc="An empty test glossary", ID=None, entries={}) + glossary_str_no_id_no_entries = glossary_no_id_no_entries.to_str() + self.assertIn("EmptyGlossary (ID: None):", glossary_str_no_id_no_entries) + self.assertIn("- An empty test glossary", glossary_str_no_id_no_entries) + self.assertIn("- Languages: en -> fr", glossary_str_no_id_no_entries) + self.assertIn("- Entries: 0", glossary_str_no_id_no_entries)