[PATCH 5/7] tests: added simple tests for media dates



---
 tests/python/test_media.py |   58 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 tests/python/test_media.py

diff --git a/tests/python/test_media.py b/tests/python/test_media.py
new file mode 100644
index 0000000..76daa21
--- /dev/null
+++ b/tests/python/test_media.py
@@ -0,0 +1,58 @@
+import unittest
+
+try:
+    from gi.repository import Grl
+except:
+    logging.warning("Unable to import Grilo's introspection bindings")
+    exit()
+try:
+    from gi.repository import GLib
+except TypeError:
+    # there seems to be a bug with GVariants these days that triggers an
+    # exception when importing GLib. Seems to be harmless though. We import
+    # explicitly GLib in a try/except here so that we can handle that, else the
+    # exception would be raised the first time it is imported by other code
+    # (e.g. by using a GDateTime)
+    from gi.repository import GLib
+
+class TestMedia(unittest.TestCase):
+    def test_creation(self):
+        media = Grl.Media.new()
+        self.assertFalse(media is None)
+
+    def test_publication_date(self):
+        media = Grl.Media.new()
+        date_string = "2001-02-03T04:05:06Z"
+        date = Grl.date_time_from_iso8601 (date_string)
+
+        self.assertTrue(media.get_publication_date() is None)
+        media.set_publication_date(date)
+        d = media.get_publication_date()
+        self.assertTrue(d is not None)
+        self.assertEqual(d.get_year(), 2001)
+        self.assertEqual(d.get_month(), 2)
+        self.assertEqual(d.get_day_of_month(), 3)
+        self.assertEqual(d.get_hour(), 4)
+        self.assertEqual(d.get_minute(), 5)
+        self.assertEqual(d.get_second(), 6)
+        self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z"))
+
+        # date only
+        date_string = "2001-02-03"
+        date = Grl.date_time_from_iso8601 (date_string)
+        media.set_publication_date(date)
+        d = media.get_publication_date()
+        self.assertTrue(d is not None)
+        self.assertEqual(d.get_year(), 2001)
+        self.assertEqual(d.get_month(), 2)
+        self.assertEqual(d.get_day_of_month(), 3)
+        self.assertEqual(d.get_hour(), 12)
+        self.assertEqual(d.get_minute(), 0)
+        self.assertEqual(d.get_second(), 0)
+        self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z"))
+        self.assertEqual(d.format("%FT%H:%M:%S%Z"), date_string + "T12:00:00UTC")
+
+# who said "this is ugly" ?
+Grl.init([])
+registry = Grl.PluginRegistry.get_default()
+registry.load_by_id("grl-filesystem")
-- 
1.7.4.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]