Browse Source

Test exclusive_lock better

tags/nilmdb-2.0.0
Jim Paris 4 years ago
parent
commit
39e66fe38c
1 changed files with 11 additions and 3 deletions
  1. +11
    -3
      tests/test_misc.py

+ 11
- 3
tests/test_misc.py View File

@@ -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"


Loading…
Cancel
Save