コード例 #1
0
ファイル: test_main.py プロジェクト: harshseth/cfg_load
    def test_configuration_class(self, mock_get):
        # Set up bucket
        conn = boto3.resource("s3", region_name="us-east-1")
        conn.create_bucket(Bucket="ryft-public-sample-data")
        obj = conn.Object("ryft-public-sample-data",
                          "ryft-server-0.13.0-rc3_amd64.deb")
        obj.put(Body=b"foo")

        # Run Test
        path = "../examples/test.json"  # always use slash
        filepath = pkg_resources.resource_filename("cfg_load", path)
        cfg2 = cfg_load.load(filepath)

        path = "../examples/cifar10_baseline.yaml"  # always use slash
        filepath = pkg_resources.resource_filename("cfg_load", path)
        cfg = cfg_load.load(filepath)
        self.assertEqual(cfg["umlautüößhere"], "wörks")
        self.assertEqual(len(cfg), 11)
        # test cfg.__iter__
        for key in cfg:
            continue
        self.assertNotEqual(cfg, cfg2)
        self.assertTrue(isinstance(repr(cfg), str))
        self.assertTrue(isinstance(str(cfg), str))
        self.assertTrue(isinstance(cfg.pformat(), str))
        self.assertTrue(isinstance(cfg.pformat(meta=True), str))
        cfg.set("foo", "bar")
コード例 #2
0
    def test_configuration_class(self, mock_get):
        # Set up bucket
        conn = boto3.resource('s3', region_name='us-east-1')
        conn.create_bucket(Bucket='ryft-public-sample-data')
        obj = conn.Object('ryft-public-sample-data',
                          'ryft-server-0.13.0-rc3_amd64.deb')
        obj.put(Body=b'foo')

        # Run Test
        path = '../examples/test.json'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        cfg2 = cfg_load.load(filepath)

        path = '../examples/cifar10_baseline.yaml'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        cfg = cfg_load.load(filepath)
        self.assertEqual(cfg['umlautüößhere'], 'wörks')
        self.assertEqual(len(cfg), 11)
        # test cfg.__iter__
        for key in cfg:
            continue
        self.assertNotEqual(cfg, cfg2)
        self.assertTrue(isinstance(repr(cfg), str))
        self.assertTrue(isinstance(str(cfg), str))
        self.assertTrue(isinstance(cfg.pformat(), str))
        self.assertTrue(isinstance(cfg.pformat(meta=True), str))
        cfg.set('foo', 'bar')
コード例 #3
0
def test_configuration_class(monkeypatch):
    monkeypatch.setattr(requests, "get", mocked_requests_get)

    # Set up bucket
    conn = boto3.resource("s3", region_name="us-east-1")
    conn.create_bucket(Bucket="ryft-public-sample-data")
    obj = conn.Object("ryft-public-sample-data",
                      "ryft-server-0.13.0-rc3_amd64.deb")
    obj.put(Body=b"foo")

    # Run Test
    path = "examples/test.json"  # always use slash
    filepath = pkg_resources.resource_filename(__name__, path)
    cfg2 = cfg_load.load(filepath)

    path = "examples/cifar10_baseline.yaml"  # always use slash
    filepath = pkg_resources.resource_filename(__name__, path)
    cfg = cfg_load.load(filepath)
    assert cfg["umlautüößhere"] == "wörks"
    assert len(cfg) == 11
    # test cfg.__iter__
    for key in cfg:
        continue
    assert cfg != cfg2
    assert isinstance(repr(cfg), str)
    assert isinstance(str(cfg), str)
    assert isinstance(cfg.pformat(), str)
    assert isinstance(cfg.pformat(meta=True), str)
    cfg.set("foo", "bar")
コード例 #4
0
ファイル: test_main.py プロジェクト: harshseth/cfg_load
    def test_load_yaml(self, mock_get):
        # Set up bucket
        conn = boto3.resource("s3", region_name="us-east-1")
        conn.create_bucket(Bucket="ryft-public-sample-data")
        obj = conn.Object("ryft-public-sample-data",
                          "ryft-server-0.13.0-rc3_amd64.deb")
        obj.put(Body=b"foo")

        # Run Test
        path = "../examples/cifar10_baseline.yaml"  # always use slash
        filepath = pkg_resources.resource_filename("cfg_load", path)
        cfg_load.load(filepath)
