Beispiel #1
0
def test_local_creation_with_topdir():
    # Like test_local_creation, with a specified topdir.

    system = pathlib.Path(config._location(SYSTEM))
    glbl = pathlib.Path(config._location(GLOBAL))
    local = pathlib.Path(config._location(LOCAL))

    topdir = pathlib.Path(os.getcwd()) / 'test-topdir'
    topdir_west = topdir / '.west'
    assert not topdir_west.exists()
    topdir_west.mkdir(parents=True)
    topdir_config = topdir_west / 'config'

    assert not system.exists()
    assert not glbl.exists()
    assert not local.exists()
    assert not topdir_config.exists()

    config.update_config('pytest',
                         'key',
                         'val',
                         configfile=LOCAL,
                         topdir=str(topdir))

    assert not system.exists()
    assert not glbl.exists()
    assert not local.exists()
    assert topdir_config.exists()

    assert cfg(f=ALL, topdir=str(topdir))['pytest']['key'] == 'val'
    assert 'pytest' not in cfg(f=SYSTEM)
    assert 'pytest' not in cfg(f=GLOBAL)
    assert cfg(f=LOCAL, topdir=str(topdir))['pytest']['key'] == 'val'
Beispiel #2
0
def config_tmpdir(tmpdir):
    # Fixture for running from a temporary directory with
    # environmental overrides in place so all configuration files
    # live inside of it. This makes sure we don't touch
    # the user's actual files.
    #
    # We also set ZEPHYR_BASE (to avoid complaints in subcommand
    # stderr), but to a spurious location (so that attempts to read
    # from inside of it are caught here).
    #
    # Using this makes the tests run faster than if we used
    # west_init_tmpdir from conftest.py, and also ensures that the
    # configuration code doesn't depend on features like the existence
    # of a manifest file, helping separate concerns.
    system = tmpdir / 'config.system'
    glbl = tmpdir / 'config.global'
    local = tmpdir / 'config.local'

    os.environ['ZEPHYR_BASE'] = str(tmpdir.join('no-zephyr-here'))
    os.environ['WEST_CONFIG_SYSTEM'] = str(system)
    os.environ['WEST_CONFIG_GLOBAL'] = str(glbl)
    os.environ['WEST_CONFIG_LOCAL'] = str(local)

    # Make sure our environment variables (as well as other topdirs)
    # are being respected, and we aren't going to touch the user's real
    # files.
    td = tmpdir / 'another-topdir'
    assert config._location(SYSTEM) == str(system)
    assert config._location(GLOBAL) == str(glbl)
    assert config._location(LOCAL) == str(local)
    assert (config._location(LOCAL,
                             topdir=str(td)) == str(td / '.west' / 'config'))

    # All clear: switch to the temporary directory and run the test.
    tmpdir.chdir()
    yield tmpdir

    # Clean up after ourselves so other test cases don't know about
    # this tmpdir.
    del os.environ['ZEPHYR_BASE']
    del os.environ['WEST_CONFIG_SYSTEM']
    del os.environ['WEST_CONFIG_GLOBAL']
    del os.environ['WEST_CONFIG_LOCAL']
Beispiel #3
0
def config_tmpdir(tmpdir):
    # Fixture for running from a temporary directory with a .west
    # inside. We also:
    #
    # - ensure we're being run under tox, to avoid messing with
    #   the user's actual configuration files
    # - ensure configuration files point where they should inside
    #   the temporary tox directories, for the same reason
    # - ensure ~ exists (since the test environment
    #   doesn't let us run in the true user $HOME).
    # - set WEST_CONFIG_SYSTEM to lie inside the tmpdir (to avoid
    #   interacting with the real system file)
    # - set ZEPHYR_BASE (to avoid complaints in subcommand stderr)
    #
    # Using this makes the tests run faster than if we used
    # west_init_tmpdir from conftest.py, and also ensures that the
    # configuration code doesn't depend on features like the existence
    # of a manifest file, helping separate concerns.
    assert 'TOXTEMPDIR' in os.environ, 'you must run tests using tox'
    toxtmp = os.environ['TOXTEMPDIR']
    toxhome = canon_path(os.path.join(toxtmp, 'pytest-home'))
    global_loc = canon_path(config._location(GLOBAL))
    assert canon_path(os.path.expanduser('~')) == toxhome
    assert global_loc == os.path.join(toxhome, '.westconfig')
    os.makedirs(toxhome, exist_ok=True)
    if os.path.exists(global_loc):
        os.remove(global_loc)
    tmpdir.mkdir('.west')
    tmpdir.chdir()

    # Make sure the 'pytest' section is not present. If it is,
    # something is wrong in either the test environment (e.g. the user
    # has a system file with a 'pytest' section in it) or the tests
    # (if we're not setting ourselves up properly)
    os.environ['ZEPHYR_BASE'] = str(tmpdir.join('no-zephyr-here'))
    os.environ['WEST_CONFIG_SYSTEM'] = str(tmpdir.join('config.system'))
    if 'pytest' in cfg():
        del os.environ['ZEPHYR_BASE']
        assert False, 'bad fixture setup'
    yield tmpdir
    del os.environ['ZEPHYR_BASE']
    del os.environ['WEST_CONFIG_SYSTEM']
Beispiel #4
0
def test_local_creation():
    # Like test_system_creation, for local config options.

    assert not os.path.isfile(config._location(SYSTEM))
    assert not os.path.isfile(config._location(GLOBAL))
    assert not os.path.isfile(config._location(LOCAL))

    config.update_config('pytest', 'key', 'val', configfile=LOCAL)

    assert not os.path.isfile(config._location(SYSTEM))
    assert not os.path.isfile(config._location(GLOBAL))
    assert os.path.isfile(config._location(LOCAL))
    assert cfg(f=ALL)['pytest']['key'] == 'val'
    assert 'pytest' not in cfg(f=SYSTEM)
    assert 'pytest' not in cfg(f=GLOBAL)
    assert cfg(f=LOCAL)['pytest']['key'] == 'val'
Beispiel #5
0
def test_system_creation():
    # Test that the system file -- and just that file -- is created on
    # demand.

    assert not os.path.isfile(config._location(SYSTEM))
    assert not os.path.isfile(config._location(GLOBAL))
    assert not os.path.isfile(config._location(LOCAL))

    config.update_config('pytest', 'key', 'val', configfile=SYSTEM)

    assert os.path.isfile(config._location(SYSTEM))
    assert not os.path.isfile(config._location(GLOBAL))
    assert not os.path.isfile(config._location(LOCAL))
    assert cfg(f=ALL)['pytest']['key'] == 'val'
    assert cfg(f=SYSTEM)['pytest']['key'] == 'val'
    assert 'pytest' not in cfg(f=GLOBAL)
    assert 'pytest' not in cfg(f=LOCAL)