コード例 #1
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_license_name_exists():
    env = create_env(dict(license={'name': "", 'year': 2015,
                                   'organization': "oa", 'project': "project"}))
    assert 'name' in check(env)

    env = create_env(dict(license={'name': "tugudu", 'year': 2015,
                                   'organization': "oa", 'project': "project"}))
    assert 'name' in check(env)
コード例 #2
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_intended_version_exists():
    env = create_env(dict(pysetup={'intended_versions': [], 'require': []}))
    assert 'intended_versions' in check(env)
    assert 'require' not in check(env)

    env = create_env(dict(pysetup={'intended_versions': ["27"],
                                   'require': [('walou', 'numpy')]}))
    assert 'require' in check(env)
コード例 #3
0
ファイル: test_local.py プロジェクト: revesansparole/pkglts
def test_pkg_full_name():
    cfg = {}
    assert_raises(KeyError, lambda: pkg_full_name(create_env(cfg)))

    cfg['base'] = dict(pkgname='toto', namespace=None)
    name1 = pkg_full_name(create_env(cfg))
    cfg['base']['namespace'] = 'oa'
    name2 = pkg_full_name(create_env(cfg))

    assert name1 != name2
コード例 #4
0
def test_create_env():
    env = create_env(default_cfg)
    assert len(tuple(installed_options(env))) == 0

    cfg = dict(default_cfg)
    cfg['base'] = dict(a=1, b=2)
    env = create_env(cfg)
    assert len(tuple(installed_options(env))) == 1
    assert env.globals['base'].a == 1
    assert env.globals['base'].b == 2
コード例 #5
0
ファイル: test_local.py プロジェクト: revesansparole/pkglts
def test_src_dir():
    cfg = {}
    assert_raises(KeyError, lambda: src_dir(create_env(cfg)))

    cfg['base'] = dict(pkgname='toto', namespace=None)
    dir1 = src_dir(create_env(cfg))
    cfg['base']['namespace'] = 'oa'
    dir2 = src_dir(create_env(cfg))

    assert dir1 != dir2
コード例 #6
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_pkg_names():
    for pkg in ('1mypkg', ' mypkg', '1', '1.mypkg',
                ' .mypkg', '.mypkg', 'None.mypkg', 'oa.o.mypkg'):
        env = create_env(dict(base={'pkgname': pkg,
                                    'namespace': None,
                                    'owner': 'moi',
                                    'url': None}))
        assert 'pkgname' in check(env)
        env = create_env(dict(base={'pkgname': 'toto',
                                    'namespace': pkg,
                                    'owner': 'moi',
                                    'url': None}))
        assert 'namespace' in check(env)
コード例 #7
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_version_numbers_are_valid():
    env = create_env(dict(version={'major': "", 'minor': "", 'post': ""}))
    assert 'major' in check(env)
    assert 'minor' in check(env)
    assert 'post' in check(env)
    env = create_env(dict(version={'major': "a", 'minor': "a", 'post': "a"}))
    assert 'major' in check(env)
    assert 'minor' in check(env)
    assert 'post' in check(env)
    env = create_env(dict(version={'major': "1", 'minor': "1", 'post': "1"}))
    assert 'major' in check(env)
    assert 'minor' in check(env)
    assert 'post' in check(env)
    env = create_env(dict(version={'major': 1, 'minor': 0, 'post': "2.dev"}))
    assert 'post' in check(env)
コード例 #8
0
def tree(dname, padding, txt):
    pkg_cfg = dict(base={"namespace": None, "owner": "owner", "pkgname": "pkgname", "url": None})

    env = create_env(pkg_cfg)

    files = [(isdir(pj(dname, fname)), fname) for fname in listdir(dname)]
    files.sort()

    count = 0
    for is_dir, fname in files:
        count += 1
        txt += padding + "|\n"
        fmt_name = nn(env, fname)
        txt += padding + "+-" + fmt_name
        path = pj(dname, fname)
        if is_dir:
            txt += "/\n"
            if count == len(files):
                txt = tree(path, padding + " " + " " * (len(fmt_name) / 2), txt)
            else:
                txt = tree(path, padding + "|" + " " * (len(fmt_name) / 2), txt)
        else:
            txt += "\n"

    return txt
コード例 #9
0
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)
コード例 #10
0
def test_create_env_render_templates():
    cfg = dict(default_cfg)
    cfg['base'] = dict(a="a", b="b")
    cfg['tpl'] = dict(tpl1="{{ base.a }}",
                      tpl2="{{ base.b }} and {{ tpl.tpl1 }}")

    env = create_env(cfg)
    assert env.globals['tpl'].tpl1 == "a"
    assert env.globals['tpl'].tpl2 == "b and a"
コード例 #11
0
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)
コード例 #12
0
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)
コード例 #13
0
def test_regenerate_dir_render_file_content():
    pth = pj(tmp_dir, "src", "test.txt")
    with open(pth, 'w') as f:
        f.write("{{ 'lorem ipsum'|upper }}")

    env = create_env(default_cfg)
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    pth = pj(tmp_dir, "tgt", "test.txt")
    with open(pth, 'r') as f:
        cnt = f.read()
        assert cnt == 'LOREM IPSUM'
コード例 #14
0
def test_regenerate_dir_walk_all_files_in_src_dir():
    ensure_created(pj(tmp_dir, "src", "sub"))
    fnames = ('toto.txt', 'titi.txt', 'sub/toto.txt')
    for fname in fnames:
        pth = pj(tmp_dir, "src", fname)
        with open(pth, 'w') as f:
            f.write("lorem ipsum")

    env = create_env(default_cfg)
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    for fname in fnames:
        assert exists(pj(tmp_dir, 'tgt', fname))
