summaryrefslogtreecommitdiff
path: root/contrib/python/test/test_libs.py
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-05-14 18:01:08 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-16 14:01:10 +0000
commit1aaf8df5be32d755a3f72f9259c66c70fbf850d8 (patch)
tree6e573fc7ae988e36d6d94973cec238aee72feaad /contrib/python/test/test_libs.py
parentc7bc7580a6a9faf6a3159d6c17ff1dfb3710e318 (diff)
downloadpodman-1aaf8df5be32d755a3f72f9259c66c70fbf850d8.tar.gz
podman-1aaf8df5be32d755a3f72f9259c66c70fbf850d8.tar.bz2
podman-1aaf8df5be32d755a3f72f9259c66c70fbf850d8.zip
Refactor libpod python varlink bindings
- More pythonic - Leverage context managers to help with socket leaks - Add system unittest's - Add image unittest's - Add container unittest's - Add models for system, containers and images, and their collections - Add helper functions for datetime parsing/formatting - GetInfo() implemented - Add support for setuptools - Update documentation - Support for Python 3.4-3.6 Signed-off-by: Jhon Honce <jhonce@redhat.com> Closes: #748 Approved by: baude
Diffstat (limited to 'contrib/python/test/test_libs.py')
-rw-r--r--contrib/python/test/test_libs.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/contrib/python/test/test_libs.py b/contrib/python/test/test_libs.py
new file mode 100644
index 000000000..e2160fc30
--- /dev/null
+++ b/contrib/python/test/test_libs.py
@@ -0,0 +1,46 @@
+import datetime
+import unittest
+
+import podman
+
+
+class TestLibs(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_parse(self):
+ expected = datetime.datetime.strptime(
+ '2018-05-08T14:12:53.797795-0700', '%Y-%m-%dT%H:%M:%S.%f%z')
+ for v in [
+ '2018-05-08T14:12:53.797795191-07:00',
+ '2018-05-08T14:12:53.797795-07:00',
+ '2018-05-08T14:12:53.797795-0700',
+ '2018-05-08 14:12:53.797795191 -0700 MST'
+ ]:
+ actual = podman.datetime_parse(v)
+ self.assertEqual(actual, expected)
+
+ podman.datetime_parse(datetime.datetime.now().isoformat())
+
+ def test_parse_fail(self):
+ # chronologist humor: '1752-09-05T12:00:00.000000-0000' also not
+ # handled correctly by python for my locale.
+ for v in [
+ '1752-9-5',
+ '1752-09-05',
+ ]:
+ with self.assertRaises(ValueError):
+ podman.datetime_parse(v)
+
+ def test_format(self):
+ expected = '2018-05-08T18:24:52.753227-07:00'
+ dt = podman.datetime_parse(expected)
+ actual = podman.datetime_format(dt)
+ self.assertEqual(actual, expected)
+
+
+if __name__ == '__main__':
+ unittest.main()