diff options
author | Simon McVittie <smcv@collabora.com> | 2019-09-02 12:39:32 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2019-09-02 12:39:32 +0100 |
commit | 5b0af53bbb3f4e12af4d979d8501ff6fa10af051 (patch) | |
tree | 9ca1ff42739e77acdde0520e25b908607a26c8e1 /test | |
parent | 0805994b1ccc3d94cc47d3072284d435aff44f5c (diff) |
Add basic test coverage for UnixFd
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-standalone.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test-standalone.py b/test/test-standalone.py index 8876a05..e5ba6d3 100755 --- a/test/test-standalone.py +++ b/test/test-standalone.py @@ -513,6 +513,37 @@ class TestMessageMarshalling(unittest.TestCase): else: pass # libdbus >= 1.6.10 allows noncharacters + @unittest.skipIf(sys.platform.startswith("win"), "requires Unix") + def test_unix_fd(self): + plain_fd = os.open('/dev/null', os.O_RDONLY) + + try: + with open('/dev/null', 'r') as file_like_object: + fd = types.UnixFd(plain_fd) + self.assertEqual(fd.variant_level, 0) + other = fd.take() + os.close(other) + + with self.assertRaises(ValueError): + fd.take() + + fd = types.UnixFd(plain_fd, variant_level=42) + self.assertEqual(fd.variant_level, 42) + + fd = types.UnixFd(file_like_object) + self.assertEqual(fd.variant_level, 0) + + fd = types.UnixFd(file_like_object, variant_level=42) + self.assertEqual(fd.variant_level, 42) + + with self.assertRaises(TypeError): + types.UnixFd(plain_fd, invalid_kwarg='nope') + + with self.assertRaises(TypeError): + types.UnixFd(plain_fd, variant_level='nope') + finally: + os.close(plain_fd) + class TestMatching(unittest.TestCase): def setUp(self): from _dbus_bindings import SignalMessage |