Skip to content

Commit ce0f41d

Browse files
committed
Meters: Extend error checking
validate.py: ignore the new exception in ActiveCircuit.CktElements
1 parent 2cb62b7 commit ce0f41d

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

dss/dss_capi_gr/IMeters.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,58 @@ class IMeters(Base):
1111

1212
def CloseAllDIFiles(self):
1313
self._lib.Meters_CloseAllDIFiles()
14+
self.CheckForError()
1415

1516
def DoReliabilityCalc(self, AssumeRestoration):
1617
self._lib.Meters_DoReliabilityCalc(AssumeRestoration)
18+
self.CheckForError()
1719

1820
def OpenAllDIFiles(self):
1921
self._lib.Meters_OpenAllDIFiles()
22+
self.CheckForError()
2023

2124
def Reset(self):
2225
self._lib.Meters_Reset()
26+
self.CheckForError()
2327

2428
def ResetAll(self):
2529
self._lib.Meters_ResetAll()
30+
self.CheckForError()
2631

2732
def Sample(self):
2833
self._lib.Meters_Sample()
34+
self.CheckForError()
2935

3036
def SampleAll(self):
3137
self._lib.Meters_SampleAll()
38+
self.CheckForError()
3239

3340
def Save(self):
3441
self._lib.Meters_Save()
42+
self.CheckForError()
3543

3644
def SaveAll(self):
3745
self._lib.Meters_SaveAll()
46+
self.CheckForError()
3847

3948
def SetActiveSection(self, SectIdx):
4049
self._lib.Meters_SetActiveSection(SectIdx)
50+
self.CheckForError()
4151

4252
@property
4353
def AllBranchesInZone(self):
4454
'''(read-only) Wide string list of all branches in zone of the active energymeter object.'''
45-
return self._get_string_array(self._lib.Meters_Get_AllBranchesInZone)
55+
return self._get_string_array(self.CheckForError(self._lib.Meters_Get_AllBranchesInZone))
4656

4757
@property
4858
def AllEndElements(self):
4959
'''(read-only) Array of names of all zone end elements.'''
50-
return self._get_string_array(self._lib.Meters_Get_AllEndElements)
60+
return self._get_string_array(self.CheckForError(self._lib.Meters_Get_AllEndElements))
5161

5262
@property
5363
def AllNames(self):
5464
'''(read-only) Array of all energy Meter names'''
55-
return self._get_string_array(self._lib.Meters_Get_AllNames)
65+
return self._get_string_array(self.CheckForError(self._lib.Meters_Get_AllNames))
5666

5767
@property
5868
def AllocFactors(self):
@@ -69,7 +79,7 @@ def AllocFactors(self, Value):
6979
@property
7080
def AvgRepairTime(self):
7181
'''(read-only) Average Repair time in this section of the meter zone'''
72-
return self._lib.Meters_Get_AvgRepairTime()
82+
return self.CheckForError(self._lib.Meters_Get_AvgRepairTime())
7383

7484
@property
7585
def CalcCurrent(self):
@@ -168,7 +178,7 @@ def Next(self):
168178
@property
169179
def NumSectionBranches(self):
170180
'''(read-only) Number of branches (lines) in this section'''
171-
return self._lib.Meters_Get_NumSectionBranches()
181+
return self.CheckForError(self._lib.Meters_Get_NumSectionBranches())
172182

173183
@property
174184
def NumSectionCustomers(self):
@@ -183,7 +193,7 @@ def NumSections(self):
183193
@property
184194
def OCPDeviceType(self):
185195
'''(read-only) Type of OCP device. 1=Fuse; 2=Recloser; 3=Relay'''
186-
return self._lib.Meters_Get_OCPDeviceType()
196+
return self.CheckForError(self._lib.Meters_Get_OCPDeviceType())
187197

188198
@property
189199
def Peakcurrent(self):

dss/dss_capi_ir/IMeters.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,58 @@ class IMeters(Base):
1111

1212
def CloseAllDIFiles(self):
1313
self._lib.Meters_CloseAllDIFiles()
14+
self.CheckForError()
1415

1516
def DoReliabilityCalc(self, AssumeRestoration):
1617
self._lib.Meters_DoReliabilityCalc(AssumeRestoration)
18+
self.CheckForError()
1719

1820
def OpenAllDIFiles(self):
1921
self._lib.Meters_OpenAllDIFiles()
22+
self.CheckForError()
2023

2124
def Reset(self):
2225
self._lib.Meters_Reset()
26+
self.CheckForError()
2327

2428
def ResetAll(self):
2529
self._lib.Meters_ResetAll()
30+
self.CheckForError()
2631

2732
def Sample(self):
2833
self._lib.Meters_Sample()
34+
self.CheckForError()
2935