コード例 #5
0
    def test_load_yaml(self, mock_get):
        # Set up bucket
        conn = boto3.resource('s3', region_name='us-east-1')
        conn.create_bucket(Bucket='ryft-public-sample-data')
        obj = conn.Object('ryft-public-sample-data',
                          'ryft-server-0.13.0-rc3_amd64.deb')
        obj.put(Body=b'foo')

        # Run Test
        path = '../examples/cifar10_baseline.yaml'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        cfg_load.load(filepath)
コード例 #6
0
    def test_update(self):
        path = '../examples/simple_base.yaml'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        cfg_base = cfg_load.load(filepath)

        path = '../examples/simple_user.yaml'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        cfg_update = cfg_load.load(filepath)

        cfg_result = cfg_base.update(cfg_update)
        cfg_expected = {'foo': 1,
                        'only': 'base',
                        'nested': {'overwrite': True, 'inner_only_base': 28}}
        self.assertDictEqual(cfg_expected, cfg_result._dict)
コード例 #7
0
ファイル: cli.py プロジェクト: mmhc1710/cfg_load
def entry_point():
    args = get_parser().parse_args()
    loaded = cfg_load.load(args.filename, args.raw)
    if hasattr(loaded, "pformat"):
        print(loaded.pformat())
    else:
        print(loaded)
コード例 #8
0
ファイル: test_main.py プロジェクト: mmhc1710/cfg_load
def test_update():
    path = "../examples/simple_base.yaml"  # always use slash
    filepath = pkg_resources.resource_filename("cfg_load", path)
    cfg_base = cfg_load.load(filepath)

    path = "../examples/simple_user.yaml"  # always use slash
    filepath = pkg_resources.resource_filename("cfg_load", path)
    cfg_update = cfg_load.load(filepath)

    cfg_result = cfg_base.update(cfg_update)
    cfg_expected = {
        "foo": 1,
        "only": "base",
        "nested": {"overwrite": True, "inner_only_base": 28},
    }
    assert cfg_expected == cfg_result._dict
コード例 #9
0
ファイル: __init__.py プロジェクト: afcarl/edapy
def get_image_info(image_path):
    """
    Get meta information of a image file.

    Parameters
    ----------
    image_path : str

    Returns
    -------
    info : OrderedDict
    """
    info = OrderedDict()
    info['path'] = image_path

    img = PIL.Image.open(image_path)
    info['width'], info['height'] = img.size
    info['area'] = info['width'] * info['height']
    info['file_extension'] = os.path.splitext(info['path'])[1].lower()

    filepath = pkg_resources.resource_filename('edapy', 'config/images.yaml')
    cfg = cfg_load.load(filepath)
    for key in cfg['keys']:
        info[key] = None

    exif = edapy.images.exif.get_exif_data(img)
    for key in exif:
        if key in cfg['keys']:
            info[key] = exif[key]
        elif key in cfg['ignore_keys']:
            continue
        else:
            logging.debug('Key \'{}\' is unknown.'.format(key))

    return info
コード例 #10
0
def get_image_info(image_path: str) -> Dict:
    """
    Get meta information of a image file.

    Parameters
    ----------
    image_path : str

    Returns
    -------
    info : OrderedDict
    """
    info: Dict[str, Any] = OrderedDict()
    info["path"] = image_path

    img = PIL.Image.open(image_path)
    info["width"], info["height"] = img.size
    info["area"] = info["width"] * info["height"]
    info["file_extension"] = os.path.splitext(info["path"])[1].lower()

    filepath = pkg_resources.resource_filename("edapy", "config/images.yaml")
    cfg = cfg_load.load(filepath)
    for key in cfg["keys"]:
        info[key] = None

    exif = edapy.images.exif.get_exif_data(img)
    for key in exif:
        if key in cfg["keys"]:
            info[key] = exif[key]
        elif key in cfg["ignore_keys"]:
            continue
        else:
            logger.debug(f"Key '{key}' is unknown.")

    return info
