Skip to content

Commit 67d6cab

Browse files
authored
Merge branch 'master' into ModelicaSystem_cleanup
2 parents 1426928 + c261cff commit 67d6cab

6 files changed

Lines changed: 19 additions & 165 deletions

File tree

.github/workflows/FMITest.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.github/workflows/Test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
verbose: true
7474
emoji: true
7575
job-summary: true
76-
custom-arguments: '-v '
76+
custom-arguments: '-v'
7777
click-to-expand: true
7878
report-title: 'Test Report'
7979

OMPython/OMCSession.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
from typing import Any, Optional, Tuple
2424
import uuid
2525
import warnings
26-
import zmq
2726

2827
import psutil
2928
import pyparsing
29+
import zmq
3030

3131
# TODO: replace this with the new parser
3232
from OMPython.OMTypedParser import om_parser_typed
@@ -407,13 +407,6 @@ def size(self) -> int:
407407

408408
raise OMCSessionException(f"Error reading file size for path {self.as_posix()}!")
409409

410-
def stat(self):
411-
"""
412-
The function stat() cannot be implemented using OMC.
413-
"""
414-
raise NotImplementedError("The function stat() cannot be implemented using OMC; "
415-
"use size() to get the file size.")
416-
417410

418411
if sys.version_info < (3, 12):
419412

OMPython/OMParser.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@
3232
Version: 1.0
3333
"""
3434

35-
import sys
36-
from typing import Dict, Any
35+
from typing import Any
3736

38-
result: Dict[str, Any] = dict()
37+
result: dict[str, Any] = {}
3938

40-
inner_sets = []
41-
next_set_list = []
4239
next_set = []
4340
next_set.append('')
4441

@@ -47,10 +44,9 @@ def bool_from_string(string):
4744
"""Attempt conversion of string to a boolean """
4845
if string in {'true', 'True', 'TRUE'}:
4946
return True
50-
elif string in {'false', 'False', 'FALSE'}:
47+
if string in {'false', 'False', 'FALSE'}:
5148
return False
52-
else:
53-
raise ValueError
49+
raise ValueError
5450

5551

5652
def typeCheck(string):
@@ -67,9 +63,7 @@ def typeCheck(string):
6763
return t(string)
6864
except ValueError:
6965
continue
70-
else:
71-
print("String contains un-handled datatype")
72-
return string
66+
raise ValueError(f"String contains un-handled datatype: {repr(string)}!")
7367

7468

7569
def make_values(strings, name):
@@ -161,14 +155,9 @@ def make_values(strings, name):
161155
varValue = (varValue.replace('{', '').strip()).replace('}', '').strip()
162156
multiple_values = varValue.split(",")
163157

164-
for n in range(len(multiple_values)):
165-
each_v = multiple_values[n]
166-
multiple_values.pop(n)
167-
each_v = typeCheck(each_v)
168-
multiple_values.append(each_v)
169-
170158
if len(multiple_values) != 0:
171-
result[main_set_name]['Elements'][name]['Properties']['Results'][varName] = multiple_values
159+
multiple_values_type_checked = [typeCheck(val) for val in multiple_values]
160+
result[main_set_name]['Elements'][name]['Properties']['Results'][varName] = multiple_values_type_checked
172161
elif varName != "" and varValue != "":
173162
result[main_set_name]['Elements'][name]['Properties']['Results'][varName] = varValue
174163
else:
@@ -187,12 +176,12 @@ def delete_elements(strings):
187176
char = strings[pos]
188177
if char == "":
189178
break
190-
elif char == ",":
179+
if char == ",":
191180
break
192-
elif char == " ":
181+
if char == " ":
193182
pos = pos + 1
194183
break
195-
elif char == "{":
184+
if char == "{":
196185
break
197186
pos = pos - 1
198187
delStr = strings[pos: strings.rfind(")")]
@@ -566,8 +555,8 @@ def skip_all_inner_sets(position):
566555
break
567556
pos += 1
568557
if count != 0:
569-
print("\nParser Error: Are you missing one or more '}'s? \n")
570-
sys.exit(1)
558+
raise ValueError("Parser Error: Are you missing one or more '}}'s in string? "
559+
f"(string value: {repr(string)}")
571560

572561
if max_count >= 2:
573562
while position < end_of_main_set:
@@ -683,15 +672,14 @@ def skip_all_inner_sets(position):
683672
position += 1
684673
else:
685674
next_set[0] = ""
686-
return (len(string) - 1)
675+
return len(string) - 1
687676

688677
max_of_sets = max(last_set, last_subset)
689678
max_of_main_set = max(max_of_sets, last_subset)
690679

691680
if max_of_main_set != 0:
692681
return max_of_main_set
693-
else:
694-
return (len(string) - 1)
682+
return len(string) - 1
695683

696684
# Main entry of get_the_string()
697685
index = 0
@@ -745,8 +733,7 @@ def skip_all_inner_sets(position):
745733
else:
746734
return current_set, next_set[0]
747735
else:
748-
print("\nThe following String has no {}s to proceed\n")
749-
print(string)
736+
raise ValueError(f"The following String has no {{}}s to proceed: {repr(string)}!")
750737

751738
# End of get_the_string()
752739

@@ -835,15 +822,15 @@ def check_for_values(string):
835822
if "record SimulationResult" in string:
836823
formatSimRes(string)
837824
return result
838-
elif "record " in string:
825+
if "record " in string:
839826
formatRecords(string)
840827
return result
841828

842829
string = typeCheck(string)
843830

844831
if not isinstance(string, str):
845832
return string
846-
elif string.find("{") == -1:
833+
if string.find("{") == -1:
847834
return string
848835

849836
current_set, next_set = get_the_set(string)

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
OMPython is a Python interface that uses ZeroMQ to
44
communicate with OpenModelica.
55

6-
[![FMITest](https://github.com/OpenModelica/OMPython/actions/workflows/FMITest.yml/badge.svg)](https://github.com/OpenModelica/OMPython/actions/workflows/FMITest.yml)
76
[![Test](https://github.com/OpenModelica/OMPython/actions/workflows/Test.yml/badge.svg)](https://github.com/OpenModelica/OMPython/actions/workflows/Test.yml)
87

98
## Dependencies

tests/test_FMIRegression.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)