def mock_init(monkeypatch):
    monkeypatch.setattr(BaseAppConfiguration, '_load_schema',
                        lambda a: AppSchema(None, '_'))
    monkeypatch.setattr(AppSchema, '_read_schema',
                        lambda a, b: get_schema(MOCK_SCHEMA))
    monkeypatch.setattr(BaseAppConfiguration, 'deprecated_dirs',
                        MOCK_DEPRECATED_DIRS)
    monkeypatch.setattr(BaseAppConfiguration, 'listify_options', {'path4'})
Beispiel #2
0
def test_schema_is_loaded(monkeypatch):
    def mock_read_schema(self, path):
        return ordered_load(MOCK_YAML)

    def mock_init(self, stream):
        super(OrderedLoader, self).__init__(stream)

    monkeypatch.setattr(AppSchema, '_read_schema', mock_read_schema)
    monkeypatch.setattr(OrderedLoader, '__init__', mock_init)

    loaded_schema = AppSchema('no path', 'mockgalaxy')
    data = ordered_load(MOCK_YAML)

    assert loaded_schema.description == data['desc']
    assert loaded_schema.raw_schema['foo'] == 'bar'
    assert loaded_schema.app_schema['option']['attr1'] == 'a'
    assert loaded_schema.get_app_option('option')['attr2'] == 'b'
Beispiel #3
0
def test_resolves_to_invalid_property(monkeypatch):
    # 'path_resolves_to' should point to an existing property in the schema
    mock_schema = {
        'path0': {
            'type': 'str',
            'default': 'value0',
        },
        'path1': {
            'type': 'str',
            'default': 'value1',
            'path_resolves_to': 'invalid',  # invalid
        },
    }
    monkeypatch.setattr(AppSchema, '_read_schema', lambda a, b: get_schema(mock_schema))

    with pytest.raises(ConfigurationError):
        AppSchema(None, '_').validate_path_resolution_graph()
Beispiel #4
0
def test_resolves_to_invalid_type(monkeypatch):
    # Paths should be strings
    mock_schema = {
        'path0': {
            'type': 'int',  # invalid
            'default': 'value0',
        },
        'path1': {
            'type': 'str',
            'default': 'value1',
            'path_resolves_to': 'path0',
        },
    }
    monkeypatch.setattr(AppSchema, '_read_schema', lambda a, b: get_schema(mock_schema))

    with pytest.raises(ConfigurationError):
        AppSchema(None, '_').validate_path_resolution_graph()
Beispiel #5
0
def test_path_resolution_cycle(monkeypatch):
    # Must be a DAG, but this one has a cycle
    mock_schema = {
        'path0': {
            'type': 'str',
            'default': 'value0',
            'path_resolves_to': 'path2',
        },
        'path1': {
            'type': 'str',
            'default': 'value1',
            'path_resolves_to': 'path0',
        },
        'path2': {
            'type': 'str',
            'default': 'value2',
            'path_resolves_to': 'path1',
        },
    }
    monkeypatch.setattr(AppSchema, '_read_schema', lambda a, b: get_schema(mock_schema))

    with pytest.raises(ConfigurationError):
        AppSchema(None, '_').validate_path_resolution_graph()
Beispiel #6
0
def test_schema_is_loaded(monkeypatch):
    def mock_read_schema(self, path):
        return ordered_load(MOCK_YAML)

    def mock_init(self, stream):
        super(OrderedLoader, self).__init__(stream)

    monkeypatch.setattr(AppSchema, '_read_schema', mock_read_schema)
    monkeypatch.setattr(OrderedLoader, '__init__', mock_init)

    schema = AppSchema('no path', 'mockgalaxy')
    data = ordered_load(MOCK_YAML)

    assert schema.description == data['desc']
    assert schema.raw_schema['foo'] == 'bar'

    assert len(schema.defaults) == 6
    assert schema.defaults['property1'] == 'a'
    assert schema.defaults['property2'] == 1
    assert schema.defaults['property3'] == 1.0
    assert schema.defaults['property4'] is True
    assert schema.defaults['property5'] is None
    assert schema.defaults['property6'] is None

    assert type(schema.defaults['property1']) is str
    assert type(schema.defaults['property2']) is int
    assert type(schema.defaults['property3']) is float
    assert type(schema.defaults['property4']) is bool

    assert len(schema.reloadable_options) == 2
    assert 'property2' in schema.reloadable_options
    assert 'property3' in schema.reloadable_options

    assert len(schema.paths_to_resolve) == 2
    assert 'property1' in schema.paths_to_resolve
    assert 'property4' in schema.paths_to_resolve
Beispiel #7
0
def test_basecase(monkeypatch):
    # Check that a valid graph is loaded correctly (this graph has 2 components)
    mock_schema = {
        'component1_path0': {
            'type': 'str',
            'default': 'value0',
        },
        'component1_path1': {
            'type': 'str',
            'default': 'value1',
            'path_resolves_to': 'component1_path0',
        },
        'component1_path2': {
            'type': 'str',
            'default': 'value2',
            'path_resolves_to': 'component1_path1',
        },
        'component2_path0': {
            'type': 'str',
            'default': 'value3',
        },
        'component2_path1': {
            'type': 'str',
            'default': 'value4',
            'path_resolves_to': 'component2_path0',
        },
    }
    monkeypatch.setattr(AppSchema, '_read_schema', lambda a, b: get_schema(mock_schema))
    monkeypatch.setattr(BaseAppConfiguration, '_load_schema', lambda a: AppSchema(None, '_'))

    config = BaseAppConfiguration()
    assert config.component1_path0 == 'value0'
    assert config.component1_path1 == 'value0/value1'
    assert config.component1_path2 == 'value0/value1/value2'
    assert config.component2_path0 == 'value3'
    assert config.component2_path1 == 'value3/value4'
Beispiel #8
0
def test_resolves_with_empty_component(monkeypatch):
    # A path can be None (root path is never None; may be asigned elsewhere)
    mock_schema = {
        'path0': {
            'type': 'str',
            'default': 'value0',
        },
        'path1': {
            'type': 'str',
            'path_resolves_to': 'path0',
        },
        'path2': {
            'type': 'str',
            'default': 'value2',
            'path_resolves_to': 'path1',
        },
    }
    monkeypatch.setattr(AppSchema, '_read_schema', lambda a, b: get_schema(mock_schema))
    monkeypatch.setattr(BaseAppConfiguration, '_load_schema', lambda a: AppSchema(None, '_'))

    config = BaseAppConfiguration()
    assert config.path0 == 'value0'
    assert config.path1 == 'value0'
    assert config.path2 == 'value0/value2'
Beispiel #9
0
 def _load_schema(self):
     return AppSchema(TOOLSHED_CONFIG_SCHEMA_PATH, TOOLSHED_APP_NAME)
Beispiel #10
0
def _schema(self):
    return AppSchema(self.schema_path, self.app_name)
Beispiel #11
0
def mock_init(monkeypatch):
    monkeypatch.setattr(BaseAppConfiguration, '_load_schema', lambda a: AppSchema(None, '_'))
    monkeypatch.setattr(AppSchema, '_read_schema', lambda a, b: get_schema(MOCK_SCHEMA))