Skip to content

Commit

Permalink
tidy ensure_checks_above tests and add coverage for check_present mar…
Browse files Browse the repository at this point in the history
…king entries as checked.
  • Loading branch information
cjw296 committed Nov 27, 2020
1 parent b49a953 commit d275252
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions testfixtures/tests/test_logcapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from testfixtures.shouldraise import ShouldAssert
from testfixtures.mock import Mock

from testfixtures import Replacer, LogCapture, compare
from testfixtures import Replacer, LogCapture, compare, Replace

root = getLogger()
one = getLogger('one')
Expand All @@ -33,33 +33,37 @@ def test_simple_strict(self):
log_capture.ensure_checked()

def test_simple_strict_re_defaulted(self):
old = LogCapture.default_ensure_checks_above
try:
with Replace('testfixtures.LogCapture.default_ensure_checks_above', ERROR):
LogCapture.default_ensure_checks_above = ERROR
log_capture = LogCapture()
root.error('during')
log_capture.uninstall()
with ShouldAssert("Not asserted ERROR log(s): [('root', 'ERROR', 'during')]"):
log_capture.ensure_checked()
finally:
LogCapture.default_ensure_checks_above = old

def test_simple_strict_asserted(self):
def test_simple_strict_asserted_by_check(self):
log_capture = LogCapture(ensure_checks_above=ERROR)
root.error('during')
log_capture.uninstall()
log_capture.check(("root", "ERROR", "during"))
log_capture.ensure_checked()

def test_simple_strict_asserted_2(self):
def test_simple_strict_asserted_by_check_present(self):
log_capture = LogCapture(ensure_checks_above=ERROR)
root.error('during')
log_capture.uninstall()
log_capture.check_present(("root", "ERROR", "during"))
log_capture.ensure_checked()

def test_simple_strict_asserted_by_containment(self):
log_capture = LogCapture(ensure_checks_above=ERROR)
root.error('during')
log_capture.uninstall()
assert ("root", "ERROR", "during") in log_capture
assert ("root", "INFO", "during") not in log_capture
log_capture.ensure_checked()

def test_simple_strict_asserted_3(self):
def test_simple_strict_asserted_by_mark_all_checked(self):
log_capture = LogCapture(ensure_checks_above=ERROR)
root.error('during')
log_capture.uninstall()
Expand All @@ -68,7 +72,7 @@ def test_simple_strict_asserted_3(self):

def test_simple_strict_ctx(self):
with ShouldAssert("Not asserted ERROR log(s): [('root', 'ERROR', 'during')]"):
with LogCapture(ensure_checks_above=ERROR) as log_capture:
with LogCapture(ensure_checks_above=ERROR):
root.error('during')

def test_simple_strict_asserted_ctx(self):
Expand Down

0 comments on commit d275252

Please sign in to comment.