From 3f0b8e50a24c980faed5da56b5d9dc09b4d1426f Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Fri, 23 Aug 2019 16:04:42 -0400 Subject: [PATCH] Split off misc tests; add coverage for failure case in exclusive_lock --- tests/test.order | 1 + tests/test_misc.py | 34 ++++++++++++++++++++++++++++++++++ tests/test_nilmdb.py | 11 ----------- 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 tests/test_misc.py diff --git a/tests/test.order b/tests/test.order index 0b3f06e..05b888b 100644 --- a/tests/test.order +++ b/tests/test.order @@ -2,6 +2,7 @@ test_printf.py test_threadsafety.py test_lrucache.py test_mustclose.py +test_misc.py test_serializer.py diff --git a/tests/test_misc.py b/tests/test_misc.py new file mode 100644 index 0000000..70195d5 --- /dev/null +++ b/tests/test_misc.py @@ -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()) diff --git a/tests/test_nilmdb.py b/tests/test_nilmdb.py index 7596813..62326f1 100644 --- a/tests/test_nilmdb.py +++ b/tests/test_nilmdb.py @@ -35,17 +35,6 @@ class Test00Nilmdb(object): # named 00 so it runs first db.close() db.close() - # test timer, just to get coverage - 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_stream(self): db = nilmdb.server.NilmDB(testdb) eq_(db.stream_list(), [])