コード例 #11
0
    def test_apply_env(self):
        path = '../examples/simple_base.yaml'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        cfg_base = cfg_load.load(filepath)

        path = '../examples/env_mapping.yaml'  # always use slash
        filepath = pkg_resources.resource_filename('cfg_load', path)
        env_mapping = cfg_load.load(filepath)

        os.environ['nested_overwrite'] = 'no'
        cfg = cfg_base.apply_env(env_mapping)

        cfg_expected = {'foo': 'bar',
                        'only': 'base',
                        'nested': {'overwrite': False,
                                   'inner_only_base': 28}}

        self.assertDictEqual(cfg._dict, cfg_expected)
コード例 #12
0
def entry_point() -> None:
    """Use this as an entry point for the CLI."""
    args = get_parser().parse_args()
    loaded = cast(cfg_load.Configuration,
                  cfg_load.load(args.filename, args.raw))
    if hasattr(loaded, "pformat"):
        print(loaded.pformat())
    else:
        print(loaded)
コード例 #13
0
ファイル: test_main.py プロジェクト: mmhc1710/cfg_load
def test_apply_env():
    path = "../examples/simple_base.yaml"  # always use slash
    filepath = pkg_resources.resource_filename("cfg_load", path)
    cfg_base = cfg_load.load(filepath)

    path = "../examples/env_mapping.yaml"  # always use slash
    filepath = pkg_resources.resource_filename("cfg_load", path)
    env_mapping = cfg_load.load(filepath)

    os.environ["nested_overwrite"] = "no"
    cfg = cfg_base.apply_env(env_mapping)

    cfg_expected = {
        "foo": "bar",
        "only": "base",
        "nested": {"overwrite": False, "inner_only_base": 28},
    }

    assert cfg._dict == cfg_expected
コード例 #14
0
ファイル: test_main.py プロジェクト: mmhc1710/cfg_load
def test_load_yaml(monkeypatch, requests_mock, mocked_urlopen):
    def mock_urlretrieve(*args, **kwargs):
        return MockUrllibResponse()

    monkeypatch.setattr(request, "urlretrieve", mock_urlretrieve)
    requests_mock.get("http://foo-bar.de/something.JPG", text="data")
    requests_mock.get(
        "https://martin-thoma.com/images/2017/02/Martin_Thoma_web_thumb.jpg",
        text="data",
    )

    # Set up bucket
    conn = boto3.resource("s3", region_name="us-east-1")
    conn.create_bucket(Bucket="ryft-public-sample-data")
    obj = conn.Object("ryft-public-sample-data", "ryft-server-0.13.0-rc3_amd64.deb")
    obj.put(Body=b"foo")

    # Run Test
    path = "../examples/cifar10_baseline.yaml"  # always use slash
    filepath = pkg_resources.resource_filename("cfg_load", path)
    cfg_load.load(filepath)
コード例 #15
0
ファイル: __init__.py プロジェクト: afcarl/edapy
def find(path, output):
    """
    Find all image files in a directory and get metadata of them.

    Parameters
    ----------
    path : str
    output : filepointer
    """
    data = []

    filepath = pkg_resources.resource_filename('edapy', 'config/images.yaml')
    cfg = cfg_load.load(filepath)

    for dirpath, dirnames, filenames in os.walk("."):
        files_in_dir = [
            f for f in filenames for ext in cfg['file_extensions']
            if f.lower().endswith('.' + ext)
        ]
        for filename in files_in_dir:
            image_path = os.path.abspath(os.path.join(dirpath, filename))
            data.append(get_image_info(image_path))
    write_csv(data, output)
コード例 #16
0
import sys
from six import StringIO, b

from gym import utils
from gym.envs.toy_text import discrete

# 3rd party modules
from gym import spaces
import cfg_load
import gym
import numpy as np

path = 'config.yaml'  # always use slash in packages
filepath = pkg_resources.resource_filename('frozen_lake', path)
config = cfg_load.load(filepath)
logging.config.dictConfig(config['LOGGING'])

LEFT = 0
DOWN = 1
RIGHT = 2
UP = 3

