def test_no_access():
    with tempfile.NamedTemporaryFile() as config:
        os.chmod(config.name, 0)

        assert pytest.raises(FileReadingError, lambda:
            python_config.load(config.name)
        ).value.errno == errno.EACCES
Пример #2
0
def load():
    """Loads the configuration file."""

    path = "/etc/xbee-monitor.conf"

    config = python_config.load(path)

    try:
        _validate_config(config)
    except Exception as e:
        raise Error("Error while parsing configuration file '{0}': {1}", path, e)

    global HOSTS
    global ADDRESSES

    HOSTS.update(config["hosts"])
    ADDRESSES.update(
        (int(address, 16), host) for host, address in config["hosts"].items())
def test_missing_file():
    assert pytest.raises(FileReadingError, lambda:
        python_config.load("missing.conf")
    ).value.errno == errno.ENOENT
Пример #4
0
def test_reading():
    assert python_config.load("tests/test.conf") == { "key": "value" }
Пример #5
0
def test_invalid_dict_key():
    assert pytest.raises(python_config.ValidationError, lambda:
        python_config.load("test", "A = {}; B = { (0, 1): 2 }")
    ).value.option_name == "A B's key"
Пример #6
0
def test_invalid_type():
    assert pytest.raises(python_config.ValidationError, lambda:
        python_config.load("test", "OS = object()")
    ).value.option_name == "OS"
Пример #7
0
def test_parsing():
    config = python_config.load("test", """
import sys

some_variable = 0
_UNDERSCORE_VALUE = 0

BOOL_VALUE = False
INT_VALUE = 1
FLOAT_VALUE = 3.3

if sys.version_info < (3,):
    BYTES_VALUE = "bytes value"
    STRING_VALUE = unicode("string value")
    LONG_VALUE = long(0)
else:
    BYTES_VALUE = "bytes value".encode("utf-8")
    STRING_VALUE = "string value"

TUPLE_VALUE = ( "a", 1 )

LIST_VALUE = ( "b", 2 )

SET_VALUE = set(( "a", "b", "c" ))

DICT_VALUE = {
    1:   "number",
    "s": "string",
    "d": {
        "l": [ "one", 2 ],
        "t": [ 1, "two" ],
    },
}
    """.strip())

    assert type(config["bool_value"]) is bool
    assert type(config["int_value"]) is int
    assert type(config["float_value"]) is float

    assert type(config["bytes_value"]) is str
    assert type(config["string_value"]) is str

    if PY2:
        assert type(config["long_value"]) is long

    assert type(config["set_value"]) is list
    config["set_value"] = sorted(config["set_value"])

    valid_config = {
        "bool_value": False,
        "int_value": 1,
        "float_value": 3.3,

        "bytes_value": "bytes value",
        "string_value": "string value",

        "tuple_value": [ "a", 1 ],

        "list_value": [ "b", 2 ],

        "set_value": sorted(( "a", "b", "c" )),

        "dict_value": {
            1:   "number",
            "s": "string",
            "d": {
                "l": [ "one", 2 ],
                "t": [ 1, "two" ],
            },
        },
    }

    if PY2:
        valid_config["long_value"] = 0

    assert config == valid_config
Пример #8
0
def test_invalid_syntax():
    with pytest.raises(python_config.ParsingError):
        python_config.load("test", contents="a=")
# IMPORTS
from telegram.ext import Updater, CommandHandler, MessageHandler, ConversationHandler, Filters
import telegram
import sqlite3
import datetime
import pytz
import python_config
import os

# load configuration
# CONF_NAME = "example_config.conf"
CONF_NAME = "contact_reminder.conf"
conf = python_config.load(
    os.path.join(os.path.dirname(os.path.realpath(__file__)), CONF_NAME))
# global variable definition
DB_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                       conf["db_filename"])
TIMEZONE = conf["timezone"]
TOKEN = conf["bot_token"]
# global variable definition
FIRST_NAME, LAST_NAME, INTERVAL, LAST_CONTACT = range(4)
REMINDER_TIME = 0
sql_dict = {}
jobs = {}


# DATABASE FUNCTION DEFINITIONS
def connect_database(db_path):
    """ create a database connection to the SQLite database
        specified by the db_file
    :param db_path: database path