Skip to content

Commit

Permalink
Merge pull request #200 from pyiron/which_file_failed
Browse files Browse the repository at this point in the history
Provide Feedback which file failed to parse
  • Loading branch information
jan-janssen committed Jul 6, 2023
2 parents efb5ee1 + 0dbe56e commit 774e989
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
12 changes: 11 additions & 1 deletion pysqa/utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pandas
from jinja2 import Template
from jinja2.exceptions import TemplateSyntaxError

from pysqa.utils.execute import execute_command
from pysqa.utils.queues import Queues
Expand Down Expand Up @@ -485,7 +486,16 @@ def _load_templates(queue_lst_dict, directory="."):
for queue_dict in queue_lst_dict.values():
if "script" in queue_dict.keys():
with open(os.path.join(directory, queue_dict["script"]), "r") as f:
queue_dict["template"] = Template(f.read())
try:
queue_dict["template"] = Template(f.read())
except TemplateSyntaxError as error:
raise TemplateSyntaxError(
message="File: "
+ queue_dict["script"]
+ " - "
+ error.message,
lineno=error.lineno,
)

@staticmethod
def _value_error_if_none(value):
Expand Down
1 change: 1 addition & 0 deletions tests/config/bad_template/bad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- endif %}
4 changes: 4 additions & 0 deletions tests/config/bad_template/queue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
queue_type: SLURM
queue_primary: bad
queues:
bad: {cores_max: 100, cores_min: 10, run_time_max: 259200, script: bad.sh}
10 changes: 7 additions & 3 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import unittest
from jinja2.exceptions import TemplateSyntaxError
from pysqa import QueueAdapter
from pysqa.utils.basic import BasisQueueAdapter

Expand All @@ -21,9 +22,12 @@ def setUpClass(cls):
cls.path = os.path.dirname(os.path.abspath(__file__))

def test_missing_config(self):
self.assertRaises(
ValueError, QueueAdapter, directory=os.path.join(self.path, "config/error")
)
with self.assertRaises(ValueError):
QueueAdapter(directory=os.path.join(self.path, "config/error"))

def test_bad_queue_template(self):
with self.assertRaises(TemplateSyntaxError):
QueueAdapter(directory=os.path.join(self.path, "config/bad_template"))


class TestBasisQueueAdapter(unittest.TestCase):
Expand Down

0 comments on commit 774e989

Please sign in to comment.