Skip to content

Commit

Permalink
Restore too long pseudo filename error.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleGower committed Sep 12, 2023
1 parent 025dbbc commit 110febb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/changes/DM-40699.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore error message about too long pseudo filename while preparing workflow.
14 changes: 14 additions & 0 deletions python/lsst/ctrl/bps/panda/cmd_line_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import os
import re

from lsst.ctrl.bps.panda.constants import PANDA_MAX_LEN_INPUT_FILE

_LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -172,6 +174,11 @@ def substitute_command_line(self, cmd_line, lazy_vars, job_name, gwfiles):
processed command line
file_name: `str`
job pseudo input file name
Raises
------
RuntimeError
Raised if pseudo input filename is too long.
"""
cmd_vals = {m.group(1) for m in re.finditer(r"[^$]{([^}]+)}", cmd_line)}
actual_lazy_vars = {}
Expand All @@ -183,4 +190,11 @@ def substitute_command_line(self, cmd_line, lazy_vars, job_name, gwfiles):
if gwfiles:
cmd_line = self.replace_static_files(cmd_line, gwfiles)
file_name = job_name + self.attach_pseudo_file_params(actual_lazy_vars)

if len(file_name) > PANDA_MAX_LEN_INPUT_FILE:
_LOG.error(f"Too long pseudo input filename: {file_name}")
raise RuntimeError(
f"job pseudo input file name contains more than {PANDA_MAX_LEN_INPUT_FILE} symbols. Aborting."
)

return cmd_line, file_name
11 changes: 11 additions & 0 deletions tests/test_cmd_line_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from lsst.ctrl.bps import GenericWorkflowFile
from lsst.ctrl.bps.panda.cmd_line_embedder import CommandLineEmbedder
from lsst.ctrl.bps.panda.constants import PANDA_MAX_LEN_INPUT_FILE


class TestCmdLineEmbedder(unittest.TestCase):
Expand Down Expand Up @@ -99,6 +100,16 @@ def testReplaceStaticFilesSome(self):
self.assertEqual(orig_cmd_line, orig_cmd_line_copy)
self.assertEqual(new_cmd_line, self.ans_cmd_line_2)

def testTooLongPseudoFilename(self):
cmd_line_embedder = CommandLineEmbedder({})
with self.assertRaises(RuntimeError):
_, _ = cmd_line_embedder.substitute_command_line("", {}, "j" * PANDA_MAX_LEN_INPUT_FILE, [])

def testOKPseudoFilename(self):
cmd_line_embedder = CommandLineEmbedder({})
_, name = cmd_line_embedder.substitute_command_line("", {}, "j" * 15, [])
self.assertIn("j" * 15, name)


if __name__ == "__main__":
unittest.main()
62 changes: 62 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file is part of ctrl_bps_panda.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This software is dual licensed under the GNU General Public License and also
# under a 3-clause BSD license. Recipients may choose which of these licenses
# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
# respectively. If you choose the GPL option then the following text applies
# (but note that there is still no warranty even if you opt for BSD instead):
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""Unit tests for ctrl_bps_panda utilities.
"""
import unittest

from lsst.ctrl.bps import GenericWorkflowExec, GenericWorkflowJob
from lsst.ctrl.bps.panda.constants import PANDA_MAX_LEN_INPUT_FILE
from lsst.ctrl.bps.panda.utils import _make_pseudo_filename


class TestPandaUtils(unittest.TestCase):
"""Simple test of utilities."""

def testTooLongPseudoFilename(self):
# define enough of a job for this test
myexec = GenericWorkflowExec("test_exec")
myexec.src_uri = "/dummy/path/test_exec"
gwjob = GenericWorkflowJob("j" * PANDA_MAX_LEN_INPUT_FILE)
gwjob.executable = myexec
gwjob.arguments = ""
with self.assertRaises(RuntimeError):
_ = _make_pseudo_filename({}, gwjob)

def testOKPseudoFilename(self):
# define enough of a job for this test
myexec = GenericWorkflowExec("test_exec")
myexec.src_uri = "/dummy/path/test_exec"
gwjob = GenericWorkflowJob("j" * 15)
gwjob.executable = myexec
gwjob.arguments = ""
name = _make_pseudo_filename({}, gwjob)
self.assertIn("j" * 15, name)


if __name__ == "__main__":
unittest.main()

Check warning on line 62 in tests/test_utils.py

View check run for this annotation

Codecov / codecov/patch

tests/test_utils.py#L62

Added line #L62 was not covered by tests

0 comments on commit 110febb

Please sign in to comment.