Exemplo n.º 1
0
def test_resource_invalid_file_package(tmpdir, monkeypatch):
    """test for non-existent resource file in a package"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        m.setattr(pkg_resources, "resource_filename", lambda *args: os.path.join('invalid', 'file', 'path'))
        resfile = os.path.join('invalid', 'file', 'path')
        assert resource.get_resource(resfile) is None
Exemplo n.º 2
0
def test_resource_file_package(resource_file, tmpdir, monkeypatch):
    """test for valid resource file in a Package context"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        resfile = "test.txt"
        m.setattr(pkg_resources, "resource_filename", lambda *args: os.path.join(tmpdir, resfile))
        assert resource_file(tmpdir, resfile) == resource.get_resource(resfile)
Exemplo n.º 3
0
def test_resource_file_bundle(resource_file, tmpdir, monkeypatch):
    """test for valid resource file in an EXE bundle"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        m.setattr(resource, '_run_context', None, False)
        m.setattr(sys, 'frozen', True, False)
        m.setattr(sys, '_MEIPASS', tmpdir, False)
        rootdir = os.path.join(sys._MEIPASS, resource._BUNDLE_DIR)
        os.mkdir(rootdir)

        resfile = "test.txt"
        assert resource_file(rootdir, resfile) == resource.get_resource(resfile)
Exemplo n.º 4
0
def _init_config():
    """
    Initialize _config based on flags.cfg, environment variables and/or default_flags.cfg
    """
    global _config

    default_data = _read_config(resource.get_resource('default_flags.cfg'))
    flag_config_file = resource.get_resource('flags.cfg')
    if flag_config_file is None:
        flag_data = {}
    else:
        flag_data = _read_config(flag_config_file)

    for k, v in default_data.items():
        if k not in flag_data:
            env_val = os.environ.get(k)
            if env_val is not None:
                _config[k] = bool(int(env_val))
            else:
                _config[k] = bool(int(v))
        else:
            _config[k] = bool(int(flag_data[k]))