Coverage for tests/test_htcondor_submit.py: 100%
25 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-14 18:41 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-14 18:41 +0000
1# This file is part of ctrl_bps_htcondor.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
28"""Unit tests for the HTCondor Submit compatibility shim."""
30import importlib.metadata
31from unittest.mock import patch
33import pytest
34from classad2 import ClassAd
35from htcondor2 import Submit
36from htcondor2._schedd import Schedd
37from packaging.version import Version
39htcondor_pkg_version = Version(importlib.metadata.version("htcondor"))
42@pytest.fixture
43def mock_schedd_ad() -> ClassAd:
44 """Return a mock ClassAd for a Schedd."""
45 schedd = ClassAd()
46 schedd["MyAddress"] = "<127.0.0.1:2573?addrs=127.0.0.1-2573&alias=schedd.local>"
47 schedd["CondorVersion"] = (
48 "$CondorVersion: 24.0.23 2026-08-20 BuildID: 943578 PackageID: 24.0.23-1 GitSHA: e1114ad7 $"
49 )
50 return schedd
53@pytest.mark.skipif(
54 htcondor_pkg_version >= Version("24.1"), reason="Test only applicable for htcondor < 24.1"
55)
56def test_htcondor_submit(mock_schedd_ad: ClassAd):
57 """Tests the ``htcondor2`` Schedd submit behavior wrt the ``queue_args``.
59 Parameters
60 ----------
61 mock_schedd_ad : ``classad2.ClassAd``
62 A minimal mock ad for a Schedd location.
64 Notes
65 -----
66 In ``htcondor==24.0.*``, the ``htcondor2.Schedd.submit`` method is broken
67 and raises an ``IndexError`` if no "queue arguments" are provided. A work-
68 around is to specify explicit "queue arguments" on the ``Submit`` ad.
69 """
70 submit_dict = {"executable": "/bin/sleep", "arguments": "10"}
71 submit_ad = Submit(submit_dict)
73 with patch("htcondor2._schedd._schedd_submit", return_value=None) as mock_submit:
74 schedd = Schedd(mock_schedd_ad)
76 with pytest.raises(IndexError, match=r"string index out of range"):
77 schedd.submit(submit_ad)
79 submit_ad.setQArgs("queue 1")
80 schedd.submit(submit_ad, itemdata=None)
82 assert mock_submit.called, "the patch missed its mark"