Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing type error for int job-names #36

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pylhc_submitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = "[email protected]"
__license__ = "MIT"
Expand Down
11 changes: 6 additions & 5 deletions pylhc_submitter/submitter/iotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
LOG = logging.getLogger(__name__)


JobNamesType = Sequence[Union[str, int]]


@dataclass
class CreationOpts:
""" Options for creating jobs. """
Expand Down Expand Up @@ -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 ----------------"
Expand All @@ -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))


Expand Down
12 changes: 0 additions & 12 deletions tests/unit/test_job_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_submitter_io.py
Original file line number Diff line number Diff line change
@@ -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