From e455fe8d76c8fcde75cd19b8e237eb323e130789 Mon Sep 17 00:00:00 2001 From: rickmeasham Date: Sat, 30 Oct 2021 22:59:26 +1100 Subject: [PATCH] fix: Template on empty/unreadable file exception is a string, not a float --- icalevents/icaldownload.py | 2 +- test/test_data/empty.ics | 0 test/test_icaldownload.py | 11 +++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/test_data/empty.ics diff --git a/icalevents/icaldownload.py b/icalevents/icaldownload.py index 0a215b2..6aadedd 100644 --- a/icalevents/icaldownload.py +++ b/icalevents/icaldownload.py @@ -82,7 +82,7 @@ class ICalDownload: content = f.read() if not content: - raise IOError("File %f is not readable or is empty!" % file) + raise IOError("File %s is not readable or is empty!" % file) return self.decode(content, apple_fix=apple_fix) diff --git a/test/test_data/empty.ics b/test/test_data/empty.ics new file mode 100644 index 0000000..e69de29 diff --git a/test/test_icaldownload.py b/test/test_icaldownload.py index e0831f6..17dd79d 100644 --- a/test/test_icaldownload.py +++ b/test/test_icaldownload.py @@ -93,3 +93,14 @@ DTSTART:19180331T020000 # Delete tmp dir os.chdir("..") shutil.rmtree("tmp") + + def test_empty_file(self): + empty_ical = "test/test_data/empty.ics" + + with self.assertRaises(IOError) as cm: + icalevents.icaldownload.ICalDownload().data_from_file(empty_ical) + + self.assertEqual( + str(cm.exception), + "File test/test_data/empty.ics is not readable or is empty!" + )