Browse Source

Add tests for two more "no cover" blocks

tags/nilmdb-2.0.0
Jim Paris 2 years ago
parent
commit
087fb39475
4 changed files with 8 additions and 2 deletions
  1. +1
    -1
      nilmdb/utils/mustclose.py
  2. +1
    -1
      nilmdb/utils/timer.py
  3. +4
    -0
      tests/test_mustclose.py
  4. +2
    -0
      tests/test_nilmdb.py

+ 1
- 1
nilmdb/utils/mustclose.py View File

@@ -38,7 +38,7 @@ def must_close(errorfile = sys.stderr, wrap_verify = False):
fprintf(errorfile, "error: %s.close() wasn't called!\n",
self.__class__.__name__)
return orig(self, *args, **kwargs)
except: # pragma: no cover
except:
pass

@wrap_class_method


+ 1
- 1
nilmdb/utils/timer.py View File

@@ -16,7 +16,7 @@ def Timer(name = None, tosyslog = False):
yield
elapsed = int((time.time() - start) * 1000)
msg = (name or 'elapsed') + ": " + str(elapsed) + " ms"
if tosyslog: # pragma: no cover
if tosyslog:
import syslog
syslog.syslog(msg)
else:


+ 4
- 0
tests/test_mustclose.py View File

@@ -115,3 +115,7 @@ class TestMustClose(object):
del w
eq_(err.getvalue(), "")

# Test errors during __del__, by closing stderr so the fprintf fails
r = Foo("hi")
err.close()
del r

+ 2
- 0
tests/test_nilmdb.py View File

@@ -41,6 +41,8 @@ class Test00Nilmdb(object): # named 00 so it runs first
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())



Loading…
Cancel
Save