|
|
@@ -0,0 +1,34 @@ |
|
|
|
from nose.tools import * |
|
|
|
from nose.tools import assert_raises |
|
|
|
from testutil.helpers import * |
|
|
|
|
|
|
|
import io |
|
|
|
import os |
|
|
|
import sys |
|
|
|
import time |
|
|
|
|
|
|
|
import nilmdb.server |
|
|
|
from nilmdb.utils import timer, lock |
|
|
|
|
|
|
|
class TestMisc(object): |
|
|
|
def test_timer(self): |
|
|
|
capture = io.StringIO() |
|
|
|
old = sys.stdout |
|
|
|
sys.stdout = capture |
|
|
|
with nilmdb.utils.Timer("test"): |
|
|
|
time.sleep(0.01) |
|
|
|
with nilmdb.utils.Timer("test syslog", tosyslog=True): |
|
|
|
time.sleep(0.01) |
|
|
|
sys.stdout = old |
|
|
|
in_("test: ", capture.getvalue()) |
|
|
|
|
|
|
|
def test_lock(self): |
|
|
|
with open("/dev/null") as f: |
|
|
|
eq_(nilmdb.utils.lock.exclusive_lock(f), True) |
|
|
|
nilmdb.utils.lock.exclusive_unlock(f) |
|
|
|
# trigger coverage |
|
|
|
class FakeFile(): |
|
|
|
def fileno(self): |
|
|
|
return None |
|
|
|
with assert_raises(TypeError): |
|
|
|
nilmdb.utils.lock.exclusive_lock(FakeFile()) |