From 5a95e7f81a589d104f0d24432766f43bc216d3a3 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 1 Feb 2024 13:36:27 -0500 Subject: [PATCH 1/2] Ignore empty lines, comments in packages dag file --- galaxy_release_util/point_release.py | 4 +-- pytest.ini | 2 ++ tests/test_release.py | 51 +++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 pytest.ini diff --git a/galaxy_release_util/point_release.py b/galaxy_release_util/point_release.py index babd3f0..9f8cc01 100644 --- a/galaxy_release_util/point_release.py +++ b/galaxy_release_util/point_release.py @@ -117,8 +117,8 @@ def __repr__(self) -> str: def get_sorted_package_paths(galaxy_root: pathlib.Path) -> List[pathlib.Path]: root_package_path = galaxy_root.joinpath("packages") sorted_packages = root_package_path.joinpath("packages_by_dep_dag.txt").read_text().splitlines() - # Check that all packages are listed in packages_by_dep_dag.txt ? - return [root_package_path.joinpath(package) for package in sorted_packages] + # Ignore empty lines and lines beginning with "#" + return [root_package_path.joinpath(p) for p in sorted_packages if p and not p.startswith("#")] def read_package(package_path: pathlib.Path) -> Package: diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..a635c5c --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +pythonpath = . diff --git a/tests/test_release.py b/tests/test_release.py index f26babb..e71a833 100644 --- a/tests/test_release.py +++ b/tests/test_release.py @@ -1,10 +1,9 @@ -import pathlib - import pytest from galaxy_release_util.point_release import ( get_next_devN_version, get_root_version, + get_sorted_package_paths, ) VERSION_PY_CONTENTS = """VERSION_MAJOR = "23.0" @@ -12,13 +11,41 @@ VERSION = VERSION_MAJOR + (f".{VERSION_MINOR}" if VERSION_MINOR else "") """ +PACKAGES_BY_DEP_DAG_CONTENTS = """ +foo + +bar +#this is a comment +baz +""" + + +@pytest.fixture(scope="session") +def make_version_file(): + def f(root): + file = root / "lib" / "galaxy" / "version.py" + file.parent.mkdir(parents=True) + file.write_text(VERSION_PY_CONTENTS) + + return f -@pytest.fixture() -def galaxy_root(tmp_path: pathlib.Path): - version_py = tmp_path / "lib" / "galaxy" / "version.py" - version_py.parent.mkdir(parents=True) - version_py.write_text(VERSION_PY_CONTENTS) - return tmp_path + +@pytest.fixture(scope="session") +def make_packages_file(): + def f(root): + file = root / "packages" / "packages_by_dep_dag.txt" + file.parent.mkdir(parents=True) + file.write_text(PACKAGES_BY_DEP_DAG_CONTENTS) + + return f + + +@pytest.fixture(scope="session") +def galaxy_root(tmp_path_factory, make_version_file, make_packages_file): + tmp_root = tmp_path_factory.mktemp("galaxy_root") + make_version_file(tmp_root) + make_packages_file(tmp_root) + return tmp_root def test_get_root_version(galaxy_root): @@ -35,3 +62,11 @@ def test_get_next_devN_version(galaxy_root): assert version.minor == 0 assert version.micro == 3 assert version.dev == 0 + + +def test_get_sorted_package_paths(galaxy_root): + packages = get_sorted_package_paths(galaxy_root) + assert len(packages) == 3 + assert packages[0].name == "foo" + assert packages[1].name == "bar" + assert packages[2].name == "baz" From 02ff377ad2ecf148f45615e65d7dbf210b00c78b Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 2 Feb 2024 11:30:16 +0100 Subject: [PATCH 2/2] Simplify test --- pytest.ini | 2 -- tests/test_release.py | 34 ++++++++++------------------------ 2 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index a635c5c..0000000 --- a/pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -pythonpath = . diff --git a/tests/test_release.py b/tests/test_release.py index e71a833..09045e5 100644 --- a/tests/test_release.py +++ b/tests/test_release.py @@ -1,3 +1,5 @@ +import pathlib + import pytest from galaxy_release_util.point_release import ( @@ -20,32 +22,16 @@ """ -@pytest.fixture(scope="session") -def make_version_file(): - def f(root): - file = root / "lib" / "galaxy" / "version.py" - file.parent.mkdir(parents=True) - file.write_text(VERSION_PY_CONTENTS) - - return f - - -@pytest.fixture(scope="session") -def make_packages_file(): - def f(root): - file = root / "packages" / "packages_by_dep_dag.txt" - file.parent.mkdir(parents=True) - file.write_text(PACKAGES_BY_DEP_DAG_CONTENTS) - - return f +def write_contents(path: pathlib.Path, contents: str): + path.parent.mkdir(parents=True) + path.write_text(contents) -@pytest.fixture(scope="session") -def galaxy_root(tmp_path_factory, make_version_file, make_packages_file): - tmp_root = tmp_path_factory.mktemp("galaxy_root") - make_version_file(tmp_root) - make_packages_file(tmp_root) - return tmp_root +@pytest.fixture() +def galaxy_root(tmp_path: pathlib.Path): + write_contents(tmp_path / "lib" / "galaxy" / "version.py", VERSION_PY_CONTENTS) + write_contents(tmp_path / "packages" / "packages_by_dep_dag.txt", PACKAGES_BY_DEP_DAG_CONTENTS) + return tmp_path def test_get_root_version(galaxy_root):