Last active
July 31, 2024 13:37
-
-
Save jmarrec/26b2610474e4ae4d2b6251d2a756fb32 to your computer and use it in GitHub Desktop.
Test removing connections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openstudio | |
import pytest | |
def test_remove_connections(): | |
m = openstudio.model.Model() | |
p = openstudio.model.PlantLoop(m) | |
c = openstudio.model.CoilCoolingWater(m) | |
n_ori = len(m.getObjectsByType("OS:Connection")) | |
assert n_ori == 12 | |
p.addDemandBranchForComponent(c) | |
assert len(m.getObjectsByType("OS:Connection")) == n_ori + 2 | |
c.remove() | |
assert len(m.getObjectsByType("OS:Connection")) == n_ori | |
p.remove() | |
assert len(m.getObjectsByType("OS:Connection")) == 0 | |
# This allows running openstudio CLI on this file (`openstudio test_measure.py`, maybe with extra args) | |
if __name__ == "__main__": | |
import sys | |
if len(sys.argv) > 1: | |
pytest.main([__file__] + sys.argv[1:]) | |
else: | |
pytest.main([__file__]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openstudio' | |
include OpenStudio::Model | |
m = Model.new | |
p = PlantLoop.new(m) | |
c = CoilCoolingWater.new(m) | |
n_ori = m.getObjectsByType("OS:Connection".to_IddObjectType).size | |
raise unless n_ori == 12 | |
p.addDemandBranchForComponent(c) | |
raise unless m.getObjectsByType("OS:Connection".to_IddObjectType).size == n_ori + 2 | |
c.remove | |
raise unless m.getObjectsByType("OS:Connection".to_IddObjectType).size == n_ori | |
p.remove | |
raise unless m.getObjectsByType("OS:Connection".to_IddObjectType).size == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment