def test_create(): appname = "aw-core-test" section = "section" config_dir = dirs.get_config_dir(appname) # Remove test config file if it already exists shutil.rmtree(config_dir) # Create default config default_config = ConfigParser() default_config[section] = { "somestring": "Hello World!", "somevalue": 12.3 } # Load non-existing config (will create a default config file) config = load_config(appname, default_config) # Check that current config file is same as default config file assert config[section]["somestring"] == default_config[section]["somestring"] assert config[section].getfloat("somevalue") == default_config[section].getfloat("somevalue") # Modify and save config file config[section]["somevalue"] = "1000.1" save_config(appname, config) # Open non-default config file and verify that values are correct new_config = load_config(appname, default_config) assert new_config[section]["somestring"] == config[section]["somestring"] assert new_config[section].getfloat("somevalue") == config[section].getfloat("somevalue") # Remove test config file shutil.rmtree(config_dir)
def test_create(): appname = "aw-core-test" section = "section" config_dir = dirs.get_config_dir(appname) # Remove test config file if it already exists shutil.rmtree(config_dir) # Create default config default_config = ConfigParser() default_config[section] = { "somestring": "Hello World!", "somevalue": 12.3 } # Load non-existing config (will create a default config file) config = load_config(appname, default_config) # Check that current config file is same as default config file assert config[section]["somestring"] == default_config[section]["somestring"] assert config[section].getfloat("somevalue") == default_config[section].getfloat("somevalue") # Modify and save config file config[section]["somevalue"] = "1000.1" save_config(appname, config) # Open non-default config file and verify that values are correct new_config = load_config(appname, default_config) assert new_config[section]["somestring"] == config[section]["somestring"] assert new_config[section].getfloat("somevalue") == config[section].getfloat("somevalue") # Remove test config file shutil.rmtree(config_dir)
def __init__(self, testing: bool): """ An instance of loaded settings, containing a list of modules to autostart. Constructor takes a `testing` boolean as an argument """ qt_config = load_config("aw-qt", default_config) config_section = qt_config["aw-qt" if not testing else "aw-qt-testing"] self.autostart_modules: List[str] = json.loads( config_section["autostart_modules"] )
def test_config_ini(): # Create default config default_config = ConfigParser() default_config[section] = {"somestring": "Hello World!", "somevalue": 12.3} # Load non-existing config (will create a default config file) config = load_config(appname, default_config) # Check that current config file is same as default config file assert config[section]["somestring"] == default_config[section][ "somestring"] assert config[section].getfloat( "somevalue") == default_config[section].getfloat("somevalue") # Modify and save config file config[section]["somevalue"] = "1000.1" save_config(appname, config) # Open non-default config file and verify that values are correct new_config = load_config(appname, default_config) assert new_config[section]["somestring"] == config[section]["somestring"] assert new_config[section].getfloat( "somevalue") == config[section].getfloat("somevalue")
from configparser import ConfigParser from aw_core.config import load_config default_settings = { "timeout": "180", "poll_time": "5", } default_testing_settings = { "timeout": "20", "poll_time": "1", } default_config = ConfigParser() default_config['aw-watcher-afk'] = default_settings default_config['aw-watcher-afk-testing'] = default_testing_settings watcher_config = load_config("aw-watcher-afk", default_config)
from configparser import ConfigParser from aw_core.config import load_config default_config = ConfigParser() default_config["server"] = { "host": "localhost", "port": "5600", "storage": "peewee", "cors_origins": "" } default_config["server-testing"] = { "host": "localhost", "port": "5666", "storage": "peewee", "cors_origins": "" } config = load_config("aw-server", default_config)
from configparser import ConfigParser from aw_core.config import load_config default_config = ConfigParser() default_config["server"] = { "host": "localhost", "port": "5600", "storage": "peewee", "cors_origins": "" } default_config["server-testing"] = { "host": "localhost", "port": "5666", "storage": "peewee", "cors_origins": "" } config = load_config("aw-server", default_config)
default_testing_settings = { "possible_modules": json.dumps([ "aw-server", "aw-watcher-afk", "aw-watcher-window", ]), "autostart_modules": json.dumps([ "aw-server", "aw-watcher-afk", "aw-watcher-window", ]), } default_config = ConfigParser() default_config['aw-qt'] = default_settings default_config['aw-qt-testing'] = default_testing_settings qt_config = load_config("aw-qt", default_config) class QTSettings: def __init__(self, testing: bool): config_section = qt_config["aw-qt" if not testing else "aw-qt-testing"] # TODO: Resolved available modules automatically. # TODO: Filter away all modules not available on system self.possible_modules = json.loads(config_section["possible_modules"]) self.autostart_modules = json.loads( config_section["autostart_modules"])
from configparser import ConfigParser from aw_core.config import load_config default_settings = {"poll_time": "5", "host": "localhost", "port": "6600"} default_testing_settings = { "poll_time": "1", "host": "localhost", "port": "6600" } default_config = ConfigParser() default_config['aw-watcher-mpd'] = default_settings default_config['aw-watcher-mpd-testing'] = default_testing_settings watcher_config = load_config("aw-watcher-mpd", default_config)
from configparser import ConfigParser from aw_core.config import load_config default_settings = { "poll_time": "5", # seconds "height_levels": "ball:0-70;sitting:70-90;standing:90-200", # cm "esp_ip": "192.168.2.4" } default_testing_settings = { "poll_time": "5", # seconds "height_levels": "ball:0-70;sitting:70-90;standing:90-200", # cm "esp_ip": "192.168.2.4" } default_config = ConfigParser() default_config['aw-watcher-table'] = default_settings default_config['aw-watcher-table-testing'] = default_testing_settings watcher_config = load_config("aw-watcher-table", default_config)