Skip to content

Commit

Permalink
test(types_test): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-chauhan committed Aug 12, 2021
1 parent 6428a09 commit b41a722
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions tests/github/types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from honeybee_vtk.model import Model

file_path = r'tests/assets/gridbased.hbjson'
hb_model = HBModel.from_hbjson(file_path)
model = Model.from_hbjson(file_path)


Expand All @@ -21,7 +22,73 @@ def test_polydata_initialization():
assert not polydata._fields


def test_metadata():
def test_add_metadata_face():
"""Test adding metadata to a honeybee face."""
polydata = PolyData()
face = hb_model.rooms[0].faces[0]
polydata._add_metadata(face)
assert polydata.name == 'TestRoom_1..Face0'
assert polydata.type == 'Wall'
assert polydata.identifier == 'TestRoom_1..Face0'
assert polydata.boundary == 'Outdoors'
assert polydata.construction == 'Generic Exterior Wall'
assert polydata.modifier == 'generic_wall_0.50'


def test_add_metadata_aperture():
"""Test adding metadata to a honeybee aperture."""
polydata = PolyData()
aperture = hb_model.rooms[0].faces[0].apertures[0]
polydata._add_metadata(aperture)
assert polydata.name == '47275c62-30dd-4f95-839e-075834ec6d99_1'
assert polydata.type == 'Aperture'
assert polydata.identifier == '47275c62-30dd-4f95-839e-075834ec6d99_1'
assert polydata.boundary == 'Outdoors'
assert polydata.construction == 'Generic Double Pane'
assert polydata.modifier == 'g_material'


def test_add_metadata_shade():
"""Test adding metadata to a honeybee shade."""
polydata = PolyData()
shade = hb_model.rooms[0].faces[0].apertures[0].outdoor_shades[0]
polydata._add_metadata(shade)
assert polydata.name == '47275c62-30dd-4f95-839e-075834ec6d99_1_OutBorder0'
assert polydata.type == 'Shade'
assert polydata.identifier == '47275c62-30dd-4f95-839e-075834ec6d99_1_OutBorder0'
assert polydata.construction == 'Generic Shade'
assert polydata.modifier == 'generic_exterior_shade_0.35'


def test_get_metadata_face():
"""Test getting metadata out from a Polydata created from a honeybee face."""
polydata = PolyData()
face = hb_model.rooms[0].faces[0]
polydata._add_metadata(face)
num_of_cells = polydata.GetNumberOfCells()
metadata = polydata._get_metadata()
assert isinstance(metadata, dict)
for key, value in metadata.items():
assert key in ['Name', 'Boundary', 'Construction', 'Modifier']
assert len(value) == num_of_cells
assert value.count(key) == num_of_cells


def test_get_metadata_shade():
"""Test getting metadata out from a Polydata created from a honeybee shade."""
polydata = PolyData()
shade = hb_model.rooms[0].faces[0].apertures[0].outdoor_shades[0]
polydata._add_metadata(shade)
num_of_cells = polydata.GetNumberOfCells()
metadata = polydata._get_metadata()
assert isinstance(metadata, dict)
for key, value in metadata.items():
assert key in ['Name', 'Construction', 'Modifier']
assert len(value) == num_of_cells
assert value.count(key) == num_of_cells


def test_metadata_assignment():
"""Test whether metadata is being correctly assigned as cell data."""

for ds in model:
Expand All @@ -31,7 +98,7 @@ def test_metadata():

if ds.name != 'Shade':
assert polydata.boundary == polydata.GetCellData(
).GetAbstractArray('Boundary Condition').GetValue(0)
).GetAbstractArray('Boundary').GetValue(0)

assert polydata.construction == polydata.GetCellData(
).GetAbstractArray('Construction').GetValue(0)
Expand Down

0 comments on commit b41a722

Please sign in to comment.