factor helper function out to top-level

This commit is contained in:
Jean-Paul Calderone 2021-09-23 07:43:18 -04:00
parent f8c07bfd11
commit 4d8164773c

View File

@ -162,11 +162,6 @@ class OpenMetrics(SyncTestCase):
self.assertThat(d, succeeded(matches_stats(self))) self.assertThat(d, succeeded(matches_stats(self)))
def matches_stats(testcase): def matches_stats(testcase):
def add_detail(testcase):
def predicate(body):
testcase.addDetail("body", text_content(body))
return True
return predicate
return MatchesAll( return MatchesAll(
MatchesStructure( MatchesStructure(
@ -177,12 +172,26 @@ def matches_stats(testcase):
AfterPreprocessing( AfterPreprocessing(
readBodyText, readBodyText,
succeeded(MatchesAll( succeeded(MatchesAll(
MatchesPredicate(add_detail(testcase), "%s dummy"), MatchesPredicate(add_detail(testcase, u"response body"), u"%s dummy"),
parses_as_openmetrics(), parses_as_openmetrics(),
)) ))
) )
) )
def add_detail(testcase, name):
"""
Create a matcher that always matches and as a side-effect adds the matched
value as detail to the testcase.
:param testtools.TestCase testcase: The case to which to add the detail.
:return: A matcher.
"""
def predicate(value):
testcase.addDetail(name, text_content(value))
return True
return predicate
def readBodyText(response): def readBodyText(response):
""" """
Read the response body and decode it using UTF-8. Read the response body and decode it using UTF-8.