def test_main(args, tmpdir): tmpdir = str(tmpdir) # XXX: python2 support shutil.copytree( os.path.join(_get_test_root(), "data/cli/hackres"), os.path.join(tmpdir, "hackres"), ) shutil.copytree( os.path.join(_get_test_root(), "data/cli/hackgit"), os.path.join(tmpdir, "hackgit"), ) sys.argv = [ "kmd", "--workspace", tmpdir, ] # Komodo expects the renamer from util-linux. On Debian/Ubuntu, this # renamer has been renamed to rename.ul. if os.path.exists("/usr/bin/rename.ul"): sys.argv.extend(["--renamer", "/usr/bin/rename.ul"]) sys.argv.extend([arg for arg in args]) cli_main() release_name = args[10] release_path = os.path.join(tmpdir, "prefix", release_name) assert os.path.exists(os.path.join(release_path, "root/lib/hackres.so")) assert os.path.exists(os.path.join(release_path, "root/lib/python4.2.so")) assert os.path.exists(os.path.join(release_path, "root/bin/python4.2")) assert os.path.exists(os.path.join(release_path, "enable")) assert os.path.exists(os.path.join(release_path, "enable.csh")) assert os.path.exists(os.path.join(release_path, "local")) assert os.path.exists(os.path.join(release_path, "local.csh")) with open(os.path.join(release_path, release_name)) as releasedoc: releasedoc_content = releasedoc.read() # test specifically for the regression introduced by # https://github.com/equinor/komodo/issues/190 where if you provided ert # with version '*', it would then show up in the releasedoc. assert f"version: '{LATEST_PACKAGE_ALIAS}'" not in releasedoc_content # ensure the alias is used when resolving the version assert "version: null" not in releasedoc_content # Ensure that the commit hash is reported as version and not the # branch "test-hack" specified in nominal_repository.yml assert "test-hash" not in releasedoc_content assert "version: 7f4405928bd16de496522d9301c377c7bcca5ef0" in releasedoc_content
def test_load_all_releases(): files = [ os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py27.yml"), os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py36.yml"), ] used_versions = load_all_releases(files) assert set(used_versions["lib1"]) == set(["1.2.3", "0.1.2"]) assert set(used_versions["lib2"]) == set(["2.3.4", "1.2.3"]) assert set(used_versions["lib3"]) == set(["3.4.5", "2.3.4"]) assert set(used_versions["lib4"]) == set(["3.4.5"])
def test_executables(tmpdir): old_argv = sys.argv.copy() sys.argv = ["run", "links_test.json"] try: test_folder = _get_test_root() with open(os.path.join(test_folder, "data/links_full.json")) as input_file: input_data = json.load(input_file) with tmpdir.as_cwd(): input_data["root_folder"] = str(tmpdir) with open("links_test.json", "w") as test_file: test_file.write(json.dumps(input_data)) with pytest.raises(SystemExit): symlink_main() os.mkdir("bleeding-py36") os.mkdir("bleeding-py27") os.mkdir("2020.01.a0-py36") os.mkdir("2020.01.a0-py27") os.mkdir("2019.12.00-py36") os.mkdir("2019.12.00-py27") symlink_main() sanity_main() finally: sys.argv = old_argv
def test_write_to_file(tmpdir): with tmpdir.as_cwd(): files = [ os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py27.yml"), os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py36.yml"), ] used_versions = load_all_releases(files) repository = _load_yaml( os.path.join(_get_test_root(), "data/test_repository.yml")) unused_versions = find_unused_versions(used_versions, repository) remove_unused_versions(repository, unused_versions) write_to_file(repository, "output_repo.yml") with open("output_repo.yml") as output: assert output.read() == expected_result
def test_main(args, tmpdir): tmpdir = str(tmpdir) # XXX: python2 support shutil.copytree( os.path.join(_get_test_root(), "data/cli/hackres"), os.path.join(tmpdir, "hackres"), ) sys.argv = [ "kmd", "--workspace", tmpdir, ] # Komodo expects the renamer from util-linux. On Debian/Ubuntu, this # renamer has been renamed to rename.ul. if os.path.exists("/usr/bin/rename.ul"): sys.argv.extend(["--renamer", "/usr/bin/rename.ul"]) sys.argv.extend([arg for arg in args]) cli_main() release_path = os.path.join(tmpdir, "prefix", args[10]) # release name assert os.path.exists(os.path.join(release_path, "root/lib/hackres.so")) assert os.path.exists(os.path.join(release_path, "root/lib/python4.2.so")) assert os.path.exists(os.path.join(release_path, "root/bin/python4.2")) assert os.path.exists(os.path.join(release_path, "enable")) assert os.path.exists(os.path.join(release_path, "enable.csh")) assert os.path.exists(os.path.join(release_path, "local")) assert os.path.exists(os.path.join(release_path, "local.csh"))
def test_main_success_symlinks(tmpdir): with tmpdir.as_cwd(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd_db.yml") os.mkdir("2020.01.01-py36-rhel6") os.mkdir("2020.01.01-py27-rhel6") os.symlink("2020.01.01-py27-rhel6", "stable") args = [ "--motd-db", motd_db_file, "--komodo-prefix", os.getcwd(), ] main(args) assert "message1" in os.listdir( os.path.join("2020.01.01-py36-rhel6", "motd", "messages")) assert "script1" in os.listdir( os.path.join("2020.01.01-py27-rhel6", "motd", "scripts")) with open(motd_db_file) as f: motd_db = yaml.safe_load(f) msg = motd_db["stable"]["inline"][0] filename = hashlib.md5(msg.encode()).hexdigest() filename = "0Z" + filename # for orderings sake assert filename in os.listdir( os.path.join("2020.01.01-py27-rhel6", "motd", "messages"))
def test_remove_unused_versions(): files = [ os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py27.yml"), os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py36.yml"), ] used_versions = load_all_releases(files) repository = _load_yaml( os.path.join(_get_test_root(), "data/test_repository.yml")) unused_versions = find_unused_versions(used_versions, repository) remove_unused_versions(repository, unused_versions) assert "lib5" not in repository assert "0.0.2" not in repository["lib1"] assert "0.0.2" not in repository["lib2"] assert "master" not in repository["lib3"]
def test_transpile(tmpdir): release_file = os.path.join(_get_test_root(), "data", "test_release_matrix.yml") release_base = os.path.basename(release_file).strip(".yml") with tmpdir.as_cwd(): transpile_releases(release_file, os.getcwd()) for rhel_ver in ("rhel7",): for py_ver in ("py36",): assert os.path.isfile("{}-{}-{}.yml".format(release_base, py_ver, rhel_ver))
def test_unused_versions(): files = [ os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py27.yml"), os.path.join(_get_test_root(), "data/test_releases/2020.01.a1-py36.yml"), ] used_versions = load_all_releases(files) repository = _load_yaml( os.path.join(_get_test_root(), "data/test_repository.yml")) unused_versions = find_unused_versions(used_versions, repository) print(prettier(repository)) print(used_versions) print(unused_versions) assert "0.0.2" in unused_versions["lib1"] assert "0.0.2" in unused_versions["lib2"] assert "master" in unused_versions["lib3"] assert "lib4" not in unused_versions assert "1.2.3" in unused_versions["lib5"]
def test_build_release_matrix(tmpdir): release_base = "2020.01.a1" release_folder = os.path.join(_get_test_root(), "data/test_releases/") with tmpdir.as_cwd(): build_matrix_file(release_base, release_folder, builtins) new_release_file = "{}.yml".format(release_base) assert os.path.isfile(new_release_file) with open(new_release_file) as f: release_matrix = yaml.safe_load(f) assert release_matrix["lib1"] == builtins["lib1"] assert release_matrix["lib2"]["py27"] == "1.2.3" assert release_matrix["lib2"]["py36"] == "2.3.4"
def test_cleanup_argparse(tmpdir): with pytest.raises(SystemExit): main([ "--repository", "nonexisting_file.yml", "--releases", "non_exisiting_path", "--check", ]) with pytest.raises(SystemExit): main([ "cleanup", "--repository", os.path.join(_get_test_root(), "data/test_repository.yml"), "--releases", "non_exisiting_path", "--check", ]) main([ "cleanup", "--repository", os.path.realpath( os.path.join(_get_test_root(), "data/test_repository.yml")), "--releases", os.path.join(_get_test_root(), "data/test_releases"), "--check", ]) with pytest.raises(SystemExit): main([ "cleanup", "--repository", "--check", "--stdout", os.path.realpath( os.path.join(_get_test_root(), "data/test_repository.yml")), "--releases", os.path.join(_get_test_root(), "data/test_releases"), ]) with tmpdir.as_cwd(): main([ "cleanup", "--repository", os.path.realpath( os.path.join(_get_test_root(), "data/test_repository.yml")), "--releases", os.path.join(_get_test_root(), "data/test_releases"), "--output", "output_repo.yml", ]) assert os.path.isfile("output_repo.yml")
def test_root_links(tmpdir): test_folder = _get_test_root() shutil.copy(os.path.join(test_folder, "data/links.json"), tmpdir) with tmpdir.as_cwd(): with open("links.json") as link_file: input_dict = json.load(link_file) assert_root_nodes(input_dict) input_dict["root_links"].append("non_exisiting") with pytest.raises(AssertionError): assert_root_nodes(input_dict)
def test_get_messages(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd_db.yml") with open(motd_db_file) as f: motd_db = yaml.safe_load(f) release = "2020.01.01-py27-rhel6" scripts, messages, inline = get_messages_and_scripts(release, motd_db) assert "script1" in scripts assert "message1" not in messages assert inline is not [] release = "2020.01.01-py36-rhel6" scripts, messages, inline = get_messages_and_scripts(release, motd_db) assert "script1" not in scripts assert "message1" in messages assert inline is not []
def test_integration(tmpdir): test_folder = _get_test_root() shutil.copy(os.path.join(test_folder, "data/links.json"), tmpdir) with tmpdir.as_cwd(): with open("links.json") as link_file: input_dict = json.load(link_file) input_dict["root_folder"] = os.path.realpath(input_dict["root_folder"]) os.mkdir(input_dict["root_folder"]) os.mkdir(os.path.join(input_dict["root_folder"], "2012.01.12")) os.mkdir(os.path.join(input_dict["root_folder"], "2012.01.rc1")) create_symlinks(input_dict) output = read_link_structure(input_dict["root_folder"]) assert equal_links(input_dict, output)
def test_main_not_existing_release(tmpdir): with tmpdir.as_cwd(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd_db.yml") release = "2020.01.01-py36-rhel6" args = [ "--release", release, "--motd-db", motd_db_file, "--komodo-prefix", os.getcwd(), ] with pytest.raises(SystemExit) as excinfo: main(args) assert "Release {} not found".format(release) in str(excinfo.value)
def test_main_success_no_release(tmpdir): with tmpdir.as_cwd(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd_db.yml") os.mkdir("2020.01.01-py36-rhel6") os.mkdir("2020.01.01-py27-rhel6") args = [ "--motd-db", motd_db_file, "--komodo-prefix", os.getcwd(), ] main(args) assert "message1" in os.listdir( os.path.join("2020.01.01-py36-rhel6", "motd", "messages")) assert "script1" in os.listdir( os.path.join("2020.01.01-py27-rhel6", "motd", "scripts"))
def test_main_no_db(tmpdir): with tmpdir.as_cwd(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd.yml") release = "no-message-db" os.mkdir(release) args = [ "--release", release, "--motd-db", motd_db_file, "--komodo-prefix", os.getcwd(), ] with pytest.raises(SystemExit) as excinfo: main(args) assert "The message-database {} was not found".format( motd_db_file) in str(excinfo.value)
def test_main_missing_message_file(tmpdir): with tmpdir.as_cwd(): motd_db_file = os.path.join(_get_test_root(), "data/test_messages/motd.yml") release = "no-message" os.mkdir(release) args = [ "--release", release, "--motd-db", motd_db_file, "--komodo-prefix", os.getcwd(), ] with pytest.raises(SystemExit) as excinfo: main(args) assert "message file {} does not exisit".format( "not-existing") in str(excinfo.value)
( "--download", "--build", "--install", "--prefix", "prefix", "--cache", "cache", "--tmp", "tmp", "--release", "nominal_release", "--pip", "/bin/true", "--extra-data-dirs", os.path.join(_get_test_root(), "data/cli"), os.path.join(_get_test_root(), "data/cli/hackres"), "--locations-config", os.path.join(_get_test_root(), "data/cli/locations.yml"), os.path.join(_get_test_root(), "data/cli/nominal_release.yml"), os.path.join(_get_test_root(), "data/cli/nominal_repository.yml"), ), ], ) def test_main(args, tmpdir): tmpdir = str(tmpdir) # XXX: python2 support shutil.copytree( os.path.join(_get_test_root(), "data/cli/hackres"), os.path.join(tmpdir, "hackres"), )