|
@@ -26,12 +26,20 @@ class TestMisc(object): |
|
|
with open("/dev/null") as f: |
|
|
with open("/dev/null") as f: |
|
|
eq_(nilmdb.utils.lock.exclusive_lock(f), True) |
|
|
eq_(nilmdb.utils.lock.exclusive_lock(f), True) |
|
|
nilmdb.utils.lock.exclusive_unlock(f) |
|
|
nilmdb.utils.lock.exclusive_unlock(f) |
|
|
# trigger coverage |
|
|
|
|
|
|
|
|
# Test error conditions |
|
|
class FakeFile(): |
|
|
class FakeFile(): |
|
|
|
|
|
def __init__(self, fileno): |
|
|
|
|
|
self._fileno = fileno |
|
|
def fileno(self): |
|
|
def fileno(self): |
|
|
return None |
|
|
|
|
|
|
|
|
return self._fileno |
|
|
with assert_raises(TypeError): |
|
|
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): |
|
|
def test_replace_file(self): |
|
|
fn = b"tests/misc-testdb/file" |
|
|
fn = b"tests/misc-testdb/file" |
|
|