Skip to content

Commit

Permalink
Update test_metadata.py to use temporary files for test cases, for ea…
Browse files Browse the repository at this point in the history
…sier extensibility (project-chip#33008)

* Modified the test script with the changes recommended

* Removed unwanted import os

* Removed path_under_test as it is using TempFile

* Restyled by autopep8

* Restyled by isort

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
vatsalghelani-csa and restyled-commits authored Apr 16, 2024
1 parent c065cc7 commit bfdb5da
Showing 1 changed file with 20 additions and 20 deletions.
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

0 comments on commit bfdb5da

Please sign in to comment.