Skip to content

Commit 3712c5b

Browse files
koubaaMohamed Koubaapyansys-ci-bot
authored
fix: warn out of bounds characters when reading lines (#647)
Co-authored-by: Mohamed Koubaa <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 85dddc0 commit 3712c5b

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

doc/changelog/647.miscellaneous.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: warn out of bounds characters when reading lines

src/ansys/dyna/core/lib/kwd_line_formatter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222

2323
import typing
24+
import warnings
2425

2526
from ansys.dyna.core.lib.parameter_set import ParameterSet
2627

@@ -146,6 +147,7 @@ def get_parameter(text_block: str, item_type: type) -> typing.Any:
146147
data.append(value)
147148

148149
if end_position < len(line_data):
149-
raise Exception("Data line is too long!")
150+
warning_message = f'Detected out of bound card characters:\n"{line_data[end_position:]}"\n"Ignoring.'
151+
warnings.warn(warning_message)
150152

151153
return tuple(data)

tests/test_card.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_load_card_errors(string_utils):
4040
# cards can only load a readable buffer
4141
card.read("")
4242

43-
with pytest.raises(Exception):
43+
with pytest.warns(UserWarning, match="Detected out of bound card characters"):
4444
# error if the line that is too long
4545
buf = " "
4646
card.read(string_utils.as_buffer(buf))

tests/test_keywords.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def test_read_keyword_no_data():
162162
# ensure that it does not throw when the data line is empty
163163
belt.loads(seatbelt_text)
164164

165+
seatbelt_text = seatbelt_text + "..."
166+
# ensure that it does not throw when extra characters are added
167+
with pytest.warns(UserWarning, match="Detected out of bound card characters"):
168+
belt.loads(seatbelt_text)
169+
165170

166171
@pytest.mark.keywords
167172
def test_read_nodes(ref_string):

tests/test_load_dataline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_load_dataline_005():
6565
@pytest.mark.keywords
6666
def test_load_dataline_006():
6767
"""test loading a data line that is too long."""
68-
with pytest.raises(Exception):
68+
with pytest.warns(UserWarning, match="Detected out of bound card characters"):
6969
load_dataline([(0, 8, int), (8, 8, float), (16, 8, float)], " ")
7070

7171

0 commit comments

Comments
 (0)