3036
def SampleAll(self):
3137
self._lib.Meters_SampleAll()
38+
self.CheckForError()
3239

3340
def Save(self):
3441
self._lib.Meters_Save()
42+
self.CheckForError()
3543

3644
def SaveAll(self):
3745
self._lib.Meters_SaveAll()
46+
self.CheckForError()
3847

3948
def SetActiveSection(self, SectIdx):
4049
self._lib.Meters_SetActiveSection(SectIdx)
50+
self.CheckForError()
4151

4252
@property
4353
def AllBranchesInZone(self):
4454
'''(read-only) Wide string list of all branches in zone of the active energymeter object.'''
45-
return self._get_string_array(self._lib.Meters_Get_AllBranchesInZone)
55+
return self._get_string_array(self.CheckForError(self._lib.Meters_Get_AllBranchesInZone))
4656

4757
@property
4858
def AllEndElements(self):
4959
'''(read-only) Array of names of all zone end elements.'''
50-
return self._get_string_array(self._lib.Meters_Get_AllEndElements)
60+
return self._get_string_array(self.CheckForError(self._lib.Meters_Get_AllEndElements))
5161

5262
@property
5363
def AllNames(self):
5464
'''(read-only) Array of all energy Meter names'''
55-
return self._get_string_array(self._lib.Meters_Get_AllNames)
65+
return self._get_string_array(self.CheckForError(self._lib.Meters_Get_AllNames))
5666

5767
@property
5868
def AllocFactors(self):
@@ -68,7 +78,7 @@ def AllocFactors(self, Value):
6878
@property
6979
def AvgRepairTime(self):
7080
'''(read-only) Average Repair time in this section of the meter zone'''
71-
return self._lib.Meters_Get_AvgRepairTime()
81+
return self.CheckForError(self._lib.Meters_Get_AvgRepairTime())
7282

7383
@property
7484
def CalcCurrent(self):
@@ -166,7 +176,7 @@ def Next(self):
166176
@property
167177
def NumSectionBranches(self):
168178
'''(read-only) Number of branches (lines) in this section'''
169-
return self._lib.Meters_Get_NumSectionBranches()
179+
return self.CheckForError(self._lib.Meters_Get_NumSectionBranches())
170180

171181
@property
172182
def NumSectionCustomers(self):
@@ -181,7 +191,7 @@ def NumSections(self):
181191
@property
182192
def OCPDeviceType(self):
183193
'''(read-only) Type of OCP device. 1=Fuse; 2=Recloser; 3=Relay'''
184-
return self._lib.Meters_Get_OCPDeviceType()
194+
return self.CheckForError(self._lib.Meters_Get_OCPDeviceType())
185195

186196
@property
187197
def Peakcurrent(self):

tests/validate.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from scipy.sparse import csc_matrix
66
from dss import enums
77
import pickle
8+
from dss import DssException
89

910
original_working_dir = os.getcwd()
1011
NO_PROPERTIES = os.getenv('DSS_PYTHON_VALIDATE') == 'NOPROP'
@@ -370,7 +371,7 @@ def validate_LineCodes(self):
370371
fA = output['ActiveCircuit.LineCodes[{}].{}'.format(nA, field)] if LOAD_COM_OUTPUT else getattr(A, field)
371372
fB = getattr(B, field)
372373
if SAVE_COM_OUTPUT: output['ActiveCircuit.LineCodes[{}].{}'.format(nA, field)] = fA
373-
if not SAVE_COM_OUTPUT: assert fA == fB, field
374+
if not SAVE_COM_OUTPUT: assert fA == fB or np.allclose(fA, fB, atol=self.atol, rtol=self.rtol), (field, fA, fB)
374375

375376
nB = B.Next
376377
if not LOAD_COM_OUTPUT:
@@ -959,12 +960,20 @@ def validate_Circuit(self):
959960
if not SAVE_COM_OUTPUT: assert A.Name == B.Name
960961

961962
# Try to use an invalid index
962-
B = self.capi.ActiveCircuit.CktElements(999999)
963+
try:
964+
B = self.capi.ActiveCircuit.CktElements(999999)
965+
except DssException:
966+
pass
967+
963968
A = self.com.ActiveCircuit.CktElements(999999)
964969
if not SAVE_COM_OUTPUT: assert A.Name == B.Name
965970

966971
# Try to use an invalid name
967-
B = self.capi.ActiveCircuit.CktElements('NONEXISTENT_123456789')
972+
try:
973+
B = self.capi.ActiveCircuit.CktElements('NONEXISTENT_123456789')
974+
except DssException:
975+
pass
976+
968977
A = self.com.ActiveCircuit.CktElements('NONEXISTENT_123456789')
969978
if not SAVE_COM_OUTPUT: assert A.Name == B.Name
970979

0 commit comments

Comments
 (0)