Skip to content

Commit

Permalink
Update src/python_testing/TC_TSTAT_4_2.py
Browse files Browse the repository at this point in the history
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
nivi-apple and bzbarsky-apple authored Aug 28, 2024
1 parent 8282355 commit bdb91fb
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions src/python_testing/TC_TSTAT_4_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,49 +499,28 @@ async def test_TC_TSTAT_4_2(self):
if totalExpectedPresetsLength > numberOfPresetsSupported:
testPresets = []
for presetType in presetTypes:
didCopyPreset = False
isBuiltInPreset = False
scenario = presetType.presetScenario

# For each scenario, check if there are presets in the Presets attribute matching the scenario. If so, copy the presets into testPresets.
# For built in presets, we can't add more entries since we can't add a built in preset according to the spec. For non built-in presets,
# check if the total number of presets copied from the Presets attribute for each preset scenario is less than the number of presets supported
# for that preset scenario. If yes, add more entries until we have reached the maximum number of presets for the scenario.
# If we did not copy the presets, add entries up to the maximum number of presets supported for the preset scenario for this preset type.
# For each scenario, copy all the existing presets that match it, then add more presets
# until we hit the cap on the number of presets for that scenario.
presetsAddedForScenario = 0
for preset in presets:
if scenario == preset.presetScenario:
testPresets.append(preset)
didCopyPreset = True
isBuiltInPreset = True
break
++presetsAddedForScenario

if didCopyPreset and not isBuiltInPreset:
countNumberOfPresetsAdded = 0
for testPreset in testPresets:
if testPreset.presetScenario == scenario:
++countNumberOfPresetsAdded

if countNumberOfPresetsAdded < presetType.numberOfPresets:
testPresets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=scenario,
name="Preset", coolingSetpoint=2500, heatingSetpoint=1700, builtIn=False))
++countNumberOfPresetsAdded
elif not didCopyPreset and not len(testPresets) > numberOfPresetsSupported:
for index in range(presetType.numberOfPresets):
while presetsAddedForScenario < presetType.numberOfPresets:
testPresets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=scenario,
name="Preset", coolingSetpoint=2500, heatingSetpoint=1700, builtIn=False))
++presetsAddedForScenario

# Since for built in presets, we can't add any more entries. That might cause the size of testPresets not to exceed the number of presets supported.
# If so, skip the test.
if not len(testPresets) > numberOfPresetsSupported:
logger.info("Couldn't run test step 18 since we couldn't build a list that exceeds number of supported presets")
else:
# Send the AtomicRequest begin command
await self.send_atomic_request_begin_command()
# Send the AtomicRequest begin command
await self.send_atomic_request_begin_command()

await self.write_presets(endpoint=endpoint, presets=testPresets, expected_status=Status.ResourceExhausted)
await self.write_presets(endpoint=endpoint, presets=testPresets, expected_status=Status.ResourceExhausted)

# Clear state for next test.
await self.send_atomic_request_rollback_command()
# Clear state for next test.
await self.send_atomic_request_rollback_command()
else:
logger.info(
"Couldn't run test step 18 since there are not enough preset types to build a Presets list that exceeds the number of presets supported")
Expand Down

0 comments on commit bdb91fb

Please sign in to comment.