Skip to content

Commit 376fa80

Browse files
committed
Tetst+save_outputs.py: for COM, allow opening the editor; wrap faulthandler.
Without the editor, we cannot get the report filename sometimes Work around faulthandler when running pytest and fix some COM test issues.
1 parent f40b948 commit 376fa80

File tree

6 files changed

+71
-28
lines changed

6 files changed

+71
-28
lines changed

tests/save_outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def get_archive_fn(live_fn):
346346
import comtypes.client
347347
DSS = comtypes.client.CreateObject("OpenDSSEngine.DSS")
348348
DSS = dss.patch_dss_com(DSS)
349-
DSS.Text.Command = r'set editor=ignore_me_invalid_executable'
349+
#DSS.Text.Command = r'set editor=ignore_me_invalid_executable' -- need to let it open for some reports :|
350350
print("Using official OpenDSS COM:", DSS.Version)
351351
com_ver = DSS.Version.split(' ')[1]
352352
suffix = f'-COM-{platform.machine()}-{com_ver}'

tests/test_batch.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import os, io
2+
try:
3+
from ._settings import BASE_DIR, WIN32
4+
except ImportError:
5+
from _settings import BASE_DIR, WIN32
26
# import numpy as np
37
import pandas as pd
8+
if WIN32:
9+
# When running pytest, the faulthandler seems to eager to grab FPC's exceptions, even when handled
10+
import faulthandler
11+
faulthandler.disable()
12+
import dss
13+
faulthandler.enable()
14+
else:
15+
import dss
16+
417
from dss import dss, Edit, IDSS
518
from dss.IObj import (
619
Vsource, Transformer, LineCode, Load, Line, Capacitor,
720
Connection as Conn, RegControl, DimensionUnits as Units,
821
)
9-
try:
10-
from ._settings import BASE_DIR
11-
except ImportError:
12-
from _settings import BASE_DIR
13-
1422
LoadModel = Load.LoadModel
1523

1624
loads_cols = 'name,bus1,phases,conn,model,kV,kW,kvar'.split(',')

tests/test_ctrlqueue.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import numpy as np
77

88
try:
9-
from ._settings import BASE_DIR
9+
from ._settings import BASE_DIR, WIN32
1010
except ImportError:
11-
from _settings import BASE_DIR
11+
from _settings import BASE_DIR, WIN32
1212

1313

1414
USE_COM = False # Change to True to test with the COM DLL
@@ -17,7 +17,15 @@ def test_ctrlqueue():
1717
'''Example of implementing a simple voltage control for Capacitors via the interface'''
1818

1919
if not USE_COM:
20-
from dss import DSS as DSSobj
20+
if WIN32:
21+
# When running pytest, the faulthandler seems to eager to grab FPC's exceptions, even when handled
22+
import faulthandler
23+
faulthandler.disable()
24+
from dss import DSS as DSSobj
25+
faulthandler.enable()
26+
else:
27+
from dss import DSS as DSSobj
28+
2129
else:
2230
import os
2331
old_cd = os.getcwd()

tests/test_general.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@
33
# covers detailed check of API states, etc.
44
import sys, os, itertools, threading
55
from time import perf_counter
6-
import dss
7-
from dss import DSS, IDSS, DSSException, SparseSolverOptions, SolveModes, set_case_insensitive_attributes, DSSCompatFlags
8-
import numpy as np
9-
import pytest
106
try:
117
from ._settings import BASE_DIR, ZIP_FN, WIN32
128
except ImportError:
139
from _settings import BASE_DIR, ZIP_FN, WIN32
1410

11+
if WIN32:
12+
# When running pytest, the faulthandler seems to eager to grab FPC's exceptions, even when handled
13+
import faulthandler
14+
faulthandler.disable()
15+
import dss
16+
faulthandler.enable()
17+
else:
18+
import dss
19+
20+
from dss import DSS, IDSS, DSSException, SparseSolverOptions, SolveModes, set_case_insensitive_attributes, DSSCompatFlags
21+
import numpy as np
22+
import pytest
23+
1524

1625
def setup_function():
1726
DSS.ClearAll()
@@ -589,10 +598,10 @@ def test_essentials(DSS: IDSS = DSS):
589598
Text.Command = 'new line.line1 bus=1 bus2=2'
590599
Text.Command = 'new line.line2 bus=2 bus2=3'
591600
assert DSS.ActiveCircuit.Name == 'test789'
592-
assert len(DSS.ActiveCircuit.Buses) == 0
601+
assert len(DSS.ActiveCircuit.ActiveBus) == 0
593602
Text.Command = 'MakeBusList'
594-
assert len(DSS.ActiveCircuit.Buses) == 4
595-
for expected, b in zip(['sourcebus', '1', '2', '3'], DSS.ActiveCircuit.Buses):
603+
assert len(DSS.ActiveCircuit.ActiveBus) == 4
604+
for expected, b in zip(['sourcebus', '1', '2', '3'], DSS.ActiveCircuit.ActiveBus):
596605
assert expected == b.Name
597606

598607

@@ -605,7 +614,8 @@ def test_patch_comtypes():
605614
def test_patch_win32com():
606615
if WIN32:
607616
import win32com.client
608-
DSS_COM = dss.patch_dss_com(win32com.client.Dispatch("OpenDSSengine.DSS"))
617+
win32com.client.Dispatch("OpenDSSengine.DSS")
618+
DSS_COM = dss.patch_dss_com(win32com.client.gencache.EnsureDispatch("OpenDSSengine.DSS"))
609619
test_essentials(DSS_COM)
610620

611621
if __name__ == '__main__':

tests/test_obj.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import numpy as np
2+
try:
3+
from ._settings import BASE_DIR, WIN32
4+
except ImportError:
5+
from _settings import BASE_DIR, WIN32
6+
7+
if WIN32:
8+
# When running pytest, the faulthandler seems to eager to grab FPC's exceptions, even when handled
9+
import faulthandler
10+
faulthandler.disable()
11+
import dss
12+
faulthandler.enable()
13+
else:
14+
import dss
15+
216
from dss import dss, Edit, IDSS #, YMatrixModes
317
from dss.IObj import (
418
Vsource, Transformer, LineCode, Load, Line, Capacitor,
519
Connection as Conn, RegControl, DimensionUnits as Units,
620
)
7-
try:
8-
from ._settings import BASE_DIR
9-
except ImportError:
10-
from _settings import BASE_DIR
21+
1122

1223

1324
LoadModel = Load.LoadModel

tests/test_past_issues.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
import numpy as np
66
import pytest
77

8-
WIN32 = (sys.platform == 'win32')
9-
DSS.AllowEditor = False
10-
if os.path.exists('../../electricdss-tst/'):
11-
BASE_DIR = os.path.abspath('../../electricdss-tst/')
12-
ZIP_FN = os.path.abspath('data/13Bus.zip')
8+
try:
9+
from ._settings import BASE_DIR, WIN32, ZIP_FN
10+
except ImportError:
11+
from _settings import BASE_DIR, WIN32, ZIP_FN
12+
13+
if WIN32:
14+
# When running pytest, the faulthandler seems to eager to grab FPC's exceptions, even when handled
15+
import faulthandler
16+
faulthandler.disable()
17+
import dss
18+
faulthandler.enable()
1319
else:
14-
BASE_DIR = os.path.abspath('../electricdss-tst/')
15-
ZIP_FN = os.path.abspath('tests/data/13Bus.zip')
20+
import dss
1621

22+
DSS.AllowEditor = False
1723

1824
def test_rxmatrix():
1925
DSS.ClearAll()

0 commit comments

Comments
 (0)