コード例 #1
0
def test_config_with_simple_classes():

    # Another method for registering items (other than using decorator).
    config.register(Item)

    test_config_path = testing.relative_module_path(__file__,
                                                    'test_config.yaml')

    data = config.load_config(test_config_path)

    foo_with_defaults = data['foo_with_defaults']
    assert foo_with_defaults.f == 1

    empty_boo = data['empty_boo']
    assert empty_boo.foo is None

    foo = data['foo']
    boo = data['boo']

    assert foo.s == 'some_string'
    assert foo.f == 2.5

    assert boo.foo is foo
    assert len(boo.items) == 2
    assert isinstance(boo.items[0], Item)
コード例 #2
0
ファイル: test_config.py プロジェクト: MichalinaKainos/owca
def test_config_strict_mode_errors():
    config.register(Item, strict_mode=True)

    test_config_path = testing.relative_module_path(__file__,
                                                    'test_config.yaml')

    with pytest.raises(ConfigLoadError, match='missing type declaration'):
        config.load_config(test_config_path)
コード例 #3
0
def test_dataclass():
    test_config_path = testing.relative_module_path(__file__,
                                                    'test_dataclasses.yaml')
    data = config.load_config(test_config_path)

    dc1 = data['dc1']
    assert dc1.x == 5
    assert dc1.y == 'bleblo'
    assert dc1.z == [1, 2, 3]
    assert dc1.d == 'asd'

    dc2 = data['dc2']
    assert dc2.x == 1
    assert dc2.y == 'newble'
    assert dc2.z == [3, 4, 5]
    assert dc2.d == 4
コード例 #4
0
ファイル: test_config.py プロジェクト: MichalinaKainos/owca
def test_config_unsafe_object_creation():
    from ruamel import yaml
    import calendar

    test_config_path = testing.relative_module_path(__file__,
                                                    'test_config_unsafe.yaml')

    # Unsafe default loader allows any python object initialization
    data = yaml.load(open(test_config_path), Loader=yaml.Loader)
    assert 'time' in data
    assert isinstance(data['time'], calendar.Calendar)

    # With use safe version only to allow construct previously registered objects
    with pytest.raises(config.ConfigLoadError,
                       match='could not determine a constructor'):
        config.load_config(test_config_path)
コード例 #5
0
def test_dataclass():
    test_config_path = testing.relative_module_path(__file__,
                                                    'test_dataclasses.yaml')
    data = config.load_config(test_config_path)

    dc1 = data['dc1']
    assert dc1.x == 5
    assert dc1.y is None
    assert dc1.z == [1, 2, 3]
    assert dc1.d == 'asd'
    assert dc1.foo == 'foobaz'

    dc2 = data['dc2']
    assert dc2.x == 1
    assert dc2.y == 'newble'
    assert dc2.z == [3, 4, 5]
    assert dc2.d == 4
    assert dc2.foo == FooEnum.BAR
コード例 #6
0
def test_dataclass_validation_invalid_dict():
    test_config_path = testing.relative_module_path(__file__,
                                                    'test_dataclasses_validation_invalid_dict.yaml')
    with pytest.raises(ConfigLoadError, match='wrong_value'):
        config.load_config(test_config_path)
コード例 #7
0
def test_dataclass_validation():
    test_config_path = testing.relative_module_path(__file__, 'test_dataclasses_validation.yaml')
    data = config.load_config(test_config_path)
    assert data['dc1'].rr == [[2, 3], []]
コード例 #8
0
ファイル: test_mesos.py プロジェクト: litrin/owca
def create_json_fixture_mock(name, status_code=200):
    """ Helper function to shorten the notation. """
    return Mock(json=Mock(return_value=json.load(
        open(relative_module_path(__file__, 'fixtures/' + name + '.json'))),
                          status_code=status_code))
コード例 #9
0
def test_dataclass_invalid_field():
    test_config_path = testing.relative_module_path(
        __file__, 'test_dataclasses_invalid_field.yaml')
    with pytest.raises(config.ConfigLoadError, match="constructor signature"):
        config.load_config(test_config_path)
コード例 #10
0
def test_invalid_dataclass_union():
    test_config_path = testing.relative_module_path(
        __file__, 'test_dataclasses_invalid_union.yaml')
    with pytest.raises(config.ConfigLoadError,
                       match="field 'd'.*improper type from union"):
        config.load_config(test_config_path)
コード例 #11
0
def test_invalid_dataclass():
    test_config_path = testing.relative_module_path(
        __file__, 'test_dataclasses_invalid.yaml')
    with pytest.raises(config.ConfigLoadError, match="has improper type"):
        config.load_config(test_config_path)