コード例 #15
0
def test_regenerate_handle_src_directory_no_namespace():
    pth = pj(tmp_dir, "src", "src", "{{ base.pkgname }}", "test.txt")
    ensure_path(pth)
    with open(pth, 'w') as f:
        f.write("lorem ipsum")

    cfg = dict(default_cfg)
    cfg['base'] = dict(pkgname='toto', namespace=None)
    env = create_env(cfg)
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    tgt = pj(tmp_dir, "tgt", "src", "toto", "test.txt")
    assert exists(tgt)
コード例 #16
0
def test_regenerate_do_not_overwrite_outside_protected_blocks():
    pth = pj(tmp_dir, "src", "test.txt")
    with open(pth, 'w') as f:
        f.write("{# pkglts, b0\nLOREM IPSUM\n#}")

    pth = pj(tmp_dir, "tgt", "test.txt")
    with open(pth, 'w') as f:
        f.write("Toto start\n{# pkglts, b0\nWTF?\n#}\nToto end\n")

    env = create_env(default_cfg)
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    with open(pth, 'r') as f:
        cnt = f.read()

    assert cnt == "Toto start\n{# pkglts, b0\nLOREM IPSUM\n#}\nToto end\n"
コード例 #17
0
def test_regenerate_dir_render_path_names():
    ensure_created(pj(tmp_dir, "src", "{{ custom_name }}"))
    fnames = ('{{ custom_name }}.txt', 'titi.txt',
              '{{ custom_name }}/{{ custom_name }}.txt')
    for fname in fnames:
        pth = pj(tmp_dir, "src", fname)
        with open(pth, 'w') as f:
            f.write("lorem ipsum")

    env = create_env(default_cfg)
    env.globals['custom_name'] = 'toto'
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    fnames = ('toto.txt', 'titi.txt', 'toto/toto.txt')
    for fname in fnames:
        assert exists(pj(tmp_dir, 'tgt', fname))
コード例 #18
0
def test_regenerate_handle_src_directory_with_namespace():
    pth = pj(tmp_dir, "src", "src", "{{ base.pkgname }}", "test.txt")
    ensure_path(pth)
    with open(pth, 'w') as f:
        f.write("lorem ipsum")

    cfg = dict(default_cfg)
    cfg['base'] = dict(pkgname='toto', namespace='myns')
    env = create_env(cfg)
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    tgt_dir = pj(tmp_dir, "tgt")
    assert exists(tgt_dir + "/src")
    assert exists(tgt_dir + "/src/myns")
    assert exists(tgt_dir + "/src/myns/__init__.py")
    assert exists(tgt_dir + "/src/myns/toto")
    assert exists(tgt_dir + "/src/myns/toto/test.txt")
コード例 #19
0
def test_regenerate_do_overwrite_unprotected_files():
    pth = pj(tmp_dir, "src", "test.txt")
    with open(pth, 'w') as f:
        f.write("{# pkglts, b0\n{{ random() }}\n#}")

    env = create_env(default_cfg)
    env.globals['random'] = random
    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    pth = pj(tmp_dir, "tgt", "test.txt")
    with open(pth, 'r') as f:
        cnt0 = f.read()

    regenerate_dir(pj(tmp_dir, 'src'), pj(tmp_dir, 'tgt'), env, {})

    pth = pj(tmp_dir, "tgt", "test.txt")
    with open(pth, 'r') as f:
        cnt1 = f.read()

    assert cnt0 != cnt1
コード例 #20
0
def test_install_example_returns_false_if_option_not_already_installed():
    env = create_env(default_cfg)
    ans = install_example_files('option', env, tmp_dir)
    assert not ans
コード例 #21
0
ファイル: test_manage.py プロジェクト: revesansparole/pkglts
def test_manage_add_opt_raise_error_if_already_installed():
    env = create_env(default_cfg)
    env = add_option("base", env)
    assert_raises(UserWarning, lambda: add_option('base', env))
def test_check_handle_option_config_not_existing():
    env = create_env(default_cfg)
    assert len(check_option_parameters("toto", env)) == 0
def test_check_handle_option_defines_no_check():
    env = create_env(default_cfg)
    assert len(check_option_parameters("test", env)) == 0
コード例 #24
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_project_exists():
    env = create_env(dict(readthedocs={'project': ""}))
    assert 'project' in check(env)
コード例 #25
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_keywords_exists():
    env = create_env(dict(doc={'description': "mydescr", 'keywords': []}))
    assert len(env.globals['doc'].keywords) == 0
    assert 'keywords' not in check(env)
コード例 #26
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_description_exists():
    env = create_env(dict(doc={'description': "mydescr", 'keywords': []}))
    assert env.globals['doc'].description == "mydescr"
    assert 'description' not in check(env)
コード例 #27
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_project_exists():
    env = create_env(dict(github={'owner': "", 'project': "", "url": ""}))
    assert 'project' in check(env)
コード例 #28
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_classifiers_exists():
    env = create_env(dict(pypi={'classifiers': []}))
    assert 'classifiers' in check(env)
コード例 #29
0
ファイル: test_config.py プロジェクト: revesansparole/pkglts
def test_config_check_src_directory():
    env = create_env(dict(notebook={'src_directory': "failed_nb"}))
    assert 'src_directory' in check(env)

    env = create_env(dict(notebook={'src_directory': tmp_dir}))
    assert 'src_directory' not in check(env)
コード例 #30
0
def test_install_example_ok_if_option_do_not_provide_examples():
    cfg = deepcopy(default_cfg)
    cfg['base'] = dict()
    env = create_env(cfg)
    ans = install_example_files('base', env, tmp_dir)
    assert not ans