<commit_before>from opentrons.util.trace import EventBroker
from datetime import datetime
import pytest

async def test_load_from_text(robot_container, protocol):
    session = robot_container.load_protocol(protocol.text, '<blank>')
    assert session.name == '<blank>'
    assert len(session.commands) == 101


async def test_load_from_file(robot_container, protocol):
    session = robot_container.load_protocol_file(protocol.filename)
    assert session.name == protocol.filename
    assert len(session.commands) == 101


async def test_async_notifications(robot_container):
    robot_container.update_filters(['bar'])
    EventBroker.get_instance().notify({'name': 'bar'})
    # Get async iterator
    aiter = robot_container.__aiter__()
    # Then read the first item
    res = await aiter.__anext__()
    # Returns tuple containing message and session
    # Since protocol hasn't been loaded, session is None
    assert res == ({'name': 'bar'}, None)


async def test_load_protocol_with_error(robot_container):
    with pytest.raises(Exception) as e:
        session = robot_container.load_protocol('blah', '<blank>')
        assert session is None

    timestamp, error = e.value.args
    exception, trace = error

    assert datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f')
    assert type(exception) == NameError
    assert str(exception) == "name 'blah' is not defined"


async def test_load_and_run(robot_container, protocol):
    session = robot_container.load_protocol_file(protocol.filename)
    assert session.run_log == []
    robot_container.run(devicename='Virtual Smoothie')
    assert len(session.run_log) == 101
<commit_msg>fix linting error<commit_after>from opentrons.util.trace import EventBroker
from datetime import datetime
import pytest


async def test_load_from_text(robot_container, protocol):
    session = robot_container.load_protocol(protocol.text, '<blank>')
    assert session.name == '<blank>'
    assert len(session.commands) == 101


async def test_load_from_file(robot_container, protocol):
    session = robot_container.load_protocol_file(protocol.filename)
    assert session.name == protocol.filename
    assert len(session.commands) == 101


async def test_async_notifications(robot_container):
    robot_container.update_filters(['bar'])
    EventBroker.get_instance().notify({'name': 'bar'})
    # Get async iterator
    aiter = robot_container.__aiter__()
    # Then read the first item
    res = await aiter.__anext__()
    # Returns tuple containing message and session
    # Since protocol hasn't been loaded, session is None
    assert res == ({'name': 'bar'}, None)


async def test_load_protocol_with_error(robot_container):
    with pytest.raises(Exception) as e:
        session = robot_container.load_protocol('blah', '<blank>')
        assert session is None

    timestamp, error = e.value.args
    exception, trace = error

    assert datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f')
    assert type(exception) == NameError
    assert str(exception) == "name 'blah' is not defined"


async def test_load_and_run(robot_container, protocol):
    session = robot_container.load_protocol_file(protocol.filename)
    assert session.run_log == []
    robot_container.run(devicename='Virtual Smoothie')
    assert len(session.run_log) == 101

{'fraction_non_alphanumeric': 0.10717529518619437, 'fraction_numerical': 0.005449591280653951, 'mean_word_length': 4.525083612040134, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4616578', 'n_tokens_mistral': 996, 'n_tokens_neox': 968, 'n_words': 240}