コード例 #1
0
ファイル: test_io.py プロジェクト: HallLabs/tracy_matdb
def test_schema():
    """Tests the template read for the whole schema to make sure that contexts
    work as expected.
    """
    varfull = read(reporoot, "tests/io/schema")
    #The full dictionary is large and unwieldly and gets tested below in
    #separate pieces. For now, we just test that the context hookups worked
    #correctly. Edges uses a relative path specifier with `../` syntax, so it is
    #most likely to mess up.
    model = [{
        'targets':
        'B',
        'name':
        'AtoB',
        'doc':
        'Connects A to B.',
        'sources':
        'A',
        'properties': [{
            'dtype': 'int',
            'doc': 'some integer.',
            'example': 3,
            'name': 'value'
        }]
    }]
    assert varfull["edges"] == model
コード例 #2
0
ファイル: test_io.py プロジェクト: HallLabs/tracy_matdb
def test_read_verts():
    """Tests the recursive read of a directory of vertex template files with
    sub-directories, relative paths, etc.
    """
    A = read(reporoot, "tests/io/verts/a")
    modelA = {
        'name':
        'A',
        'properties': [{
            'name': 'kind',
            'dtype': 'VarKind',
            'example': 'kind(1.8)',
            'keytype': 'float',
            'doc': 'testing how kind the vertex is.'
        }],
        'doc':
        'Simple vertex for unit tests.'
    }
    assert A == modelA

    B = read(reporoot, "tests/io/verts/b")
    modelB = {
        'vtype':
        'logic',
        'doc':
        'Simple schema for unit tests.  ',
        'properties': [{
            'example': 3,
            'doc': 'some integer.',
            'dtype': 'int',
            'name': 'value'
        }, {
            'example': "'cc'",
            'doc': 'b.text',
            'dtype': 'str',
            'name': 'text'
        }],
        'name':
        'B'
    }
    assert B == modelB
コード例 #3
0
def globals_setup(new_root):
    """Sets up the globals for the calculator instance.
    """
    from matdb.io import read
    from matdb.calculators.utility import paths, set_paths

    target = relpath("./tests/AgPd/matdb_qe")
    config = path.expanduser(path.abspath(target))
    if path.isabs(config):
        root, config = path.split(config)
    else:
        root, config = path.dirname(config), config

    configyml = read(root, config)
    configyml["root"] = new_root

    set_paths(configyml)
コード例 #4
0
ファイル: test_io.py プロジェクト: HallLabs/tracy_matdb
def test_read_types():
    """Tests the recursive read of a directory of edge template files with
    sub-directories, relative paths, etc.
    """
    varkind = read(reporoot, "tests/io/types/varkind")
    model = {
        'name':
        'VarKind',
        'properties': [{
            'name': 'tolerance',
            'example': 0.2,
            'dtype': 'float',
            'doc': 'heard of epsilon.'
        }],
        'doc':
        'Simple custom type for unit testing.'
    }
    assert varkind == model
コード例 #5
0
def test_get_calc_hashes():
    """Tests the get_calculator_hashes function."""
    from matdb.calculators.utility import get_calculator_hashes
    key = "matdb"
    target = relpath("./tests/AgPd/matdb")
    config = path.expanduser(path.abspath(target))
    if path.isabs(config):
        root, config = path.split(config)
    else:
        root, config = path.dirname(config), config

    configyml = read(root, config)
    bc = ""
    cp = {}
    get_calculator_hashes(key, configyml, bc, cp)

    assert "vasp" in cp
    assert len(cp["vasp"]) == 2
    for k, v in cp["vasp"].items():
        assert "tests/vasp" in v
コード例 #6
0
def test_set_paths():
    """Tests the setting of the global paths."""
    from matdb.calculators.utility import paths, set_paths

    target = relpath("./tests/AgPd/matdb")
    config = path.expanduser(path.abspath(target))
    if path.isabs(config):
        root, config = path.split(config)
    else:
        root, config = path.dirname(config), config

    configyml = read(root, config)

    set_paths(configyml)

    name = configyml["title"].strip().replace(' ', '_')
    namehash = str(sha1(name.encode("ASCII")).hexdigest())
    assert namehash in paths
    assert "vasp" in paths[namehash]
    for k, v in paths[namehash]["vasp"].items():
        assert "tests/vasp" in v
コード例 #7
0
ファイル: test_io.py プロジェクト: HallLabs/tracy_matdb
def test_read_edges():
    """Tests the recursive read of a directory of edge template files with
    sub-directories, relative paths, etc.
    """
    AtoB = read(reporoot, "tests/io/edges/atob")
    model = {
        'targets':
        'B',
        'properties': [{
            'dtype': 'int',
            'doc': 'some integer.',
            'name': 'value',
            'example': 3
        }],
        'doc':
        'Connects A to B.',
        'name':
        'AtoB',
        'sources':
        'A'
    }
    assert AtoB == model
コード例 #8
0
def test_build_calc():
    """Tests the setting of the calc builder."""

    from matdb.calculators.utility import build_calc
    from matdb.io import read
    from matdb.calculators.utility import paths, set_paths
    from matdb.utility import _set_config_paths

    _set_config_paths("AgPd_Enumerated", '.')

    target = relpath("./tests/AgPd/matdb")
    config = path.expanduser(path.abspath(target))
    if path.isabs(config):
        root, config = path.split(config)
    else:
        root, config = path.dirname(config), config

    configyml = read(root, config)

    set_paths(configyml)

    kwargs = {
        "kpoints": {
            "rmin": 50
        },
        "potcars": {
            "directory": "./tests/vasp",
            "xc": "pbe"
        }
    }

    res = build_calc("Vasp", None, **kwargs)

    assert res.key == "vasp"

    res = None
    res = build_calc("Vasp", '.', **kwargs)

    assert res.key == "vasp"
コード例 #9
0
ファイル: test_io.py プロジェクト: HallLabs/tracy_matdb
def test_raises_errors():
    """Makes sure errors are raised where appropriate.
    """
    with pytest.raises(ValueError):
        template = read(reporoot, "tests/dummy")
コード例 #10
0
ファイル: test_io.py プロジェクト: HallLabs/tracy_matdb
def test_corner_cases():
    """Tests the corner cases in the template reader.
    """
    varcorner = read(reporoot, "tests/io/corner")
    model = {'first': {'a': 0, 'b': 1}, 'second': [{'a': 0, 'b': 1}]}
    assert varcorner == model