mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
factor helper function out to top-level
This commit is contained in:
parent
f8c07bfd11
commit
4d8164773c
@ -162,11 +162,6 @@ class OpenMetrics(SyncTestCase):
|
||||
self.assertThat(d, succeeded(matches_stats(self)))
|
||||
|
||||
def matches_stats(testcase):
|
||||
def add_detail(testcase):
|
||||
def predicate(body):
|
||||
testcase.addDetail("body", text_content(body))
|
||||
return True
|
||||
return predicate
|
||||
|
||||
return MatchesAll(
|
||||
MatchesStructure(
|
||||
@ -177,12 +172,26 @@ def matches_stats(testcase):
|
||||
AfterPreprocessing(
|
||||
readBodyText,
|
||||
succeeded(MatchesAll(
|
||||
MatchesPredicate(add_detail(testcase), "%s dummy"),
|
||||
MatchesPredicate(add_detail(testcase, u"response body"), u"%s dummy"),
|
||||
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):
|
||||
"""
|
||||
Read the response body and decode it using UTF-8.
|
||||
|
Loading…
Reference in New Issue
Block a user