Skip to content

Commit

Permalink
Typos various tests with yaml tests parser attempt3 (#24599)
Browse files Browse the repository at this point in the history
* [matter_yamltests] Make definitions.py more strict about casing

* Fix various typos in src/app/tests/suites/ yaml tests (#3 attempt)
  • Loading branch information
vivien-apple authored Jan 24, 2023
1 parent 57cd02e commit 95c1888
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 130 deletions.
41 changes: 30 additions & 11 deletions scripts/py_matter_yamltests/matter_yamltests/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,24 @@ def __init__(self, sources: List[ParseSource]):

self.__clusters_by_name[name] = cluster.code
self.__commands_by_name[name] = {
c.name.lower(): c.code for c in cluster.commands}
c.name: c.code for c in cluster.commands}
self.__responses_by_name[name] = {}
self.__attributes_by_name[name] = {
a.definition.name.lower(): a.definition.code for a in cluster.attributes}
a.definition.name: a.definition.code for a in cluster.attributes}
self.__events_by_name[name] = {
e.name.lower(): e.code for e in cluster.events}
e.name: e.code for e in cluster.events}

self.__bitmaps_by_name[name] = {
b.name.lower(): b for b in cluster.bitmaps}
b.name: b for b in cluster.bitmaps}
self.__enums_by_name[name] = {
e.name.lower(): e for e in cluster.enums}
e.name: e for e in cluster.enums}
self.__structs_by_name[name] = {
s.name.lower(): s for s in cluster.structs}
s.name: s for s in cluster.structs}

for struct in cluster.structs:
if struct.tag == StructTag.RESPONSE:
self.__responses_by_id[code][struct.code] = struct
self.__responses_by_name[name][struct.name.lower(
)] = struct.code
self.__responses_by_name[name][struct.name] = struct.code

