Skip to content

Commit 992ce8c

Browse files
committed
Extends holdsConstruction - 01
1 parent 9638a1e commit 992ce8c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/osut/osut.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ def genShade(subs=None) -> bool:
602602
A list of sub surfaces.
603603
604604
Returns:
605-
True: If successfully generated shade.
606-
False: if invalid input (see logs).
605+
True: If shade successfully generated.
606+
False: If invalid input (see logs).
607607
608608
"""
609609
# Filter OpenStudio warnings for ShadingControl:
@@ -612,10 +612,9 @@ def genShade(subs=None) -> bool:
612612
# openstudio.Logger().instance().standardOutLogger().setChannelRegex(str)
613613

614614
mth = "osut.genShade"
615-
v = int("".join(openstudio.openStudioVersion().split(".")))
616-
cl = openstudio.model.SubSurfaceVector
615+
cl = openstudio.model.SubSurfaceVector
617616

618-
if v < 321:
617+
if int("".join(openstudio.openStudioVersion().split("."))) < 321:
619618
return False
620619
if not isinstance(subs, cl):
621620
return oslg.mismatch("subs", subs, cl, mth, CN.DBG, False)
@@ -779,8 +778,7 @@ def genMass(sps=None, ratio=2.0) -> bool:
779778

780779

781780
def holdsConstruction(set=None, base=None, gr=False, ex=False, type=""):
782-
"""Validates whether a default construction set holds an opaque base
783-
construction.
781+
"""Validates whether a default construction set holds a base construction.
784782
785783
Args:
786784
set (openstudio.model.DefaultConstructionSet):
@@ -802,11 +800,15 @@ def holdsConstruction(set=None, base=None, gr=False, ex=False, type=""):
802800
mth = "osut.holdsConstruction"
803801
cl1 = openstudio.model.DefaultConstructionSet
804802
cl2 = openstudio.model.ConstructionBase
803+
t1 = openstudio.model.Surface.validSurfaceTypeValues()
804+
t2 = openstudio.model.SubSurface.validSubSurfaceTypeValues()
805+
t1 = [t.lower() for t in t1]
806+
t2 = [t.lower() for t in t2]
805807

806808
if not isinstance(set, cl1):
807-
return oslg.invalid("set" , mth, 1, CN.DBG, False)
809+
return oslg.mismatch("set", set, cl1, mth, CN.DBG, False)
808810
if not isinstance(base, cl2):
809-
return oslg.invalid("base", mth, 2, CN.DBG, False)
811+
return oslg.mismatch("base", base, cl2, mth, CN.DBG, False)
810812
if gr not in [True, False]:
811813
return oslg.invalid("ground", mth, 3, CN.DBG, False)
812814
if ex not in [True, False]:
@@ -819,7 +821,7 @@ def holdsConstruction(set=None, base=None, gr=False, ex=False, type=""):
819821

820822
type = type.lower()
821823

822-
if type not in ["floor", "wall", "roofceiling"]:
824+
if type not in (t1 + t2):
823825
return oslg.invalid("surface type", mth, 5, CN.DBG, False)
824826

825827
constructions = None

tests/test_osut.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,8 @@ def test08_holds_constructions(self):
884884
n1 = "CBECS Before-1980 ClimateZone 8 (smoff) ConstSet"
885885
n2 = "CBECS Before-1980 ExtRoof IEAD ClimateZone 8"
886886
m5 = "Invalid 'surface type' arg #5 (osut.holdsConstruction)"
887-
m6 = "Invalid 'set' arg #1 (osut.holdsConstruction)"
887+
m6 = "'set' LayeredConstruction? expecting DefaultConstructionSet"
888+
m7 = "'set' Model? expecting DefaultConstructionSet"
888889
set = model.getDefaultConstructionSetByName(n1)
889890
c = model.getLayeredConstructionByName(n2)
890891
self.assertTrue(set)
@@ -893,6 +894,7 @@ def test08_holds_constructions(self):
893894
c = c.get()
894895

895896
# TRUE case: 'set' holds 'c' (exterior roofceiling construction).
897+
answer = osut.holdsConstruction(set, c, False, True, t1)
896898
self.assertTrue(osut.holdsConstruction(set, c, False, True, t1))
897899
self.assertEqual(o.status(), 0)
898900

@@ -925,14 +927,14 @@ def test08_holds_constructions(self):
925927
self.assertFalse(osut.holdsConstruction(c, c, True, True, c))
926928
self.assertTrue(o.is_debug())
927929
self.assertEqual(len(o.logs()), 1)
928-
self.assertEqual(o.logs()[0]["message"], m6)
930+
self.assertTrue(m6 in o.logs()[0]["message"])
929931
self.assertEqual(o.clean(), DBG)
930932

931933
# INVALID case: arg #1 : model (instead of surface type string).
932934
self.assertFalse(osut.holdsConstruction(mdl, c, True, True, t1))
933935
self.assertTrue(o.is_debug())
934936
self.assertEqual(len(o.logs()), 1)
935-
self.assertEqual(o.logs()[0]["message"], m6)
937+
self.assertTrue(m7 in o.logs()[0]["message"])
936938
self.assertEqual(o.clean(), DBG)
937939

938940
del(model)

0 commit comments

Comments
 (0)