|
1 |
| -#!/usr/bin/python3 |
2 | 1 | # Copyright (c) 2024 Project CHIP Authors
|
3 | 2 | #
|
4 | 3 | # Licensed under the Apache License, Version 2.0 (the "License");
|
|
13 | 12 | # See the License for the specific language governing permissions and
|
14 | 13 | # limitations under the License.
|
15 | 14 |
|
16 |
| -import os |
| 15 | +import tempfile |
17 | 16 | import unittest
|
18 | 17 | from os import path
|
| 18 | +from typing import List |
19 | 19 |
|
20 | 20 | from metadata import Metadata, MetadataReader
|
21 | 21 |
|
22 | 22 |
|
23 | 23 | class TestMetadataReader(unittest.TestCase):
|
24 |
| - path_under_test = path_under_test = path.join(path.dirname(__file__), "simple_run_args.txt") |
25 | 24 |
|
26 | 25 | def setUp(self):
|
27 |
| - |
28 | 26 | # build the reader object
|
29 | 27 | self.reader = MetadataReader(path.join(path.dirname(__file__), "env_test.yaml"))
|
30 |
| - with open(self.path_under_test, 'w', encoding='utf8') as test_file: |
31 |
| - test_file.writelines(''' |
32 |
| - # test-runner-runs: run1 |
33 |
| - # test-runner-run/run1: app/all-clusters discriminator KVS storage-path commissioning-method discriminator passcode |
34 |
| - ''') |
35 |
| - |
36 |
| - def test_parse_single_run(self): |
37 | 28 |
|
38 |
| - expected_runs_metadata = [] |
| 29 | + def assertMetadataParse(self, file_content: str, expected: List[Metadata]): |
| 30 | + with tempfile.NamedTemporaryFile(mode='w', delete=False) as fp: |
| 31 | + fp.write(file_content) |
| 32 | + fp.close() |
| 33 | + for e in expected: |
| 34 | + e.py_script_path = fp.name |
| 35 | + actual = self.reader.parse_script(fp.name) |
| 36 | + self.assertEqual(actual, expected) |
39 | 37 |
|
40 |
| - expected_runs_metadata.append(Metadata(app="out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app", |
41 |
| - discriminator=1234, py_script_path=self.path_under_test, run="run1", passcode=20202021)) |
42 |
| - |
43 |
| - self.assertEqual(self.reader.parse_script(self.path_under_test), expected_runs_metadata) |
44 |
| - |
45 |
| - def tearDown(self): |
46 |
| - if os.path.exists(self.path_under_test): |
47 |
| - os.remove(self.path_under_test) |
| 38 | + def test_parse_single_run(self): |
| 39 | + self.assertMetadataParse(''' |
| 40 | + # test-runner-runs: run1 |
| 41 | + # test-runner-run/run1: app/all-clusters discriminator passcode |
| 42 | + ''', |
| 43 | + [ |
| 44 | + Metadata(app="out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app", |
| 45 | + discriminator=1234, run="run1", passcode=20202021) |
| 46 | + ] |
| 47 | + ) |
48 | 48 |
|
49 | 49 |
|
50 | 50 | if __name__ == "__main__":
|
|
0 commit comments