| # Copyright 2026 The Pigweed 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 |
| # |
| # https://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 unittest |
| import os |
| import tempfile |
| import shutil |
| import sys |
| |
| # Import the script to test |
| sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
| import parse_test_metadata |
| |
| class TestParseTestMetadata(unittest.TestCase): |
| def setUp(self): |
| self.test_dir = tempfile.mkdtemp() |
| |
| def tearDown(self): |
| shutil.rmtree(self.test_dir) |
| |
| def test_lightweight_yaml_parse_platform_allow(self): |
| file_path = os.path.join(self.test_dir, "testcase.yaml") |
| |
| # Test simple list |
| with open(file_path, 'w') as f: |
| f.write(""" |
| platform_allow: |
| - board1 |
| - board2 |
| """) |
| platforms = parse_test_metadata.lightweight_yaml_parse_platform_allow(file_path) |
| self.assertEqual(platforms, ["board1", "board2"]) |
| |
| def test_lightweight_yaml_parse_platform_allow_empty(self): |
| file_path = os.path.join(self.test_dir, "testcase.yaml") |
| |
| # Test no platform_allow |
| with open(file_path, 'w') as f: |
| f.write(""" |
| other_field: value |
| """) |
| platforms = parse_test_metadata.lightweight_yaml_parse_platform_allow(file_path) |
| self.assertEqual(platforms, []) |
| |
| def test_lightweight_yaml_parse_platform_allow_complex(self): |
| file_path = os.path.join(self.test_dir, "testcase.yaml") |
| |
| # Test complex YAML structure similar to with_mcumgr |
| with open(file_path, 'w') as f: |
| f.write(""" |
| common: |
| sysbuild: true |
| platform_allow: |
| - board1 |
| - board2 |
| tests: |
| test1: |
| platform_allow: |
| - board3 |
| """) |
| platforms = parse_test_metadata.lightweight_yaml_parse_platform_allow(file_path) |
| # It should pick the first platform_allow (in common) |
| self.assertEqual(platforms, ["board1", "board2", "board3"]) |
| |
| if __name__ == '__main__': |
| unittest.main() |