Пример #1
0
def validate_pyessv_enum(collection_id, val, var):
    """Validates an enumerable member.

    """
    namespace = '{}:{}'.format(collection_id, val)
    try:
        pyessv.parse(namespace)
    except pyessv.ParsingError:
        _raise_value_error(val, var, 'enum-member')
Пример #2
0
def validate_pyessv_enum(collection_id, val, var):
    """Validates an enumerable member.

    """
    namespace = '{}:{}'.format(collection_id, val)
    try:
        pyessv.parse(namespace)
    except pyessv.ParsingError:
        _raise_value_error(val, var, 'enum-member')
Пример #3
0
def _get_test_dataset(project):
    """Returns a test dataset identifier.

    """
    pattern = _DATASETS_PATTERNS[project]

    if project == 'cmip5':
        return pattern.format(
            pyessv.load_random('wcrp:cmip5:product', field='raw_name'),
            pyessv.parse('wcrp:cmip5:institute:ipsl', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:model', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:experiment', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:time-frequency', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:realm', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:cmor-table', field='raw_name')
            )

    elif project == 'cmip6':
        return pattern.format(
            pyessv.load_random('wcrp:cmip6:activity-id', field='raw_name'),
            pyessv.parse('wcrp:cmip6:institution-id:ipsl', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:source-id', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:experiment-id', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:table-id', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:grid-label', field='raw_name')
            )

    elif project == 'cordex':
        return pattern.format(
            pyessv.load_random('wcrp:cordex:product', field='raw_name'),
            pyessv.load_random('wcrp:cordex:domain', field='raw_name'),
            pyessv.parse('wcrp:cordex:institute:ipsl-ineris', field='raw_name'),
            pyessv.load_random('wcrp:cordex:driving-model', field='raw_name'),
            pyessv.load_random('wcrp:cordex:experiment', field='raw_name'),
            pyessv.load_random('wcrp:cordex:rcm-name', field='raw_name'),
            pyessv.load_random('wcrp:cordex:time-frequency', field='raw_name'),
            pyessv.load_random('wcrp:cordex:variable', field='raw_name')
            )
Пример #4
0
def _get_dataset(project):
    """Returns a dataset identifier.

    """
    pattern = _DATASETS_PATTERNS[project]

    if project == 'cmip5':
        return pattern.format(
            pyessv.load_random('wcrp:cmip5:product', field='raw_name'),
            pyessv.parse('wcrp:cmip5:institute:ipsl', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:model', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:experiment', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:time-frequency', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:realm', field='raw_name'),
            pyessv.load_random('wcrp:cmip5:cmor-table', field='raw_name')
            )

    elif project == 'cmip6':
        return pattern.format(
            pyessv.load_random('wcrp:cmip6:activity-id', field='raw_name'),
            pyessv.parse('wcrp:cmip6:institution-id:ipsl', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:source-id', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:experiment-id', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:table-id', field='raw_name'),
            pyessv.load_random('wcrp:cmip6:grid-label', field='raw_name')
            )

    elif project == 'cordex':
        return pattern.format(
            pyessv.load_random('wcrp:cordex:product', field='raw_name'),
            pyessv.load_random('wcrp:cordex:domain', field='raw_name'),
            pyessv.parse('wcrp:cordex:institute:ipsl-ineris', field='raw_name'),
            pyessv.load_random('wcrp:cordex:driving-model', field='raw_name'),
            pyessv.load_random('wcrp:cordex:experiment', field='raw_name'),
            pyessv.load_random('wcrp:cordex:rcm-name', field='raw_name'),
            pyessv.load_random('wcrp:cordex:time-frequency', field='raw_name'),
            pyessv.load_random('wcrp:cordex:variable', field='raw_name')
            )
Пример #5
0
def test_parse_name(typekey, name, expected, strictness, parent):
    """Test parsing of names at various levels.

    """
    if typekey == LIB.NODE_TYPEKEY_AUTHORITY:
        namespace = name
    elif typekey == LIB.NODE_TYPEKEY_SCOPE:
        namespace = '{}:{}'.format(tu.AUTHORITY_NAME, name)
    elif typekey == LIB.NODE_TYPEKEY_COLLECTION:
        namespace = '{}:{}:{}'.format(tu.AUTHORITY_NAME, tu.SCOPE_NAME, name)
    elif typekey == LIB.NODE_TYPEKEY_TERM:
        namespace = '{}:{}:{}:{}'.format(tu.AUTHORITY_NAME, tu.SCOPE_NAME, parent, name)

    try:
        result = LIB.parse(namespace, strictness=strictness)
    except LIB.ParsingError:
        result = LIB.ParsingError

    assert result == expected, \
           'Name parsing error: node-type={}.  name={}.  actual = {}.  expected {}.'.format(typekey, name, result, expected)