def get_cluster_name(self, cluster_id: int) -> str:
cluster = self.__clusters_by_id.get(cluster_id)
Expand Down Expand Up @@ -153,9 +152,6 @@ def __get_by_name(self, cluster_name: str, target_name: str, target_type: _ItemT

# The idl parser remove spaces
cluster_name = cluster_name.replace(' ', '')
# Many YAML tests formats the name using camelCase despites that the spec mandates
# CamelCase. To be compatible with the current tests, everything is converted to lower case.
target_name = target_name.lower()

cluster_id = self.__clusters_by_name.get(cluster_name)
if cluster_id is None:
Expand All @@ -164,26 +160,40 @@ def __get_by_name(self, cluster_name: str, target_name: str, target_type: _ItemT
target = None

if target_type == _ItemType.Request:
self.__enforce_casing(
target_name, self.__commands_by_name.get(cluster_name))
target_id = self.__commands_by_name.get(
cluster_name).get(target_name)
target = self.__get_by_id(cluster_id, target_id, target_type)
elif target_type == _ItemType.Response:
self.__enforce_casing(
target_name, self.__responses_by_name.get(cluster_name))
target_id = self.__responses_by_name.get(
cluster_name).get(target_name)
target = self.__get_by_id(cluster_id, target_id, target_type)
elif target_type == _ItemType.Event:
self.__enforce_casing(
target_name, self.__events_by_name.get(cluster_name))
target_id = self.__events_by_name.get(
cluster_name).get(target_name)
target = self.__get_by_id(cluster_id, target_id, target_type)
elif target_type == _ItemType.Attribute:
self.__enforce_casing(
target_name, self.__attributes_by_name.get(cluster_name))
target_id = self.__attributes_by_name.get(
cluster_name).get(target_name)
target = self.__get_by_id(cluster_id, target_id, target_type)
elif target_type == _ItemType.Bitmap:
self.__enforce_casing(
target_name, self.__bitmaps_by_name.get(cluster_name))
target = self.__bitmaps_by_name.get(cluster_name).get(target_name)
elif target_type == _ItemType.Enum:
self.__enforce_casing(
target_name, self.__enums_by_name.get(cluster_name))
target = self.__enums_by_name.get(cluster_name).get(target_name)
elif target_type == _ItemType.Struct:
self.__enforce_casing(
target_name, self.__structs_by_name.get(cluster_name))
target = self.__structs_by_name.get(cluster_name).get(target_name)

return target
Expand All @@ -204,3 +214,12 @@ def __get_by_id(self, cluster_id: int, target_id: int, target_type: str):
return None

return targets.get(target_id)

def __enforce_casing(self, target_name: str, targets: list):
if targets.get(target_name) is not None:
return

for name in targets:
if name.lower() == target_name.lower():
raise KeyError(
f'Unknown target {target_name}. Did you mean {name} ?')
38 changes: 19 additions & 19 deletions scripts/py_matter_yamltests/test_spec_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from matter_yamltests.definitions import *

import unittest
import io
import unittest

from matter_yamltests.definitions import *

source_cluster = '''<?xml version="1.0"?>
<configurator>
Expand Down Expand Up @@ -215,8 +215,8 @@ def test_get_command_by_name(self):
'Test', 'TestCommand'), Command)
self.assertIsNone(
definitions.get_command_by_name('test', 'TestCommand'))
self.assertIsInstance(definitions.get_command_by_name(
'Test', 'testcommand'), Command)
self.assertRaises(KeyError, definitions.get_command_by_name,
'Test', 'testcommand')

def test_get_response_by_name(self):
definitions = SpecDefinitions(
Expand All @@ -231,8 +231,8 @@ def test_get_response_by_name(self):
'Test', 'TestCommandResponse'), Struct)
self.assertIsNone(definitions.get_response_by_name(
'test', 'TestCommandResponse'))
self.assertIsInstance(definitions.get_response_by_name(
'Test', 'testcommandresponse'), Struct)
self.assertRaises(KeyError, definitions.get_response_by_name,
'Test', 'testcommandresponse')

def test_get_attribute_by_name(self):
definitions = SpecDefinitions(
Expand All @@ -251,10 +251,10 @@ def test_get_attribute_by_name(self):
'test', 'TestAttribute'))
self.assertIsNone(definitions.get_attribute_by_name(
'test', 'TestGlobalAttribute'))
self.assertIsInstance(definitions.get_attribute_by_name(
'Test', 'testattribute'), Attribute)
self.assertIsInstance(definitions.get_attribute_by_name(
'Test', 'testglobalattribute'), Attribute)
self.assertRaises(KeyError, definitions.get_attribute_by_name,
'Test', 'testattribute')
self.assertRaises(KeyError, definitions.get_attribute_by_name,
'Test', 'testglobalattribute')

def test_get_event_by_name(self):
definitions = SpecDefinitions(
Expand All @@ -266,8 +266,8 @@ def test_get_event_by_name(self):
self.assertIsInstance(
definitions.get_event_by_name('Test', 'TestEvent'), Event)
self.assertIsNone(definitions.get_event_by_name('test', 'TestEvent'))
self.assertIsInstance(
definitions.get_event_by_name('Test', 'testevent'), Event)
self.assertRaises(
KeyError, definitions.get_event_by_name, 'Test', 'testevent')

def test_get_bitmap_by_name(self):
definitions = SpecDefinitions(
Expand All @@ -279,8 +279,8 @@ def test_get_bitmap_by_name(self):
self.assertIsInstance(definitions.get_bitmap_by_name(
'Test', 'TestBitmap'), Bitmap)
self.assertIsNone(definitions.get_bitmap_by_name('test', 'TestBitmap'))
self.assertIsInstance(definitions.get_bitmap_by_name(
'Test', 'testbitmap'), Bitmap)
self.assertRaises(KeyError, definitions.get_bitmap_by_name,
'Test', 'testbitmap')

def test_get_enum_by_name(self):
definitions = SpecDefinitions(
Expand All @@ -292,8 +292,8 @@ def test_get_enum_by_name(self):
self.assertIsInstance(
definitions.get_enum_by_name('Test', 'TestEnum'), Enum)
self.assertIsNone(definitions.get_enum_by_name('test', 'TestEnum'))
self.assertIsInstance(
definitions.get_enum_by_name('Test', 'testenum'), Enum)
self.assertRaises(
KeyError, definitions.get_enum_by_name, 'Test', 'testenum')

def test_get_struct_by_name(self):
definitions = SpecDefinitions(
Expand All @@ -305,8 +305,8 @@ def test_get_struct_by_name(self):
self.assertIsInstance(definitions.get_struct_by_name(
'Test', 'TestStruct'), Struct)
self.assertIsNone(definitions.get_struct_by_name('test', 'TestStruct'))
self.assertIsInstance(definitions.get_struct_by_name(
'Test', 'teststruct'), Struct)
self.assertRaises(
KeyError, definitions.get_struct_by_name, 'Test', 'teststruct')

def test_get_type_by_name(self):
definitions = SpecDefinitions(
Expand Down
6 changes: 3 additions & 3 deletions src/app/tests/suites/TV_AccountLoginCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tests:
value: nodeId

- label: "Get Setup PIN Command"
command: "getSetupPIN"
command: "GetSetupPIN"
timedInteractionTimeoutMs: 10000
arguments:
values:
Expand All @@ -40,7 +40,7 @@ tests:
- name: "SetupPIN"
value: "tempPin123"
- label: "Login Command"
command: "login"
command: "Login"
timedInteractionTimeoutMs: 10000
arguments:
values:
Expand All @@ -50,5 +50,5 @@ tests:
value: "tempPin123"

- label: "Logout Command"
command: "logout"
command: "Logout"
timedInteractionTimeoutMs: 10000
6 changes: 3 additions & 3 deletions src/app/tests/suites/TV_ApplicationLauncherCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests:
value: null

- label: "Launch App Command"
command: "launchApp"
command: "LaunchApp"
arguments:
values:
- name: "Data"
Expand All @@ -56,7 +56,7 @@ tests:
value: 0

- label: "Stop App Command"
command: "stopApp"
command: "StopApp"
arguments:
values:
- name: "Application"
Expand All @@ -69,7 +69,7 @@ tests:
value: 0

- label: "Hide App Command"
command: "hideApp"
command: "HideApp"
arguments:
values:
- name: "Application"
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/suites/TV_AudioOutputCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ tests:
value: 1

- label: "Select Output Command"
command: "selectOutput"
command: "SelectOutput"
arguments:
values:
- name: "Index"
value: 1

- label: "Rename Output Command"
command: "renameOutput"
command: "RenameOutput"
arguments:
values:
- name: "Index"
Expand Down
6 changes: 3 additions & 3 deletions src/app/tests/suites/TV_ChannelCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ tests:
}

- label: "Change Channel Command"
command: "changeChannel"
command: "ChangeChannel"
arguments:
values:
- name: "Match"
Expand All @@ -103,7 +103,7 @@ tests:
value: 0

- label: "Change Channel By Number Command"
command: "changeChannelByNumber"
command: "ChangeChannelByNumber"
arguments:
values:
- name: "MajorNumber"
Expand All @@ -112,7 +112,7 @@ tests:
value: 0

- label: "Skip Channel Command"
command: "skipChannel"
command: "SkipChannel"
arguments:
values:
- name: "Count"
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/suites/TV_ContentLauncherCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests:
value: 0

- label: "Launch Content Command"
command: "launchContent"
command: "LaunchContent"
arguments:
values:
- name: "AutoPlay"
Expand Down Expand Up @@ -69,7 +69,7 @@ tests:
value: 0

- label: "Launch URL Command"
command: "launchURL"
command: "LaunchURL"
arguments:
values:
- name: "ContentURL"
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/TV_KeypadInputCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tests:
value: nodeId

- label: "Send Key Command"
command: "sendKey"
command: "SendKey"
arguments:
values:
- name: "KeyCode"
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/TV_LowPowerCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ tests:
value: nodeId

- label: "Sleep Input Status Command"
command: "sleep"
command: "Sleep"
8 changes: 4 additions & 4 deletions src/app/tests/suites/TV_MediaInputCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ tests:
value: 1

- label: "Select Input Command"
command: "selectInput"
command: "SelectInput"
arguments:
values:
- name: "Index"
value: 1

- label: "Hide Input Status Command"
command: "hideInputStatus"
command: "HideInputStatus"

- label: "Show Input Status Command"
command: "showInputStatus"
command: "ShowInputStatus"

- label: "Rename Input Command"
command: "renameInput"
command: "RenameInput"
arguments:
values:
- name: "Index"
Expand Down
Loading

0 comments on commit 95c1888

Please sign in to comment.