コード例 #1
0
def test_remove_model_when_exists():
    system = SimulatedSystem()
    battery = SinglePhaseGenerator()
    uuid = system.add_model(battery)
    assert system.remove_model(uuid)

    assert len(system.devices) == 0
    assert len(system.subscriptions) == 0
コード例 #2
0
def test_subscribe_returns_disposable():
    system = SimulatedSystem()

    # Adding a subscriber adds it to the list of subjects
    def subscriber(profile):
        pass

    disposable = system.subscribe(cb=subscriber)
    assert len(system.subjects) == 1

    # Disposing of it removes the item
    disposable()
    assert len(system.subjects) == 0
コード例 #3
0
def main(cmd_line):
    """Entry point for the application.

    :param cmd_line: Array of command line arguments (without the application
                     name).
    """
    args = parse_arguments(cmd_line)
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)

    event_loop = asyncio.get_event_loop()

    system = SimulatedSystem()

    # The web server really wants to own the event loop, so we first
    # create the NATS server.
    nats_disposable = create_server(args.servers, system, event_loop)

    try:
        # Start the web server to visualize the system in an alternative way
        # The web server handles the termination detection
        # The server will initialize the system before it starts
        create_web_server(args.listen[0], args.listen[1], event_loop, system)
    finally:
        nats_disposable()
        event_loop.run_until_complete(event_loop.shutdown_asyncgens())
        event_loop.close()
def test_integration_create_server_returns_canceler():
    event_loop = asyncio.new_event_loop()
    system = SimulatedSystem()
    canceler = create_server(servers=["nats://127.0.0.1:4222"],
                             system=system,
                             event_loop=event_loop)

    canceler()
async def test_nats_publisher_publish():
    system = SimulatedSystem()
    loop = asyncio.get_event_loop()
    mock_nats = MockNats()
    publisher = NatsPublisher([], system, loop, mock_nats)

    await publisher.start()

    profile = gm.GenerationReadingProfile()
    publisher.publish_async(profile)
async def test_nats_subscriber_event_handler_invalid_data():
    system = SimulatedSystem()
    event_loop = asyncio.new_event_loop()
    mock_nats = MockNats()
    subscriber = NatsSubscriber([], system, event_loop, mock_nats)

    await subscriber.start()

    # Send an event
    model = gm.GenerationReadingProfile
    Message = collections.namedtuple("Message", "data subject")
    msg = Message(data="", subject="")

    # We don't have much to test other than we didn't raise
    await subscriber.event_handler(model, msg)
async def test_nats_subscriber_event_handler():
    system = SimulatedSystem()
    event_loop = asyncio.new_event_loop()
    mock_nats = MockNats()
    subscriber = NatsSubscriber([], system, event_loop, mock_nats)

    await subscriber.start()

    # Send an event
    model = gm.GenerationReadingProfile
    encoded_model = model().SerializeToString()
    Message = collections.namedtuple("Message", "data subject")
    msg = Message(data=encoded_model, subject="")

    await subscriber.event_handler(model, msg)
コード例 #8
0
def test_update_profile_when_mrid_matches_device():
    # We have this to ensure that we are getting good test coverage.
    device_mrid = uuid.uuid4()
    battery = Mock(mrid=device_mrid)

    system = SimulatedSystem()
    system.add_model(battery)

    profile = gm.GenerationControlProfile()
    profile.generatingUnit.conductingEquipment.mRID = str(device_mrid)
    system.update_profile(str(device_mrid), profile)

    battery.update_profile.assert_called_once_with(profile)
コード例 #9
0
def test_update_profile_when_invalid_mrid():
    # We have this to ensure that we are getting good test coverage.
    system = SimulatedSystem()

    profile = gm.GenerationControlProfile()
    system.update_profile("ae8b5a94-fa97-4140-96f1", profile)
コード例 #10
0
def test_update_profile_when_mrid_doesnot_exist():
    # We have this to ensure that we are getting good test coverage.
    system = SimulatedSystem()

    profile = gm.GenerationControlProfile()
    system.update_profile("ae8b5a94-fa97-4140-96f1-1b2f6b9255f8", profile)
コード例 #11
0
def test_remove_model_when_no_devices():
    system = SimulatedSystem()
    assert system.remove_model(uuid.uuid1()) is False
コード例 #12
0
def _test_app(tmpdir):
    app.system = SimulatedSystem()
    return app