From 39e66fe38c41371493e27629fd566ceb1ba4f9f9 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Fri, 23 Aug 2019 16:23:15 -0400 Subject: [PATCH] Test exclusive_lock better --- tests/test_misc.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index da9cf76..e57375f 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -26,12 +26,20 @@ class TestMisc(object): with open("/dev/null") as f: eq_(nilmdb.utils.lock.exclusive_lock(f), True) nilmdb.utils.lock.exclusive_unlock(f) - # trigger coverage + # Test error conditions class FakeFile(): + def __init__(self, fileno): + self._fileno = fileno def fileno(self): - return None + return self._fileno with assert_raises(TypeError): - nilmdb.utils.lock.exclusive_lock(FakeFile()) + nilmdb.utils.lock.exclusive_lock(FakeFile('none')) + with assert_raises(ValueError): + nilmdb.utils.lock.exclusive_lock(FakeFile(-1)) + with assert_raises(IOError): + nilmdb.utils.lock.exclusive_lock(FakeFile(12345)) + + # Lock failure is tested in test_bulkdata def test_replace_file(self): fn = b"tests/misc-testdb/file"