From 0cc8b9105f991e4fa8a71792dfb0074f904d006c Mon Sep 17 00:00:00 2001 From: JoschD <26184899+JoschD@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:54:12 +0100 Subject: [PATCH] fix and test and bump --- CHANGELOG.md | 4 ++++ pylhc_submitter/__init__.py | 2 +- pylhc_submitter/submitter/iotools.py | 11 +++++----- tests/unit/test_job_submitter.py | 12 ----------- tests/unit/test_submitter_io.py | 32 ++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 tests/unit/test_submitter_io.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e8f64..2f37e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # `pylhc-submitter` Changelog +## Version 2.0.1 + +- Fixing job_submitter: type error in `print_stats`, when job-names are integers. + ## Version 2.0.0 - General code cleanup/refactoring/documentation: diff --git a/pylhc_submitter/__init__.py b/pylhc_submitter/__init__.py index ed21d9e..2a1fbe1 100644 --- a/pylhc_submitter/__init__.py +++ b/pylhc_submitter/__init__.py @@ -10,7 +10,7 @@ __title__ = "pylhc_submitter" __description__ = "pylhc-submitter contains scripts to simplify the creation and submission of jobs to HTCondor at CERN" __url__ = "https://github.com/pylhc/submitter" -__version__ = "2.0.0" +__version__ = "2.0.1" __author__ = "pylhc" __author_email__ = "pylhc@github.com" __license__ = "MIT" diff --git a/pylhc_submitter/submitter/iotools.py b/pylhc_submitter/submitter/iotools.py index 5c66c90..4b849a0 100644 --- a/pylhc_submitter/submitter/iotools.py +++ b/pylhc_submitter/submitter/iotools.py @@ -25,6 +25,9 @@ LOG = logging.getLogger(__name__) +JobNamesType = Sequence[Union[str, int]] + + @dataclass class CreationOpts: """ Options for creating jobs. """ @@ -228,7 +231,7 @@ def get_server_from_uri(path: Union[Path, str]) -> str: return server_part -def print_stats(new_jobs: Sequence[str], finished_jobs: Sequence[str]): +def print_stats(new_jobs: JobNamesType, finished_jobs: JobNamesType): """Print some quick statistics.""" text = [ "\n------------- QUICK STATS ----------------" @@ -237,11 +240,9 @@ def print_stats(new_jobs: Sequence[str], finished_jobs: Sequence[str]): f"Jobs already finished: {len(finished_jobs):d}", "---------- JOBS TO RUN: NAMES -------------" ] - for job_name in new_jobs: - text.append(job_name) + text += [str(job_name) for job_name in new_jobs] text += ["--------- JOBS FINISHED: NAMES ------------"] - for job_name in finished_jobs: - text.append(job_name) + text += [str(job_name) for job_name in finished_jobs] LOG.info("\n".join(text)) diff --git a/tests/unit/test_job_submitter.py b/tests/unit/test_job_submitter.py index f395840..09e330b 100644 --- a/tests/unit/test_job_submitter.py +++ b/tests/unit/test_job_submitter.py @@ -115,18 +115,6 @@ def test_htcondor_bindings_not_found_on_nonlinux_os(tmp_path): assert "htcondor bindings" in str(e) -@pytest.mark.skipif(on_windows(), reason="Paths are not split on '/' on Windows.") -def test_eos_uri_manipulation_functions(): - """ Unit-test for the EOS-URI parsing. (OH LOOK! An actual unit test!)""" - server = "root://eosuser.cern.ch/" - path = "/eos/user/m/mmustermann/" - uri = f"{server}{path}" - assert is_eos_uri(uri) - assert not is_eos_uri(path) - assert uri_to_path(uri) == Path(path) - assert get_server_from_uri(uri) == server - - @run_only_on_linux @pytest.mark.cern_network @pytest.mark.parametrize("destination", [True, False]) diff --git a/tests/unit/test_submitter_io.py b/tests/unit/test_submitter_io.py new file mode 100644 index 0000000..1ee6503 --- /dev/null +++ b/tests/unit/test_submitter_io.py @@ -0,0 +1,32 @@ +import logging +from pathlib import Path + +import pytest + +from pylhc_submitter.submitter.iotools import (get_server_from_uri, is_eos_uri, print_stats, + uri_to_path) +from pylhc_submitter.utils.environment import on_linux, on_windows + + +@pytest.mark.skipif(on_windows(), reason="Paths are not split on '/' on Windows.") +def test_eos_uri_manipulation_functions(): + """ Unit-test for the EOS-URI parsing. (OH LOOK! An actual unit test!)""" + server = "root://eosuser.cern.ch/" + path = "/eos/user/m/mmustermann/" + uri = f"{server}{path}" + assert is_eos_uri(uri) + assert not is_eos_uri(path) + assert uri_to_path(uri) == Path(path) + assert get_server_from_uri(uri) == server + + +def test_print_stats(caplog): + """ Checking that the stats are printed correctly. """ + new_jobs = ["a", 1] + finished_jobs = [3, "d"] + with caplog.at_level(logging.INFO): + print_stats(new_jobs, finished_jobs) + assert "run: 2" in caplog.text + assert "finished: 2" in caplog.text + assert "a\n1" in caplog.text + assert "3\nd" in caplog.text