How to use the testfixtures.LogCapture function in testfixtures

To help you get started, we’ve selected a few testfixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bmartin5692 / bumper / tests / test_mqttserver.py View on Github external
async def test_helperbot_message():
    mqtt_address = ("127.0.0.1", 8883)
    mqtt_server = bumper.MQTTServer(mqtt_address)
    await mqtt_server.broker_coro()

    with LogCapture() as l:

        # Test broadcast message
        mqtt_helperbot = bumper.MQTTHelperBot(mqtt_address)
        await mqtt_helperbot.start_helper_bot()
        assert (
            mqtt_helperbot.Client._connected_state._value == True
        )  # Check helperbot is connected
        msg_payload = ""
        msg_topic_name = "iot/atr/DustCaseST/bot_serial/ls1ok3/wC3g/x"
        await mqtt_helperbot.Client.publish(
            msg_topic_name, msg_payload.encode(), hbmqtt.client.QOS_0
        )
        try:
            await asyncio.wait_for(mqtt_helperbot.Client.deliver_message(), timeout=0.1)
        except asyncio.TimeoutError:
            pass
github RouganStriker / django-query-debug / tests / mock_models / test_patch.py View on Github external
def assertNumQueriesAndLogs(self, expected_queries, expected_logs=None):
        with self.assertNumQueries(expected_queries), LogCapture() as log_capture:
            yield

        if expected_logs is None:
            expected_logs = []

        log_capture.check(*[
            ('query_debug', 'WARNING', log) for log in expected_logs
        ])
github edx / pa11ycrawler / tests / test_spider.py View on Github external
tests = [record.msg for record in records]

    assert 'HttpError Code: %s' in tests
    assert 'HttpError on %s' in tests
    assert not 'Credentials failed. Either add/update the current credentials ' \
    'or remove them to enable auto auth' in tests
    assert not 'DNSLookupError on %s' in tests

    #test DNSLookup failures
    dnsFailureMock = mocker.patch('twisted.python.failure.Failure')
    dnsFailureMock.check = mock_check
    isHttpError = False
    isDNSError = True
    mocker.patch.object(dnsFailureMock, 'DNSLookupError', autospec=True)

    with LogCapture() as l:
        spider.handle_error(dnsFailureMock)
    records = list(l.records)
    tests = [record.msg for record in records]

    assert 'DNSLookupError on %s' in tests
    assert not 'HttpError Code: %s' in tests
    assert not 'HttpError on %s' in tests
    assert not 'Credentials failed. Either add/update the current credentials ' \
    'or remove them to enable auto auth' in tests
github OpenIDC / pyoidc / tests / test_oauth2_provider.py View on Github external
_session_db = DictSessionBackend()
        cons = Consumer(
            _session_db,
            client_config=CLIENT_CONFIG,
            server_info=SERVER_INFO,
            **CONSUMER_CONFIG
        )

        sid, location = cons.begin(
            "http://localhost:8087", "http://localhost:8088/authorization"
        )

        resp = self.provider.authorization_endpoint(urlparse(location).query)
        assert resp.status_code == 303
        resp = urlparse(resp.message).query
        with LogCapture(level=logging.DEBUG) as logcap:
            aresp = cons.handle_authorization_response(query=resp)

        assert isinstance(aresp, AuthorizationResponse)
        assert _eq(aresp.keys(), ["state", "code", "client_id", "iss"])
        assert _eq(
            cons.grant[sid].keys(),
            ["tokens", "code", "exp_in", "seed", "id_token", "grant_expiration_time"],
        )

        state = aresp["state"]
        assert _eq(logcap.records[0].msg, "- authorization - code flow -")
        assert verify_outcome(
            logcap.records[1].msg,
            "QUERY: ",
            [
                "state={}".format(state),
github coursera / courseraprogramming / tests / commands / grade_tests.py View on Github external
def test_check_output_good_output_is_correct(sys):
    with LogCapture() as logs:
        docker_mock = MagicMock()
        container = {
            "Id": "myimageId"
        }
        args = argparse.Namespace()
        args.timeout = 300
        args.no_rm = False

        docker_mock.wait.return_value = 0
        docker_mock.logs.side_effect = [
            '',
            '{"isCorrect":false, "feedback": "Helpful comment!"}'
        ]
        # Run the function under test
        grade.run_container(docker_mock, container, args)
    logs.check(
github coursera / courseraprogramming / tests / commands / grade_tests.py View on Github external
def test_check_output_good_output_fractional_score_zero(sys):
    with LogCapture() as logs:
        docker_mock = MagicMock()
        container = {
            "Id": "myimageId"
        }
        args = argparse.Namespace()
        args.timeout = 300
        args.no_rm = False

        docker_mock.wait.return_value = 0
        docker_mock.logs.side_effect = [
            '',
            '{"fractionalScore":0, "feedback": "Helpful comment!"}'
        ]
        # Run the function under test
        grade.run_container(docker_mock, container, args)
    logs.check(
github scrapy / scrapy / tests / test_proxy_connect.py View on Github external
def test_https_noconnect(self):
        proxy = os.environ['https_proxy']
        os.environ['https_proxy'] = proxy + '?noconnect'
        crawler = get_crawler(SimpleSpider)
        with LogCapture() as l:
            yield crawler.crawl(self.mockserver.url("/status?n=200", is_secure=True))
        self._assert_got_response_code(200, l)
github scrapy / scrapy / tests / test_proxy_connect.py View on Github external
def test_https_noconnect(self):
        proxy = os.environ['https_proxy']
        os.environ['https_proxy'] = proxy + '?noconnect'
        crawler = get_crawler(SimpleSpider)
        with LogCapture() as l:
            yield crawler.crawl(self.mockserver.url("/status?n=200", is_secure=True))
        self._assert_got_response_code(200, l)
github BiznetGIO / neo-cli / tests / test_utils.py View on Github external
def test_log_warn(self):
        with LogCapture() as log:
            utils.log_warn("test warn")
        assert "test warn" in str(log.records)
github scitran / core / tests / unit_tests / python / test_request.py View on Github external
def setUp(self):
        self.log_capture = LogCapture()
        self.request = api.web.request.SciTranRequest({})