Fixing website and API documentation links
[PyCIM.git] / PyCIM / Test / CIM15Test.py
blob35cc645f596d0c0cb55ee088baae1088996b328d
1 # Copyright (C) 2010-2011 Richard Lincoln
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 # IN THE SOFTWARE.
21 import unittest
23 import pytest
25 from CIM15.IEC61970.Core import \
26 ConnectivityNode, Terminal, BaseVoltage
28 from CIM15.IEC61970.LoadModel import \
29 ConformLoad, ConformLoadGroup, LoadArea, ConformLoadSchedule
31 from CIM15.IEC61970.Meas import \
32 AnalogLimit, AnalogValue, Analog
34 from CIM15.IEC61970.Protection import \
35 CurrentRelay, ProtectionEquipment
37 from CIM15.IEC61970.Topology import \
38 TopologicalNode
40 from CIM15.IEC61970.Wires import \
41 Breaker, SynchronousMachine, BusbarSection, ACLineSegment, \
42 PowerTransformer, PowerTransformerEnd, ReactiveCapabilityCurve, \
43 EnergyConsumer, PerLengthPhaseImpedance, PerLengthSequenceImpedance, \
44 TransformerEnd
46 from CIM15.IEC61970.Generation.Production import \
47 ThermalGeneratingUnit, GenUnitOpCostCurve, GenUnitOpSchedule, StartupModel
50 from CIM15.IEC61970.WiresPhaseModel import \
51 EnergyConsumerPhase, ACLineSegmentPhase
54 class CIMTestCase(unittest.TestCase):
55 """Test the full CIM package.
56 """
58 def setUp(self):
59 """The test runner will execute this method prior to each test.
60 """
61 pass
63 def test_energy_consumer_phase_sets_attributes(self):
64 energy_consumer = EnergyConsumer()
65 energy_consumer_phase = EnergyConsumerPhase(
66 'A', energy_consumer, pfixed=100, qfixed=30)
67 assert energy_consumer_phase.phase == 'A'
68 assert energy_consumer_phase.EnergyConsumer == energy_consumer
69 assert energy_consumer_phase.pfixed == 100
70 assert energy_consumer_phase.qfixed == 30
72 def test_xfmr_end_sets_base_voltage(self):
73 base_voltage = BaseVoltage(nominalVoltage=4160)
74 xfmr_end_1 = TransformerEnd(BaseVoltage=base_voltage)
75 xfmr_end_2 = TransformerEnd(BaseVoltage=base_voltage)
76 assert xfmr_end_1.BaseVoltage == base_voltage
77 assert xfmr_end_2.BaseVoltage == base_voltage
78 assert set(base_voltage.TransformerEnd) == set(
79 [xfmr_end_1, xfmr_end_2])
81 def test_base_voltage_add_xfmr_ends(self):
82 xfmr_end_1 = TransformerEnd()
83 xfmr_end_2 = TransformerEnd()
84 base_voltage = BaseVoltage(TransformerEnd=[xfmr_end_1])
85 base_voltage.addTransformerEnd(xfmr_end_2)
86 assert set(base_voltage.TransformerEnd) == set(
87 [xfmr_end_1, xfmr_end_2])
88 assert xfmr_end_1.BaseVoltage == base_voltage
89 assert xfmr_end_2.BaseVoltage == base_voltage
91 def test_base_voltage_set_xfmr_ends(self):
92 xfmr_end_1 = TransformerEnd()
93 xfmr_end_2 = TransformerEnd()
94 xfmr_end_3 = TransformerEnd()
95 xfmr_end_4 = TransformerEnd()
96 base_voltage = BaseVoltage(TransformerEnd=[xfmr_end_1, xfmr_end_2])
97 assert set(base_voltage.TransformerEnd) == set(
98 [xfmr_end_1, xfmr_end_2])
99 assert xfmr_end_1.BaseVoltage == base_voltage
100 assert xfmr_end_2.BaseVoltage == base_voltage
101 base_voltage.setTransformerEnd([xfmr_end_3, xfmr_end_4])
102 assert set(base_voltage.TransformerEnd) == set(
103 [xfmr_end_3, xfmr_end_4])
104 assert xfmr_end_1.BaseVoltage == None
105 assert xfmr_end_2.BaseVoltage == None
106 assert xfmr_end_3.BaseVoltage == base_voltage
107 assert xfmr_end_4.BaseVoltage == base_voltage
109 def test_base_voltage_remove_xfmr_end(self):
110 xfmr_end_1 = TransformerEnd()
111 xfmr_end_2 = TransformerEnd()
112 base_voltage = BaseVoltage(TransformerEnd=[xfmr_end_1, xfmr_end_2])
113 base_voltage.removeTransformerEnd(xfmr_end_2)
114 assert base_voltage.TransformerEnd == [xfmr_end_1]
115 assert xfmr_end_2.BaseVoltage == None
116 assert xfmr_end_1.BaseVoltage == base_voltage
118 def testInstantiation(self):
119 """Test element instantiation.
121 ThermalGeneratingUnit(oMCost=6.0, variableCost=10.0)
122 GenUnitOpCostCurve(name="curve1", isNetGrossP=True)
123 GenUnitOpSchedule(timeStep=1.0)
124 StartupModel(name="model1", startupCost=20.0)
126 ConformLoad(aggregate=True, pfixed=30.0)
127 clg = ConformLoadGroup(aliasName="group1")
128 LoadArea(name="area1")
129 cls = ConformLoadSchedule(ConformLoadGroup=clg)
130 self.assertEqual(cls.ConformLoadGroup, clg)
132 AnalogLimit(value=100.0)
133 AnalogValue(value=6.0)
134 Analog(maxValue=100.0)
135 ProtectionEquipment(normallyInService=True)
136 CurrentRelay(inverseTimeFlag=True)
138 tn = TopologicalNode(name="tn1")
139 cn = ConnectivityNode(TopologicalNode=tn)
140 self.assertTrue(cn.TopologicalNode, tn)
141 Terminal(connected=True)
143 Breaker(ratedCurrent=20.0)
144 SynchronousMachine(coolantType="water")
145 BusbarSection(normallyInService=True)
146 ACLineSegment(r=0.1, length=10.0)
147 ReactiveCapabilityCurve(coolantTemperature=20.0)
148 te = PowerTransformerEnd(x0=0.1)
149 pt = PowerTransformer(PowerTransformerEnd=[te])
150 self.assertTrue(te in pt.PowerTransformerEnd)
153 def testOneToOne(self):
154 """Test one-to-one bidirectional references.
156 sm1 = StartupModel()
157 tgu1 = ThermalGeneratingUnit(StartupModel=sm1)
159 self.assertEqual(tgu1.StartupModel, sm1)
160 self.assertEqual(sm1.ThermalGeneratingUnit, tgu1)
162 tgu2 = ThermalGeneratingUnit()
163 tgu2.setStartupModel(sm1)
165 self.assertEqual(tgu1.StartupModel, None)
166 self.assertEqual(tgu2.StartupModel, sm1)
167 self.assertNotEqual(sm1.ThermalGeneratingUnit, tgu1)
168 self.assertTrue(sm1.ThermalGeneratingUnit, tgu2)
171 def testOneToMany(self):
172 """Test one-to-many bidirectional references.
174 lg1 = ConformLoadGroup(name="CLG1")
175 lg2 = ConformLoadGroup(name="CLG2")
176 cl = ConformLoad(name="Load 1", LoadGroup=lg1)
178 self.assertEqual(cl.LoadGroup, lg1)
179 self.assertTrue(cl in lg1.EnergyConsumers)
181 cl.setLoadGroup(lg2)
183 self.assertNotEqual(cl.LoadGroup, lg1)
184 self.assertEqual(cl.LoadGroup, lg2)
185 self.assertFalse(cl in lg1.EnergyConsumers)
186 self.assertTrue(cl in lg2.EnergyConsumers)
189 def testManyToOne(self):
190 """Test many-to-one bidirectional references.
192 te1 = PowerTransformerEnd()
193 te2 = PowerTransformerEnd()
194 pt1 = PowerTransformer(PowerTransformerEnd=[te1])
195 pt1.addPowerTransformerEnd(te2)
197 self.assertTrue(te1 in pt1.PowerTransformerEnd)
198 self.assertTrue(te2 in pt1.PowerTransformerEnd)
199 self.assertEqual(te1.PowerTransformer, pt1)
200 self.assertEqual(te2.PowerTransformer, pt1)
202 pt2 = PowerTransformer()
203 pt2.addPowerTransformerEnd(te2)
205 self.assertTrue(te1 in pt1.PowerTransformerEnd)
206 self.assertTrue(te2 in pt2.PowerTransformerEnd)
207 self.assertFalse(te2 in pt1.PowerTransformerEnd)
208 self.assertNotEqual(te2.PowerTransformer, pt1)
209 self.assertEqual(te2.PowerTransformer, pt2)
211 te3 = PowerTransformerEnd()
212 pt1.setPowerTransformerEnd([te3])
214 self.assertFalse(te1 in pt1.PowerTransformerEnd)
215 self.assertTrue(te3 in pt1.PowerTransformerEnd)
216 self.assertEqual(te1.PowerTransformer, None)
217 self.assertEqual(te3.PowerTransformer, pt1)
219 pt1.removePowerTransformerEnd(te3)
221 self.assertFalse(te3 in pt1.PowerTransformerEnd)
222 self.assertEqual(te3.PowerTransformer, None)
225 # def testManyToMany(self):
226 # """Test many-to-many bidirectional references.
227 # """
228 # sm1 = SynchronousMachine()
229 # sm2 = SynchronousMachine()
230 # rcc1 = ReactiveCapabilityCurve()
231 # sm1.add_reactive_capability_curves(rcc1)
232 # rcc2 = ReactiveCapabilityCurve(synchronous_machines=[sm2])
234 # self.assertTrue(sm1 in rcc1.synchronous_machines)
235 # self.assertTrue(rcc2 in sm2.reactive_capability_curves)
238 class ACLineSegmentTests(unittest.TestCase):
240 def test_ac_line_segment_phases_sets_attributes(self):
241 ac_line_segment = ACLineSegment()
242 ac_line_segment_phase = ACLineSegmentPhase('A', ac_line_segment)
243 assert ac_line_segment_phase.phase == 'A'
244 assert ac_line_segment_phase.ACLineSegment == ac_line_segment
246 def test_sets_per_length_impedance_given_phase(self):
247 per_length_phase_impedance = PerLengthPhaseImpedance()
248 ac_line_segment = ACLineSegment(
249 PhaseImpedance=per_length_phase_impedance)
250 assert ac_line_segment.PerLengthImpedance == per_length_phase_impedance
251 assert ac_line_segment.PhaseImpedance == per_length_phase_impedance
252 assert ac_line_segment.SequenceImpedance is None
254 def test_sets_per_length_impedance_given_sequence(self):
255 per_length_sequence_impedance = PerLengthSequenceImpedance()
256 ac_line_segment = ACLineSegment(
257 SequenceImpedance=per_length_sequence_impedance)
258 assert ac_line_segment.PerLengthImpedance == \
259 per_length_sequence_impedance
260 assert ac_line_segment.SequenceImpedance == \
261 per_length_sequence_impedance
262 assert ac_line_segment.PhaseImpedance is None
264 def test_sets_per_length_impedance_given_phase_via_generic(self):
265 per_length_phase_impedance = PerLengthPhaseImpedance()
266 ac_line_segment = ACLineSegment(
267 PerLengthImpedance=per_length_phase_impedance)
268 assert ac_line_segment.PerLengthImpedance == per_length_phase_impedance
269 assert ac_line_segment.PhaseImpedance == per_length_phase_impedance
270 assert ac_line_segment.SequenceImpedance is None
272 def test_sets_per_length_impedance_given_sequence_via_generic(self):
273 per_length_sequence_impedance = PerLengthSequenceImpedance()
274 ac_line_segment = ACLineSegment(
275 PerLengthImpedance=per_length_sequence_impedance)
276 assert ac_line_segment.PerLengthImpedance == per_length_sequence_impedance
277 assert ac_line_segment.SequenceImpedance == per_length_sequence_impedance
278 assert ac_line_segment.PhaseImpedance is None
280 def test_more_than_one_impedance_returns_error(self):
281 per_length_sequence_impedance = PerLengthSequenceImpedance()
282 per_length_phase_impedance = PerLengthPhaseImpedance()
283 with pytest.raises(ValueError):
284 ac_line_segment = ACLineSegment(
285 PhaseImpedance=per_length_phase_impedance,
286 SequenceImpedance=per_length_sequence_impedance)
289 if __name__ == "__main__":
290 unittest.main()