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)
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)
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
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
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
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)
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)
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
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)
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"
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 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_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'
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))
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)
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"
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))
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")
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
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
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
def test_config_check_project_exists(): env = create_env(dict(readthedocs={'project': ""})) assert 'project' in check(env)
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)
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)
def test_config_check_project_exists(): env = create_env(dict(github={'owner': "", 'project': "", "url": ""})) assert 'project' in check(env)
def test_config_check_classifiers_exists(): env = create_env(dict(pypi={'classifiers': []})) assert 'classifiers' in check(env)
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)
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