Пример #1
0
def test_config_update():
    fn = _file_path('valid.cfg')
    fn_new = _file_path('updates.cfg')
    cfg_new = parse_config(fn_new)
    cfg_ = parse_config(fn)
    update_config(cfg_, cfg_new, update_comments=False)
    assert 'section3' in cfg_
    assert 'newvar' in cfg_.section2
    assert cfg_.section1._comment == 'old section1 comment'
    cfg_ = parse_config(fn)
    update_config(cfg_, cfg_new, create_new_sections=False)
    assert 'section3' not in cfg_
    assert 'newvar' in cfg_.section2
    cfg_ = parse_config(fn)
    update_config(cfg_,
                  cfg_new,
                  create_new_sections=True,
                  create_new_items=False)
    assert 'section3' in cfg_
    assert 'newvar' not in cfg_.section2
    cfg_ = parse_config(fn)
    update_config(cfg_, cfg_new, update_comments=True)
    assert cfg_.section1._comment == 'updated section1 comment'
    cfg_ = parse_config(fn)
    update_config(cfg_, cfg_new, create_new_items=['section2'])
    assert 'newvar' in cfg_.section2
    cfg_ = parse_config(fn)
    update_config(cfg_, cfg_new, create_new_items=['section1'])
    assert 'newvar' not in cfg_.section2
Пример #2
0
def test_write_read_cycle():
    fn = _file_path('valid.cfg')
    cfg_ = parse_config(fn)
    txt = dump_config(cfg_)
    txtlines = txt.split('\n')
    cfg_back = _parse_config(txtlines)
    for secname, sec in cfg_:
        assert secname in cfg_back
        for itemname, item in sec:
            assert itemname in getattr(cfg_back, secname)
Пример #3
0
def test_config():
    """Test reading of valid config"""
    fn = _file_path('valid.cfg')
    cfg_ = parse_config(fn)
    assert 'section1' in cfg_
    assert 'section2' in cfg_
    secs = sorted(secname for (secname, sec) in cfg_)
    assert secs == ['section1', 'section2']
    assert cfg_.section1.var1 == 1
    assert 'list' in cfg_.section1.var2
    assert cfg_.section1['var1']._comment == 'this is var1'
    assert cfg_.section2.mydict['c'] == 3
Пример #4
0
 def load_config_dialog(self):
     """Bring up load dialog and load selected file"""
     fout = QtWidgets.QFileDialog.getOpenFileName(self, 'Load config file',
                                                  op.expanduser('~'),
                                                  'Config files (*.cfg)')
     fname = fout[0]
     if fname:
         try:
             cfg_new = configdot.parse_config(fname)
             configdot.update_config(
                 cfg,
                 cfg_new,
                 create_new_sections=False,
                 create_new_items=['layouts'],
                 update_comments=False,
             )
         except ValueError:
             qt_message_dialog('Could not parse %s' % fname)
         else:
             self._update_inputs()
Пример #5
0
def test_def_last_line():
    """Test cfg with multiline def terminating on last line"""
    fn = _file_path('def_last_line.cfg')
    cfg = parse_config(fn)
    assert 'foo' in cfg.section2
Пример #6
0
def test_invalid_def():
    """Test cfg with invalid def"""
    fn = _file_path('invalid.cfg')
    with pytest.raises(ValueError):
        parse_config(fn)
Пример #7
0
def test_orphaned_def():
    """Test cfg with def outside section"""
    fn = _file_path('orphan.cfg')
    with pytest.raises(ValueError):
        parse_config(fn)
Пример #8
0
        cfg.autoproc['write_eclipse_fp_info'].value = 'write'


# default config
cfg_template_fn = resource_filename(__name__, 'data/default.cfg')
# user specific config
# On Windows, this typically puts the config at C:\Users\Username, since the
# USERPROFILE environment variable points there. Putting the config in a
# networked home dir requires some tinkering with environment variables
# (e.g. setting HOME)
homedir = op.expanduser('~')
cfg_user_fn = op.join(homedir, '.gaitutils.cfg')

# provide the global cfg instance
# read template config
cfg = parse_config(cfg_template_fn)
if op.isfile(cfg_user_fn):
    logger.debug('reading user config from %s' % cfg_user_fn)
    cfg_user = parse_config(cfg_user_fn)
    # update config from user file, but do not overwrite comments
    # new config items are only allowed in layouts section
    update_config(
        cfg,
        cfg_user,
        create_new_sections=False,
        create_new_items=['layouts'],
        update_comments=False,
    )
else:
    logger.warning('no config file, trying to create %s' % cfg_user_fn)
    cfg_txt = dump_config(cfg)
Пример #9
0
@author: jussi ([email protected])
"""

import inspect
import sys
import os.path as op
import os
import subprocess
import time
import logging
from ulstools.configdot import parse_config

from gaitutils import nexus, config

# reset the config so that user settings do not affect testing
cfg = parse_config(config.cfg_template_fn)
# where test data is held
testdata_root = r'Z:\gaitutils_testdata'


def start_nexus():
    if not nexus.pid():
        # try to start Nexus for tests...
        exe = op.join(cfg.general.nexus_path, 'Nexus.exe')
        # silence Nexus output
        blackhole = open(os.devnull, 'w')
        subprocess.Popen([exe], stdout=blackhole)
        time.sleep(9)
        if not nexus.pid():
            raise Exception('Please start Vicon Nexus first')