Exemplo n.º 1
0
def test_get_pkg_config_handle_versions(tmp_dir):
    pkg_cfg = dict(default_cfg)
    pkg_cfg["_pkglts"]["version"] = 0
    json.dump(pkg_cfg, open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w'))

    cfg = get_pkg_config(tmp_dir)
    assert cfg["_pkglts"]['version'] == current_pkg_cfg_version
def test_regenerate_fail_if_permanent_section_ids_have_been_modified():
    env = get_pkg_config(tmp_dir)

    with open(init_file, 'a') as f:
        f.write("\n# {# pkglts, test\na = 1\n# #}\n")

    assert_raises(KeyError, lambda: regenerate_package(env, tmp_dir, overwrite=True))
Exemplo n.º 3
0
def test_get_pkg_config_handle_versions(tmp_dir):
    pkg_cfg = dict(DEFAULT_CFG)
    pkg_cfg["_pkglts"]["version"] = 0
    json.dump(pkg_cfg, open(tmp_dir / pkglts_dir / pkg_cfg_file, 'w'))

    cfg = get_pkg_config(tmp_dir)
    assert cfg["_pkglts"]['version'] == CURRENT_PKG_CFG_VERSION
def test_get_pkg_config_handle_versions():
    cfg = dict(default_cfg)
    cfg["_pkglts"]["version"] = 0
    with open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w') as f:
        json.dump(cfg, f)

    env = get_pkg_config(tmp_dir)
    assert env.globals["_pkglts"].version == current_pkg_cfg_version
Exemplo n.º 5
0
def test_regenerate_option_fails_if_option_not_available(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    regenerate_option(cfg, 'base', tmp_dir)

    with pytest.raises(KeyError):
        regenerate_option(cfg, "toto", tmp_dir)
Exemplo n.º 6
0
def test_get_pkg_config_read_cfg(tmp_dir):
    pkg_cfg = dict(DEFAULT_CFG)
    pkg_cfg['base'] = dict(pkgname="toto", namespace="nm",
                           url=None, authors=[("moi", "moi@aussi")])
    json.dump(pkg_cfg, open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w'))

    cfg = get_pkg_config(tmp_dir)
    assert 'base' in cfg
Exemplo n.º 7
0
def test_regenerate_handle_global_overwrite(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    addendum(init_file)

    regenerate_package(cfg, tmp_dir, overwrite=True)

    assert "modified" not in init_file.read_text()
Exemplo n.º 8
0
def test_regenerate_fail_if_permanent_section_ids_have_been_modified(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    with open(init_file, 'a') as f:
        f.write("\n# {# pkglts, test\na = 1\n# #}\n")

    with pytest.raises(KeyError):
        regenerate_package(cfg, tmp_dir, overwrite=True)
def test_get_pkg_config_read_cfg():
    cfg = dict(default_cfg)
    cfg['base'] = dict(pkgname="toto", namespace="nm",
                       url=None, authors=[("moi", "moi@aussi")])
    with open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w') as f:
        json.dump(cfg, f)

    env = get_pkg_config(tmp_dir)
    assert 'base' in env.globals
Exemplo n.º 10
0
def test_regenerate_handle_conflicts_keep(tmp_pths, mocker):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    init_file.write_text("modified")

    mocker.patch('pkglts.manage.get_user_permission', return_value=False)
    regenerate_package(cfg, tmp_dir)

    assert init_file.read_text() == "modified"
Exemplo n.º 11
0
def test_regenerate_remove_tpl_files_do_not_generate_conflicts(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    regenerate_package(cfg, tmp_dir)

    init_file.unlink()

    regenerate_package(cfg, tmp_dir)
    assert init_file.exists()
Exemplo n.º 12
0
def test_regenerate_handle_global_overwrite():
    env = get_pkg_config(tmp_dir)

    addendum()

    regenerate_package(env, tmp_dir, overwrite=True)

    with open(init_file, 'r') as f:
        txt = f.read()
        assert "modified" not in txt
Exemplo n.º 13
0
def test_regenerate_handle_conflicts_overwrite(tmp_pths, mocker):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    addendum(init_file)

    mocker.patch('pkglts.manage.get_user_permission', return_value=True)
    regenerate_package(cfg, tmp_dir)

    assert "modified" not in init_file.read_text()
Exemplo n.º 14
0
def test_pkg_cfg_read_write_maintains_templates(tmp_dir):
    pkg_cfg = dict(DEFAULT_CFG)
    pkg_cfg['base'] = dict(pkgname="toto", namespace="nm",
                           url=None, authors=[("moi", "moi@aussi")])
    pkg_cfg['license'] = dict(name="CeCILL-C", organization="org",
                              project="{{ base.pkgname }}", year="2015")

    json.dump(pkg_cfg, open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w'))

    cfg = get_pkg_config(tmp_dir)
    assert cfg['license']['project'] == "toto"

    write_pkg_config(cfg, tmp_dir)
    pkg_cfg = json.load(open(pj(tmp_dir, ".pkglts/pkg_cfg.json")))
    pkg_cfg["base"]["pkgname"] = "tutu"

    json.dump(pkg_cfg, open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w'))

    cfg = get_pkg_config(tmp_dir)
    assert cfg['license']['project'] == "tutu"
Exemplo n.º 15
0
def action_example(*args, **kwds):
    """Install example files associated with options.
    """
    del kwds  # unused
    if len(args) == 0:
        raise UserWarning("need to specify at least one option name")

    logger.info("install examples")
    cfg = get_pkg_config()
    for name in args:
        install_example_files(name, cfg)
Exemplo n.º 16
0
def test_regenerate_new_files_do_not_generate_conflicts(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    new_pth = tmp_dir / "src/toto/new_file.py"
    new_pth.write_text("txt = 'addendum'")

    regenerate_package(cfg, tmp_dir)

    assert new_pth.exists()
    assert new_pth.read_text() == "txt = 'addendum'"
Exemplo n.º 17
0
def test_regenerate_handle_global_overwrite(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    addendum(init_file)

    regenerate_package(cfg, tmp_dir, overwrite=True)

    with open(init_file, 'r') as f:
        txt = f.read()
        assert "modified" not in txt
Exemplo n.º 18
0
def test_regenerate_handle_conflicts_keep(tmp_pths, mocker):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    with open(init_file, 'w') as f:
        f.write("modified")

    with mocker.patch('pkglts.manage.get_user_permission', return_value=False):
        regenerate_package(cfg, tmp_dir)

    with open(init_file, 'r') as f:
        assert f.read() == "modified"
Exemplo n.º 19
0
def test_regenerate_handle_conflicts_overwrite():
    env = get_pkg_config(tmp_dir)

    addendum()

    with mock.patch('pkglts.manage.get_user_permission',
                    return_value=True):
        regenerate_package(env, tmp_dir)

    with open(init_file, 'r') as f:
        txt = f.read()
        assert "modified" not in txt
Exemplo n.º 20
0
def test_regenerate_handle_conflicts_keep():
    env = get_pkg_config(tmp_dir)

    with open(init_file, 'w') as f:
        f.write("modified")

    with mock.patch('pkglts.manage.get_user_permission',
                    return_value=False):
        regenerate_package(env, tmp_dir)

    with open(init_file, 'r') as f:
        assert f.read() == "modified"
Exemplo n.º 21
0
def action_add(*args, **kwds):
    """Add new options in the package.
    """
    del kwds  # unused
    if len(args) == 0:
        raise UserWarning("need to specify at least one option name")

    logger.info("add option")
    cfg = get_pkg_config()
    for name in args:
        cfg = add_option(name, cfg)

    write_pkg_config(cfg)
Exemplo n.º 22
0
def test_regenerate_handle_conflicts_overwrite(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    addendum(init_file)

    with mock.patch('pkglts.manage.get_user_permission',
                    return_value=True):
        regenerate_package(cfg, tmp_dir)

    with open(init_file, 'r') as f:
        txt = f.read()
        assert "modified" not in txt
Exemplo n.º 23
0
def test_regenerate_remove_user_files_do_not_generate_conflicts():
    env = get_pkg_config(tmp_dir)

    new_pth = pj(tmp_dir, "src", "toto", "new_file.py")
    with open(new_pth, 'w') as f:
        f.write("txt = 'addendum'")

    regenerate_package(env, tmp_dir)

    remove(new_pth)

    regenerate_package(env, tmp_dir)
    assert not exists(new_pth)
Exemplo n.º 24
0
def test_regenerate_remove_user_files_do_not_generate_conflicts(tmp_pths):
    tmp_dir, init_file = tmp_pths
    cfg = get_pkg_config(tmp_dir)

    new_pth = pj(tmp_dir, "src", "toto", "new_file.py")
    with open(new_pth, 'w') as f:
        f.write("txt = 'addendum'")

    regenerate_package(cfg, tmp_dir)

    remove(new_pth)

    regenerate_package(cfg, tmp_dir)
    assert not exists(new_pth)
Exemplo n.º 25
0
def action_regenerate(*args, **kwds):
    """Regenerate all files in the package.
    """
    overwrite = 'overwrite' in kwds

    cfg = get_pkg_config()
    clean()

    if len(args) == 0:
        logger.info("regenerate package")
        regenerate_package(cfg, overwrite=overwrite)
    else:
        for name in args:
            logger.info("regenerate '%s'" % name)
            regenerate_option(cfg, name, overwrite=overwrite)
Exemplo n.º 26
0
def action_info(*args, **kwds):
    """Display info on package for debug purpose.
    """
    del args  # unused
    del kwds  # unused
    logger.info("package info")
    from pkglts.option_tools import available_options
    print("available_options:")
    for opt_name in available_options:
        print("  ", opt_name)
    from pkglts.config_management import get_pkg_config
    cfg = get_pkg_config()
    print("current config (after resolution)")
    for opt_name, opt_params in cfg.items():
        print(opt_name, opt_params)
Exemplo n.º 27
0
def test_pkg_cfg_read_write_maintains_templates():
    cfg = dict(default_cfg)
    cfg['base'] = dict(pkgname="toto", namespace="nm",
                       url=None, authors=[("moi", "moi@aussi")])
    cfg['license'] = dict(name="CeCILL-C", organization="org",
                          project="{{ base.pkgname }}", year="2015")

    with open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w') as f:
        json.dump(cfg, f)

    env = get_pkg_config(tmp_dir)
    assert env.globals['license'].project == "toto"

    write_pkg_config(env, tmp_dir)
    with open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'r') as f:
        cfg = json.load(f)

    cfg["base"]["pkgname"] = "tutu"

    with open(pj(tmp_dir, ".pkglts/pkg_cfg.json"), 'w') as f:
        json.dump(cfg, f)

    env = get_pkg_config(tmp_dir)
    assert env.globals['license'].project == "tutu"