MAPS = {
    "4x4": ["SFFF", "FHFH", "FFFH", "HFFG"],
    "8x8": [
        "SFFFFFFF", "FFFFFFFF", "FFFHFFFF", "FFFFFHFF", "FFFHFFFF", "FHHFFFHF",
        "FHFFHFHF", "FFFHFFFG"
    ],
    "15x15": [
        "SFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFF", "FFFHFFFFFFFFHFF",
コード例 #17
0
ファイル: vuepress2pdf.py プロジェクト: r-hoffmann/canvas-api
#!/usr/bin/env python
import asyncio
import logging
import datetime
import os
import sys
import json
from sys import argv
from pyppeteer import launch
from PyPDF2 import PdfFileMerger

import cfg_load

config = cfg_load.load('config.yaml')
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

format_string = '%(asctime)s - %(levelname)s - %(message)s'

level = os.getenv('LOG_LEVEL', logging.INFO)
logging.basicConfig(stream=sys.stdout, level=level, format=format_string)
log = logging.getLogger(__name__)  # pylint: disable=C0103

MARGIN_LEFT = config['layout']['margin']['left']
MARGIN_TOP = config['layout']['margin']['top']
MARGIN_RIGHT = config['layout']['margin']['right']
MARGIN_BOTTOM = config['layout']['margin']['bottom']
NO_MARGIN = False
NOW = str(datetime.datetime.now().strftime("%Y-%m-%d"))

with open('style.html', 'r') as style_file:
    style = style_file.read()
コード例 #18
0
 def test_load_unknown(self):
     path = '../README.md'  # always use slash
     filepath = pkg_resources.resource_filename('cfg_load', path)
     with self.assertRaises(NotImplementedError):
         cfg_load.load(filepath)
コード例 #19
0
 def test_to_dict(self):
     path = '../examples/test.json'  # always use slash
     filepath = pkg_resources.resource_filename('cfg_load', path)
     cfg = cfg_load.load(filepath)
     dict_ = cfg.to_dict()
     self.assertIsInstance(dict_, dict)
コード例 #20
0
 def test_load_json(self):
     path = '../examples/test.json'  # always use slash
     filepath = pkg_resources.resource_filename('cfg_load', path)
     cfg_load.load(filepath)
コード例 #21
0
 def test_load_ini(self):
     path = '../examples/db_cfg.ini'  # always use slash
     filepath = pkg_resources.resource_filename('cfg_load', path)
     cfg_load.load(filepath)
コード例 #22
0
import sqlite3, os, json, cfg_load
cfgsource = "../cfg/config.dat"

# Load defaults
base_cfg = cfg_load.load("../cfg/config.dat")

# Overwrite defaults if user defined it
user_cfg = cfg_load.load("../cfg/config.dat.bu")
user_cfg = base_cfg.update(user_cfg)

# Overwrite user default with environment variables
env_mapping = cfg_load.load('other/env_mapping.yaml')
cfg = user_cfg.apply_env(env_mapping)

cfg = ""

temp = {
    "datafiles": {
        "datapath": "../data/",
        "SQLFiles": {
            "users": "users.sql",
            "inventory": "inventory.sql",
            "loans": "loans.sql"
        },
        "DBFiles": {
            "users": "users.db",
            "inventory": "inventory.db",
            "loans": "loans.db"
        }
    },
    "configFiles": {
コード例 #23
0
def test_load_ini():
    path = "examples/db_cfg.ini"  # always use slash
    filepath = pkg_resources.resource_filename(__name__, path)
    cfg_load.load(filepath)
コード例 #24
0
def test_load_json():
    path = "examples/test.json"  # always use slash
    filepath = pkg_resources.resource_filename(__name__, path)
    cfg_load.load(filepath)
コード例 #25
0
def test_to_dict():
    path = "examples/test.json"  # always use slash
    filepath = pkg_resources.resource_filename(__name__, path)
    cfg = cfg_load.load(filepath)
    dict_ = cfg.to_dict()
    assert isinstance(dict_, dict)
コード例 #26
0
def test_load_unknown():
    path = "README.md"  # always use slash
    filepath = pkg_resources.resource_filename(__name__, path)
    with pytest.raises(NotImplementedError):
        cfg_load.load(filepath)