Exemple #1
0
def test_pypi_version():
    pypi_meta = requests.get(
        "https://pypi.python.org/pypi/cimpyorm/json").json()
    pypi_releases = pypi_meta["releases"].keys()
    path = Path(get_path("PACKAGEROOT")).parent
    toml_meta = toml.loads(open(os.path.join(path, "pyproject.toml")).read())
    toml_version = toml_meta["tool"]["poetry"]["version"]
    assert toml_version in pypi_releases
Exemple #2
0
def test_find_valid_rdfs_version(Version):
    try:
        os.path.isdir(get_path("SCHEMAROOT"))
    except KeyError:
        pytest.skip(f"Schema folder not configured")
    version = f"{Version}"
    rdfs_path = find_rdfs_path(version)
    assert os.path.isdir(rdfs_path) and os.listdir(rdfs_path)
Exemple #3
0
def configure(schemata: Union[Path, str] = None,
              datasets: Union[Path, str] = None):
    """
    Configure paths to schemata or update the DATASETROOT used for tests.

    :param schemata: Path to a folder containing CIM schema descriptions.

    :param datasets: Path to a folder containing test datasets.
    """
    config = configparser.ConfigParser()
    config.read(get_path("CONFIGPATH"))
    if schemata:
        config["Paths"]["SCHEMAROOT"] = os.path.abspath(schemata)
    if datasets:
        config["Paths"]["DATASETROOT"] = os.path.abspath(datasets)
    with open(get_path("CONFIGPATH"), 'w') as configfile:
        config.write(configfile)
Exemple #4
0
def test_find_invalid_rdfs_version(Version):
    try:
        os.path.isdir(get_path("SCHEMAROOT"))
    except KeyError:
        pytest.skip(f"Schema folder not configured")
    with pytest.raises((ValueError, NotImplementedError)) as ex_info:
        version = f"{Version}"
        find_rdfs_path(version)
    print(ex_info)
Exemple #5
0
def full_grid():
    try:
        path = os.path.join(get_path("DATASETROOT"), "FullGrid")
    except KeyError:
        pytest.skip(f"Dataset path not configured")
    if not os.path.isdir(path) or not os.listdir(path):
        pytest.skip("Dataset 'FullGrid' not present.")
    else:
        return path
Exemple #6
0
def configure(schemata: Union[Path, str] = None,
              datasets: Union[Path, str] = None):
    """
    Configure paths to schemata or update the DATASETROOT used for tests.

    :param schemata: Path to a folder containing CIM schema descriptions.

    :param datasets: Path to a folder containing test datasets.
    """
    raise DeprecationWarning("Configuration of schema resources has been deprecated. Please get in "
                             "touch if you rely on this functionality.")
    config = configparser.ConfigParser()
    config.read(get_path("CONFIGPATH"))
    if schemata:
        config["Paths"]["SCHEMAROOT"] = os.path.abspath(schemata)
    if datasets:
        config["Paths"]["DATASETROOT"] = os.path.abspath(datasets)
    with open(get_path("CONFIGPATH"), 'w') as configfile:
        config.write(configfile)
Exemple #7
0
def dummy_source():
    try:
        path = os.path.join(get_path("DATASETROOT"), "FullGrid",
                            "20171002T0930Z_BE_EQ_4.xml")
    except KeyError:
        pytest.skip(f"Dataset path not configured")
    if not os.path.isfile(path):
        pytest.skip("Dataset 'FullGrid' not present.")
    from cimpyorm.Model.Source import SourceInfo
    ds = SourceInfo(source_file=path)
    return ds
Exemple #8
0
def load_test_db():
    """
    Returns a session and a model for a database that's only supposed to be read from
    :return: session, m
    """
    from cimpyorm.api import load
    path = os.path.join(get_path("DATASETROOT"), "FullGrid", "StaticTest.db")
    if not os.path.isfile(path):
        pytest.skip("StaticTest.db not present.")
    session, m = load(path)
    return session, m
Exemple #9
0
project = 'CIMPyORM'
copyright = '2018-2019, Institute for High Voltage Technology, RWTH Aachen'
author = 'Thomas Offergeld'

try:
    _rtd = os.environ["READTHEDOCS"] == "True"
except KeyError:
    _rtd = False

