예제 #1
0
def test_configuration_object_supports_equality_testing():
    conf = configuration.Configuration(formatter=None, loader=None)
    match_dict = {'test': 'wat'}
    conf['test'] = 'wat'

    assert conf == conf
    assert conf == match_dict
    assert configuration.Configuration() != match_dict
예제 #2
0
def test_set_updates_a_nested_value_in_the_context():
    mock_value = {}

    subject = configuration.Configuration()
    subject.set('test.example', mock_value)
    print(subject.context)
    assert mock_value is subject.get('test.example')
예제 #3
0
async def load(
    identifier: str,
    *,
    configuration: typing.Dict[str, typing.Any] = {},
) -> configuration_module.Configuration:

    Formatter, formatter_configuration = find_matching_plugin(
        identifier=identifier,
        defaults=formatters.defaults,
        plugin_list=configuration.get('formatters'),
    )

    Loader, loader_configuration = find_matching_plugin(
        identifier=identifier,
        defaults=loaders.defaults,
        plugin_list=configuration.get('loaders'),
    )

    formatter = Formatter(configuration=formatter_configuration)
    loader = Loader(configuration=loader_configuration)

    loader_result = await loader.load(identifier)
    context = await formatter.deserialize(loader_result.content)

    return configuration_module.Configuration(
        context=context,
        identifier=identifier,
        source=loader_result.source,
        loader=loader,
        formatter=formatter,
    )
예제 #4
0
def test_configuration_object_gets_items_from_context():
    conf = configuration.Configuration(
        loader=None,
        formatter=None,
        context={'test': 'wat'},
    )

    assert conf['test'] == 'wat'
예제 #5
0
def test_configuration_object_raises_error_on_save_until_implemented():
    has_seen_expected_error = False

    try:
        configuration.Configuration().save()
    except Exception as e:
        has_seen_expected_error = isinstance(e, NotImplementedError)

    assert has_seen_expected_error is True
예제 #6
0
def test_get_returns_nested_item_from_context():
    context = {'test': {'nested': {'example': 'wat'}}}
    subject = configuration.Configuration(context=context)

    assert 'wat' == subject.get('test.nested.example')
예제 #7
0
def test_get_returns_item_from_context():
    context = {'test': 'wat'}
    assert 'wat' == configuration.Configuration(context=context).get('test')
예제 #8
0
def test_configuration_object_checks_context_for_containment():
    context = {'test': 'wat'}
    assert 'test' in configuration.Configuration(context=context)
예제 #9
0
def test_configuration_object_deletes_items_from_context():
    context = {'test': 'wat'}
    conf = configuration.Configuration(context=context)
    del conf['test']
    assert 'test' not in context
예제 #10
0
def test_configuration_using_acts_as_identity_function_when_given_same_type():
    instance = configuration.Configuration()
    assert configuration.Configuration.using(instance) is instance
예제 #11
0
def test_configuration_object_supports_context_assignment_via_setitem():
    conf = configuration.Configuration(context=mock.MagicMock())
    conf['test'] = 'wat'
    conf.context.__setitem__.assert_called_once_with('test', 'wat')