From 1cafa1cf74d54221daf63378c34fa0a0c38668d4 Mon Sep 17 00:00:00 2001
From: "Mayr, Hannes" <hannes.mayr@stud.tu-darmstadt.de>
Date: Tue, 10 Jan 2023 12:55:53 +0100
Subject: [PATCH] Add unittest for wrong font file.

---
 plotid/tagplot_image.py     | 2 +-
 tests/test_tagplot_image.py | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/plotid/tagplot_image.py b/plotid/tagplot_image.py
index 282b2b0..86a92dc 100644
--- a/plotid/tagplot_image.py
+++ b/plotid/tagplot_image.py
@@ -39,7 +39,7 @@ def tagplot_image(plotid_object: PlotOptions) -> PlotIDTransfer:
         if not isinstance(img, str):
             raise TypeError("Name of the image is not a string.")
         if not os.path.isfile(img):
-            raise TypeError("File does not exist.")
+            raise TypeError(f"Image '{img}' does not exist.")
             # Check if figs is a valid file is done by pillow internally
 
     color = tuple(rgb_value * 255 for rgb_value in plotid_object.fontcolor)
diff --git a/tests/test_tagplot_image.py b/tests/test_tagplot_image.py
index 42dbf3e..727243f 100644
--- a/tests/test_tagplot_image.py
+++ b/tests/test_tagplot_image.py
@@ -88,6 +88,13 @@ class TestTagplotImage(unittest.TestCase):
         with self.assertRaises(TypeError):
             tagplot_image("wrong_object")
 
+    def test_font_file_not_defined(self) -> None:
+        """Test if a Warning is raised if an invalid font file was specified."""
+        options = PlotOptions(IMG1, ROTATION, POSITION, font="font")
+        options.validate_input()
+        with self.assertWarns(Warning):
+            tagplot_image(options)
+
     def tearDown(self) -> None:
         os.remove(IMG1)
         os.remove(IMG2)
-- 
GitLab