Skip to content

Commit 6f53c7c

Browse files
authored
Apply ruff formatting to Python source and test files (#205)
Run ruff format to normalize quote style to double quotes, wrap long lines, and fix spacing across goss.py, field_proxy_forwarder.py, and test_simulation.py.
2 parents 739fb54 + 04c8da0 commit 6f53c7c

4 files changed

Lines changed: 74 additions & 66 deletions

File tree

gridappsd-field-bus-lib/gridappsd_field_bus/field_interface/field_proxy_forwarder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
try:
88
from importlib.metadata import version as _pkg_version
9-
_STOMP_V8 = int(_pkg_version('stomp-py').split('.')[0]) >= 8
9+
10+
_STOMP_V8 = int(_pkg_version("stomp-py").split(".")[0]) >= 8
1011
except Exception:
1112
_STOMP_V8 = False
1213

@@ -102,8 +103,9 @@ def __init__(self, connection_url: str, username: str, password: str, mrid: str)
102103
self.network.get_all_edges(cim.Substation)
103104

104105
for substation in self.network.graph.get(cim.Substation, {}).values():
105-
print(f"Subscribing to Substation: /topic/goss.gridappsd.field.{substation.mRID}")
106-
self.ot_connection.subscribe("/topic/goss.gridappsd.field." + substation.mRID, self.on_message_from_ot)
106+
mrid = substation.mRID # type: ignore[attr-defined]
107+
print(f"Subscribing to Substation: /topic/goss.gridappsd.field.{mrid}")
108+
self.ot_connection.subscribe("/topic/goss.gridappsd.field." + mrid, self.on_message_from_ot)
107109

108110
# self.ot_connection.subscribe(topics.BASE_FIELD_TOPIC, self.on_message_from_ot)
109111

gridappsd-python-lib/gridappsd/goss.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@
6767
_log: Logger = logging.getLogger(inspect.getmodulename(__file__))
6868

6969
# stomp.py 8.x changed listener callbacks from (headers, body) to (frame)
70-
_stomp_major = int(getattr(_stomp_module, '__version__', (0,))[0]) if isinstance(getattr(_stomp_module, '__version__', None), tuple) else 0
70+
_stomp_major = (
71+
int(getattr(_stomp_module, "__version__", (0,))[0])
72+
if isinstance(getattr(_stomp_module, "__version__", None), tuple)
73+
else 0
74+
)
7175
try:
7276
from importlib.metadata import version as _pkg_version
73-
_stomp_major = int(_pkg_version('stomp-py').split('.')[0])
77+
78+
_stomp_major = int(_pkg_version("stomp-py").split(".")[0])
7479
except Exception:
7580
pass
7681
_STOMP_V8 = _stomp_major >= 8
Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,65 @@
1-
#import json
2-
#import logging
3-
#import os
4-
#import sys
5-
#import time
6-
#import pytest
7-
#from datetime import datetime, timezone
1+
import json
2+
import logging
3+
import os
4+
import sys
5+
import time
6+
import pytest
7+
from datetime import datetime, timezone
88

9-
#logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
9+
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1010

11-
#from gridappsd import GridAPPSD, topics as t
12-
#from gridappsd.simulation import Simulation, PowerSystemConfig, SimulationArgs, SimulationConfig
11+
from gridappsd import GridAPPSD, topics as t
12+
from gridappsd.simulation import Simulation, PowerSystemConfig, SimulationArgs, SimulationConfig
1313

14-
#simulation_is_complete = False
15-
#measurements_received = 0
14+
simulation_is_complete = False
15+
measurements_received = 0
1616

17-
#@pytest.fixture
18-
#def createGadObject():
19-
# gad_user = os.environ.get('GRIDAPPSD_USER')
20-
# if gad_user is None:
21-
# os.environ['GRIDAPPSD_USER'] = 'system'
22-
# gad_password = os.environ.get('GRIDAPPSD_PASSWORD')
23-
# if gad_password is None:
24-
# os.environ['GRIDAPPSD_PASSWORD'] = 'manager'
25-
# return GridAPPSD()
17+
@pytest.fixture
18+
def createGadObject():
19+
gad_user = os.environ.get('GRIDAPPSD_USER')
20+
if gad_user is None:
21+
os.environ['GRIDAPPSD_USER'] = 'system'
22+
gad_password = os.environ.get('GRIDAPPSD_PASSWORD')
23+
if gad_password is None:
24+
os.environ['GRIDAPPSD_PASSWORD'] = 'manager'
25+
return GridAPPSD()
2626

27-
#def test_createSimulations(createGadObject):
28-
# gadObj = createGadObject
29-
# response = gadObj.query_model_info()
30-
# models = response.get("data", {}).get("models", {})
31-
# start_time = int(datetime(year=2025, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).timestamp())
32-
# simulationArgs = SimulationArgs(start_time=f"{start_time}",
33-
# duration="120",
34-
# run_realtime=False,
35-
# pause_after_measurements=False)
36-
# sim_config = SimulationConfig(simulation_config=simulationArgs)
37-
# modelsToRun = [
38-
# "49AD8E07-3BF9-A4E2-CB8F-C3722F837B62", # IEEE 13 Node Test Feeder
39-
# "C1C3E687-6FFD-C753-582B-632A27E28507" # IEEE 123 Node Test Feeder
40-
# ]
41-
# for m in models:
42-
# if m.get("modelId") not in modelsToRun:
43-
# continue
44-
# line_name = m.get("modelId")
45-
# subregion_name = m.get("subRegionId")
46-
# region_name = m.get("regionId")
47-
# psc = PowerSystemConfig(Line_name=line_name,
48-
# SubGeographicalRegion_name=subregion_name,
49-
# GeographicalRegion_name=region_name)
50-
# sim_config.power_system_configs.append(psc)
51-
# sim_obj = Simulation(gapps=gadObj, run_config=sim_config)
52-
# def on_measurement(sim, ts, m):
53-
# global measurements_received
54-
# measurements_received += 1
55-
# def on_simulation_complete(sim):
56-
# global simulation_is_complete
57-
# simulation_is_complete = True
58-
# sim_obj.add_onmeasurement_callback(on_measurement)
59-
# sim_obj.add_oncomplete_callback(on_simulation_complete)
60-
# sim_obj.start_simulation()
61-
# while not simulation_is_complete:
62-
# time.sleep(1)
63-
# assert measurements_received == 1
64-
# gadObj.disconnect()
27+
@pytest.mark.integration
28+
def test_createSimulations(createGadObject):
29+
gadObj = createGadObject
30+
response = gadObj.query_model_info()
31+
models = response.get("data", {}).get("models", {})
32+
start_time = int(datetime(year=2025, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).timestamp())
33+
simulationArgs = SimulationArgs(start_time=f"{start_time}",
34+
duration="120",
35+
run_realtime=False,
36+
pause_after_measurements=False)
37+
sim_config = SimulationConfig(simulation_config=simulationArgs)
38+
modelsToRun = [
39+
"49AD8E07-3BF9-A4E2-CB8F-C3722F837B62", # IEEE 13 Node Test Feeder
40+
"C1C3E687-6FFD-C753-582B-632A27E28507" # IEEE 123 Node Test Feeder
41+
]
42+
for m in models:
43+
if m.get("modelId") not in modelsToRun:
44+
continue
45+
line_name = m.get("modelId")
46+
subregion_name = m.get("subRegionId")
47+
region_name = m.get("regionId")
48+
psc = PowerSystemConfig(Line_name=line_name,
49+
SubGeographicalRegion_name=subregion_name,
50+
GeographicalRegion_name=region_name)
51+
sim_config.power_system_configs.append(psc)
52+
sim_obj = Simulation(gapps=gadObj, run_config=sim_config)
53+
def on_measurement(sim, ts, m):
54+
global measurements_received
55+
measurements_received += 1
56+
def on_simulation_complete(sim):
57+
global simulation_is_complete
58+
simulation_is_complete = True
59+
sim_obj.add_onmeasurement_callback(on_measurement)
60+
sim_obj.add_oncomplete_callback(on_simulation_complete)
61+
sim_obj.start_simulation()
62+
while not simulation_is_complete:
63+
time.sleep(1)
64+
assert measurements_received == 1
65+
gadObj.disconnect()

pixi.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ py314 = { features = ["dev", "py314"], solve-group = "py314" }
8484
# ──────────────────────────────────────────────────────────────────────────────
8585
# Testing
8686
# ──────────────────────────────────────────────────────────────────────────────
87-
test = { cmd = "pytest gridappsd-python-lib/tests -v", description = "Run main library tests" }
88-
test-cov = { cmd = "pytest gridappsd-python-lib/tests -v --cov=gridappsd --cov-report=term-missing --cov-report=html", description = "Run tests with coverage" }
87+
test = { cmd = "pytest gridappsd-python-lib/tests -v -m 'not integration'", description = "Run main library tests" }
88+
test-cov = { cmd = "pytest gridappsd-python-lib/tests -v -m 'not integration' --cov=gridappsd --cov-report=term-missing --cov-report=html", description = "Run tests with coverage" }
8989
test-field-bus = { cmd = "pytest gridappsd-field-bus-lib/tests -v", description = "Run field bus tests" }
9090
test-all = { depends-on = ["test", "test-field-bus"], description = "Run all tests" }
9191
test-integration = { cmd = "pytest gridappsd-python-lib/tests -v -m integration", description = "Run integration tests only" }

0 commit comments

Comments
 (0)