Browse Source

Split off misc tests; add coverage for failure case in exclusive_lock

tags/nilmdb-2.0.0
Jim Paris 4 years ago
parent
commit
3f0b8e50a2
3 changed files with 35 additions and 11 deletions
  1. +1
    -0
      tests/test.order
  2. +34
    -0
      tests/test_misc.py
  3. +0
    -11
      tests/test_nilmdb.py

+ 1
- 0
tests/test.order View File

@@ -2,6 +2,7 @@ test_printf.py
test_threadsafety.py
test_lrucache.py
test_mustclose.py
test_misc.py

test_serializer.py



+ 34
- 0
tests/test_misc.py View File

@@ -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())

+ 0
- 11
tests/test_nilmdb.py View File

@@ -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(), [])


Loading…
Cancel
Save