Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML test parser #24066

Merged
merged 23 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
98bef42
Initial commit of 3 files from Vivien's branch
tehampson Dec 2, 2022
011180e
Adding a test commit containing a TODO
andy31415 Dec 2, 2022
1ef84a6
Restyle
andy31415 Dec 2, 2022
4fcd6a1
Small tweaks plus adding unit test
tehampson Dec 5, 2022
1b410ef
Refactor constraints
tehampson Dec 6, 2022
ce47d84
[Yaml Parser] Add scripts/tests/yamltests/SpecDefinitions.py with som…
vivien-apple Dec 6, 2022
b06cbd2
[Yaml Parser] Use SpecDefinitions API instead of ClusterDefinitions
vivien-apple Dec 6, 2022
c680b7b
[Yaml Parser] Uses convert_yaml_octet_string_to_bytes for octet_string
vivien-apple Dec 6, 2022
1115306
[Yaml Parser / Constraints] Move the check for None before the type c…
vivien-apple Dec 7, 2022
1c5f1cb
[Yaml Parser] Add _convert_single_value_to_values and make it sooner …
vivien-apple Dec 6, 2022
e36f684
Small fixes
tehampson Dec 7, 2022
310122b
[Yaml Parser] Moves _convert_single_value_to_values up one block such…
vivien-apple Dec 7, 2022
e6d3919
Move `__update_placeholder` to TestStep
tehampson Dec 7, 2022
6eba146
Add docstring, and initial constraint parsing
tehampson Dec 12, 2022
06218a3
Refactor for TestStep into two parts
tehampson Dec 12, 2022
ad4fa77
Converge to PEP8 python format standard
tehampson Dec 12, 2022
a4067e0
Add and clean up doc strings
tehampson Dec 13, 2022
005cc7e
Attempt at creating a python package
tehampson Dec 13, 2022
6151607
Make Restyle Happy
tehampson Dec 14, 2022
08a1677
Clean up yaml parser unit test to be self contained
tehampson Dec 14, 2022
7b2100d
Fix test name
tehampson Dec 14, 2022
8573cfd
Fix test name
tehampson Dec 14, 2022
0036de8
Address PR comments
tehampson Dec 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions scripts/tests/test_yaml_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Copyright (c) 2022 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# TODO Once yamltest is a proper self contained module we can move this file
# to a more appropriate spot. For now, having this file to do some quick checks
# is arguably better then no checks at all.

import io
import tempfile
import unittest

from yamltests.definitions import *
from yamltests.parser import TestParser

simple_test_description = '''<?xml version="1.0"?>
<configurator>
<struct name="TestStruct">
<cluster code="0x1234"/>
<item name="a" type="boolean"/>
</struct>

<cluster>
<name>Test</name>
<code>0x1234</code>
</cluster>

</configurator>
'''

simple_test_yaml = '''
name: Test Cluster Tests

config:
nodeId: 0x12344321
cluster: "Test"
endpoint: 1

tests:
- label: "Send Test Command"
command: "test"

- label: "Send Test Not Handled Command"
command: "testNotHandled"
response:
error: INVALID_COMMAND

- label: "Send Test Specific Command"
command: "testSpecific"
response:
values:
- name: "returnValue"
value: 7
'''


class TestYamlParser(unittest.TestCase):
def setUp(self):
self._definitions = SpecDefinitions(
[ParseSource(source=io.StringIO(simple_test_description), name='simple_test_description')])
self._temp_file = tempfile.NamedTemporaryFile(suffix='.yaml')
with open(self._temp_file.name, 'w') as f:
f.writelines(simple_test_yaml)
pics_file = None
self._yaml_parser = TestParser(self._temp_file.name, pics_file, self._definitions)

def test_able_to_iterate_over_all_parsed_tests(self):
# self._yaml_parser.tests implements `__next__`, which does value substitution. We are
# simply ensure there is no exceptions raise.
count = 0
for idx, test_step in enumerate(self._yaml_parser.tests):
count += 1
pass
self.assertEqual(count, 3)


def main():
unittest.main()


if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions scripts/tests/yamltests/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python.gni")

pw_python_package("yamltests") {
setup = [ "setup.py" ]

sources = [
"__init__.py",
"constraints.py",
"definitions.py",
"fixes.py",
"parser.py",
]

python_deps = [ "${chip_root}/scripts/idl" ]

tests = [ "test_spec_definitions.py" ]

# TODO: at a future time consider enabling all (* or missing) here to get
# pylint checking these files
static_analysis = []
}
Empty file.
Loading