Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
with LogCapture() as capture:
DummyClient().log_response(
Response('{"jsonrpc": "2.0", "result": 5, "id": 1}')
)
capture.check(
(
"jsonrpcclient.client.response",
"INFO",
StringComparison(r'.*"result": 5.*'),
)
if limit > 0:
import time
time.sleep(wait)
limit -= wait
continue
else:
break
else:
raise
buf += block
from testfixtures import StringComparison as S
buf = norm.pgctl(buf.decode('UTF-8'))
print('NORMED:')
print(buf)
assert buf == S('''(?s)\
==> playground/ohhi/logs/current <==
{TIMESTAMP} [oe].*
==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
==> playground/ohhi/logs/current <==
.*{TIMESTAMP} .*$''')
assert p.poll() is None # it's still running
p.terminate()
assert p.wait() == -15
def test(self, *_):
with LogCapture() as capture:
DummyClient().log_request('{"jsonrpc": "2.0", "method": "foo"}')
capture.check(
(
"jsonrpcclient.client.request",
"INFO",
StringComparison(r'.*"method": "foo".*'),
)
assert not validate_thrift_deep(comm)
log_capture.check(
('root', 'ERROR',
"Communication: Required Field 'id' is unset!"))
comm.id = "ID"
with LogCapture() as log_capture:
assert not validate_thrift_deep(comm)
log_capture.check(
('root', 'ERROR',
"Communication: Required Field 'uuid' is unset!"))
comm.uuid = concrete.UUID(uuidString="TEST_UUID")
with LogCapture() as log_capture:
assert not validate_thrift_deep(comm)
log_capture.check(('root', 'ERROR', StringComparison(
r".*TEST_UUID.*Required Field 'type' is unset!")))
comm.metadata = concrete.AnnotationMetadata(
tool="TEST", timestamp=int(time.time()))
comm.type = "OTHER"
assert validate_thrift_deep(comm)
def test_entity_mention_tokenization():
comm = read_test_comm()
assert validate_communication(comm)
assert validate_entity_mention_ids(comm)
comm.entityMentionSetList[0].mentionList[0].tokens.tokenizationId = (
concrete.UUID(uuidString='BAD_TOKENIZATION_UUID')
)
with LogCapture() as log_capture:
assert not validate_entity_mention_tokenization_ids(comm)
log_capture.check(('root', 'ERROR', StringComparison(
r'.*invalid tokenizationId.*BAD_TOKENIZATION_UUID')))
def test_untrimmed(self):
"""Should not trim"""
req = '{"jsonrpc": "2.0", "method": "go", "params": {"foo": "%s"}}' % (
"foo" * 100,
)
with LogCapture() as capture:
DummyClient().log_request(req, trim_log_values=False)
capture.check(
(
"jsonrpcclient.client.request",
"INFO",
StringComparison(r".*" + "foo" * 100 + ".*"),
)
def test_entity_mention_ids():
comm = read_test_comm()
assert validate_communication(comm)
assert validate_entity_mention_ids(comm)
comm.entitySetList[0].entityList[0].mentionIdList[
0] = concrete.UUID(uuidString='BAD_ENTITY_MENTION_UUID')
with LogCapture() as log_capture:
assert not validate_entity_mention_ids(comm)
log_capture.check(('root', 'ERROR', StringComparison(
r'.*invalid entityMentionId.*BAD_ENTITY_MENTION_UUID')))
def it_explodes_on_ambiguity(self, tmpdir):
conffile = tmpdir.join('example1.ini')
conffile.write(example1.ini)
conffile = tmpdir.join('example1.conf')
conffile.write(example1.ini)
with ShouldRaise(
C.AmbiguousConfig(
S(r'multiple configurations found at .*/example1\.\*'))
):
example1.config.from_path_prefix(tmpdir.strpath + '/')
def test_missing_from_context(self):
# make sure exception is helpful
class T(object): pass
@requires(T)
def job(arg):
pass # pragma: nocover
runner = Runner(job)
with ShouldRaise(KeyError(
S("'No T in context' attempting to call "
"")
)):
runner()
def test_trimmed(self):
req = '{"jsonrpc": "2.0", "result": "%s", "id": 1}' % ("foo" * 100,)
with LogCapture() as capture:
DummyClient().log_response(Response(req), trim_log_values=True)
capture.check(
(
"jsonrpcclient.client.response",
"INFO",
StringComparison(r".*foofoofoof...ofoofoofoo.*"),
)