def test_regenerate_pass():
    with open(pj(tmp_dir, pkglts_dir, pkg_cfg_file), 'r') as f:
        cfg = json.load(f)

    cfg['base'] = dict(pkgname='toto', namespace=None,
                       authors=[('moi', '*****@*****.**')], url=None)
    env = create_env(cfg)
    regenerate_package(env, tmp_dir)
    assert exists(init_file)
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
def setup():
    ensure_created(tmp_dir)
    init_pkg(tmp_dir)
    with open(pj(tmp_dir, pkglts_dir, pkg_cfg_file), 'r') as f:
        cfg = json.load(f)

    cfg['base'] = dict(pkgname='toto', namespace=None,
                       authors=[('moi', '*****@*****.**')], url=None)
    env = create_env(cfg)
    write_pkg_config(env, tmp_dir)
    regenerate_package(env, tmp_dir)
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
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"
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)
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))
def test_regenerate_check_pkg_cfg_validity():
    with open(pj(tmp_dir, pkglts_dir, pkg_cfg_file), 'r') as f:
        cfg = json.load(f)

    cfg['base'] = dict(pkgname='1toto', namespace=None,
                       authors=[('moi', '*****@*****.**')], url=None)
    env = create_env(cfg)
    assert not regenerate_package(env, tmp_dir)