def test_TargetFactory_create_serial(serial_config):
    port = serial_config['port']
    baudrate = serial_config['baud']
    config = Configuration(copy.deepcopy(serial_config))

    console = TargetFactory.create_serial(config, SystemContext())
    assert console.port == port
    assert console.baud == baudrate
def test_TargetFactory_create_serial_should_error_with_no_port(serial_config):
    serial_config.pop('port')

    with pytest.raises(ConfigurationError):
        TargetFactory.create_serial(Configuration(serial_config),
                                    SystemContext())
def test_TargetFactory_create_serial_should_error_if_unconsumed(serial_config):
    serial_config['unused'] = 'abc'

    with pytest.raises(ConfigurationError):
        TargetFactory.create_serial(Configuration(serial_config),
                                    SystemContext())
def test_TargetFactory_create_serial_should_return_none_with_no_config():
    assert TargetFactory.create_serial(None, None) is None
def test_TargetFactory_create_serial_should_error_if_uncomsuned():
    config = Configuration({'baud': 123})

    with pytest.raises(TargetConfigError):
        TargetFactory.create_serial(config, SystemContext())