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

Update test_metadata.py to use temporary files for test cases, for easier extensibility #33008

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
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
40 changes: 20 additions & 20 deletions scripts/tests/py/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/python3
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,38 +12,39 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import tempfile
import unittest
from os import path
from typing import List

from metadata import Metadata, MetadataReader


class TestMetadataReader(unittest.TestCase):
path_under_test = path_under_test = path.join(path.dirname(__file__), "simple_run_args.txt")

def setUp(self):

# build the reader object
self.reader = MetadataReader(path.join(path.dirname(__file__), "env_test.yaml"))
with open(self.path_under_test, 'w', encoding='utf8') as test_file:
test_file.writelines('''
# test-runner-runs: run1
# test-runner-run/run1: app/all-clusters discriminator KVS storage-path commissioning-method discriminator passcode
''')

def test_parse_single_run(self):

expected_runs_metadata = []
def assertMetadataParse(self, file_content: str, expected: List[Metadata]):
with tempfile.NamedTemporaryFile(mode='w', delete=False) as fp:
fp.write(file_content)
fp.close()
for e in expected:
e.py_script_path = fp.name
actual = self.reader.parse_script(fp.name)
self.assertEqual(actual, expected)

expected_runs_metadata.append(Metadata(app="out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app",
discriminator=1234, py_script_path=self.path_under_test, run="run1", passcode=20202021))

self.assertEqual(self.reader.parse_script(self.path_under_test), expected_runs_metadata)

def tearDown(self):
if os.path.exists(self.path_under_test):
os.remove(self.path_under_test)
def test_parse_single_run(self):
self.assertMetadataParse('''
# test-runner-runs: run1
# test-runner-run/run1: app/all-clusters discriminator passcode
''',
[
Metadata(app="out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app",
discriminator=1234, run="run1", passcode=20202021)
]
)


if __name__ == "__main__":
Expand Down
Loading