if not _rtd:
    try:
        import toml
        from pathlib import Path
        from cimpyorm.auxiliary import get_path

        _path = Path(get_path("PACKAGEROOT")).parent
        _toml_meta = toml.loads(open(os.path.join(_path, "pyproject.toml")).read())
        _toml_name = _toml_meta["tool"]["poetry"]["name"]
        _toml_version = _toml_meta["tool"]["poetry"]["version"]

        # The short X.Y version
        version = ".".join(_toml_version.split(".")[0:2])
        # The full version, including alpha/beta/rc tags
        release = _toml_version
    except ImportError:
        pass

# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
Exemple #10
0
try:
    import pytest

    def test_all(runslow=False):
        if runslow:
            pytest.main([os.path.join(_TESTROOT), "--runslow"])
        else:
            pytest.main([os.path.join(_TESTROOT)])
except ModuleNotFoundError:
    pass


try:
    # See if we already know a schemaroot
    CONFIG["Paths"]["SCHEMAROOT"] = get_path("SCHEMAROOT")
    if not os.path.isdir(CONFIG["Paths"]["SCHEMAROOT"]):
        # Is schemaroot an actual directory?
        log.warning(f"Invalid schema path in configuration.")
        raise NotADirectoryError
except (KeyError, NotADirectoryError):
    if os.path.isdir(os.path.join(_PACKAGEROOT, "res", "schemata")):
        # Look in the default path
        CONFIG["Paths"]["SCHEMAROOT"] = os.path.join(_PACKAGEROOT, "res", "schemata")
        log.info(f"Found schemata in default location.")
    else:
        # Ask user to configure
        log.warning(f"No schemata configured. Use cimpyorm.configure(path_to_schemata) to set-up.")
        from cimpyorm.api import configure

try:
Exemple #11
0
def test_parse_with_schema_directory(full_grid):
    s, m = parse(full_grid,
                 schema=os.path.join(get_path("SCHEMAROOT"), "CIM16"),
                 backend=InMemory)
    assert m.ACLineSegment
    assert s.query(m.Terminal).count() > 0
Exemple #12
0
#   This module is part of CIMPyORM.
#  #
#   CIMPyORM is licensed under the BSD-3-Clause license.
#   For further information see LICENSE in the project's root directory.
#

import pytest
import lxml.etree as et
import os

from cimpyorm.auxiliary import log, get_path, parseable_files

schemata = []
datasets = []
try:
    SCHEMAROOT = get_path("SCHEMAROOT")
    if os.path.isdir(SCHEMAROOT) and os.listdir(SCHEMAROOT):
        schemata = [
            os.path.join(SCHEMAROOT, f"CIM{version}") for version in [16]
        ]
except KeyError:
    pass

try:
    DATASETROOT = get_path("DATASETROOT")
    if os.path.isdir(os.path.join(DATASETROOT)) and os.listdir(
            os.path.join(DATASETROOT)):
        datasets = [
            os.path.join(DATASETROOT, dir_)
            for dir_ in os.listdir(os.path.join(DATASETROOT))
            if os.path.isdir(os.path.join(DATASETROOT, dir_))
Exemple #13
0
 def test_all(runslow=False):
     if runslow:
         pytest.main([get_path("TESTROOT"), "--runslow"])
     else:
         pytest.main([get_path("TESTROOT")])
Exemple #14
0
    Dummy function for parsing in shared docker tmp directory.
    """
    parse(r"/tmp")


def describe(element, fmt: str = "psql") -> None:
    """
    Give a description of an object.

    :param element: The element to describe.

    :param fmt: Format string for tabulate package.
    """
    try:
        element.describe(fmt)
    except AttributeError:
        print(f"Element of type {type(element)} doesn't provide descriptions.")


if __name__ == "__main__":
    root = get_path("DATASETROOT")
    session, model = load(os.path.join(root, "FullGrid", "out.db"))
    session.query(model.ACLineSegment).first().__repr__()
    print(lint(session, model))
    # # db_session, m = parse([os.path.abspath(os.path.join(root, folder)) for folder in os.listdir(root) if
    # #                        os.path.isdir(os.path.join(root, folder)) or
    # #                        os.path.join(root, folder).endswith(".zip")])
    # db_session, m = parse(os.path.join(get_path("DATASETROOT"), "FullGrid"), InMemory())
    # print(db_session.query(m.IdentifiedObject).first().name)  # pylint: disable=no-member
    # db_session.close()