Skip to content

Commit 941e153

Browse files
committed
type checking in check_valid_params
1 parent 7214293 commit 941e153

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed
177 Bytes
Binary file not shown.

pygridsim/parameters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def check_valid_params(params, valid_params):
4848
for key in params:
4949
if key not in valid_params:
5050
raise KeyError(f"Parameter {key} is not supported")
51+
if not isinstance(params[key], (int, float)):
52+
raise TypeError("Parameter input should be int or float")
5153
if key in ["kV", "BasekV"] and params[key] < 0:
5254
raise ValueError("KV cannot be less than 0")
5355

sim.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"Voltages": {
3-
"source": 2275.42083457249,
4-
"load0": 174.86504811289413
3+
"source": 2077.428822659733,
4+
"load0": 217.52249209519556
55
},
66
"Losses": {
7-
"Active Power Loss": 331250.37737900193,
8-
"Reactive Power Loss": 688674.6517717106
7+
"Active Power Loss": 284917.58902059204,
8+
"Reactive Power Loss": 592389.8824783975
99
}
1010
}
256 Bytes
Binary file not shown.

tests/test_circuit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def test_003_one_source_one_load_exhaustive(self):
6868
circuit.add_load_nodes(num=1, load_type=load_type.value)
6969
circuit.add_lines([("source", "load0")], line_type.value)
7070
circuit.solve()
71-
print("LineType:", line_type, "SourceType", source_type, "LoadType", load_type)
72-
print(circuit.results(["Voltages", "Losses"]))
71+
#print("LineType:", line_type, "SourceType", source_type, "LoadType", load_type)
72+
#print(circuit.results(["Voltages", "Losses"]))
7373
circuit.clear()
7474

7575

@@ -251,6 +251,11 @@ def test_103_invalid_nodes_in_line(self):
251251
with self.assertRaises(ValueError):
252252
# only has source, load0 for now but tries to add another one
253253
circuit.add_lines([("source", "load5")])
254+
255+
def test_104_non_int_parameters(self):
256+
circuit = PyGridSim()
257+
with self.assertRaises(TypeError):
258+
circuit.add_load_nodes(params={"kV": "stringInput"})
254259

255260

256261
class TestLargeCircuit(unittest.TestCase):

0 commit comments

Comments
 (0)