From 7318c7209126d22bbae9349ec5f05668271401fd Mon Sep 17 00:00:00 2001
From: Vatsal Ghelani <vghelani@csa-iot.org>
Date: Tue, 16 Apr 2024 11:01:39 -0400
Subject: [PATCH 1/5] Modified the test script with the changes recommended

---
 scripts/tests/py/test_metadata.py | 42 ++++++++++++++++---------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/scripts/tests/py/test_metadata.py b/scripts/tests/py/test_metadata.py
index 7c2594d08134c2..693e978db48875 100644
--- a/scripts/tests/py/test_metadata.py
+++ b/scripts/tests/py/test_metadata.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python3
 # Copyright (c) 2024 Project CHIP Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,36 +15,39 @@
 import os
 import unittest
 from os import path
+import tempfile
+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")
+    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, py_script_path=self.path_under_test, run="run1", passcode=20202021)
+            ]
+        )
 
 if __name__ == "__main__":
-    unittest.main()
+    unittest.main()
\ No newline at end of file

From 1c9ce0ce73e9ceac55596459d4aaecc52a7961ff Mon Sep 17 00:00:00 2001
From: Vatsal Ghelani <vghelani@csa-iot.org>
Date: Tue, 16 Apr 2024 11:42:34 -0400
Subject: [PATCH 2/5] Removed unwanted import os

---
 scripts/tests/py/test_metadata.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/scripts/tests/py/test_metadata.py b/scripts/tests/py/test_metadata.py
index 693e978db48875..41f2b825c2cd9a 100644
--- a/scripts/tests/py/test_metadata.py
+++ b/scripts/tests/py/test_metadata.py
@@ -12,7 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import os
 import unittest
 from os import path
 import tempfile

From 24e614a1aca068385986443068c854c495ab9663 Mon Sep 17 00:00:00 2001
From: Vatsal Ghelani <vghelani@csa-iot.org>
Date: Tue, 16 Apr 2024 12:51:35 -0400
Subject: [PATCH 3/5] Removed path_under_test as it is using TempFile

---
 scripts/tests/py/test_metadata.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/scripts/tests/py/test_metadata.py b/scripts/tests/py/test_metadata.py
index 41f2b825c2cd9a..34d0f76dad676c 100644
--- a/scripts/tests/py/test_metadata.py
+++ b/scripts/tests/py/test_metadata.py
@@ -21,7 +21,6 @@
 
 
 class TestMetadataReader(unittest.TestCase):
-    path_under_test = path.join(path.dirname(__file__), "simple_run_args.txt")
 
     def setUp(self):
         # build the reader object
@@ -44,7 +43,7 @@ def test_parse_single_run(self):
             ''',
             [
                 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)
+                         discriminator=1234, run="run1", passcode=20202021)
             ]
         )
 

From 0130c61f44c8ca938dbd110f00bcfb61c49addb6 Mon Sep 17 00:00:00 2001
From: "Restyled.io" <commits@restyled.io>
Date: Tue, 16 Apr 2024 16:51:57 +0000
Subject: [PATCH 4/5] Restyled by autopep8

---
 scripts/tests/py/test_metadata.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/tests/py/test_metadata.py b/scripts/tests/py/test_metadata.py
index 34d0f76dad676c..759e89e31bbaa6 100644
--- a/scripts/tests/py/test_metadata.py
+++ b/scripts/tests/py/test_metadata.py
@@ -35,17 +35,17 @@ def assertMetadataParse(self, file_content: str, expected: List[Metadata]):
             actual = self.reader.parse_script(fp.name)
             self.assertEqual(actual, expected)
 
-
     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)
-            ]
-        )
+                                 [
+                                     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__":
-    unittest.main()
\ No newline at end of file
+    unittest.main()

From bb627ae852560081a6fc607fdfb7df10dcd60641 Mon Sep 17 00:00:00 2001
From: "Restyled.io" <commits@restyled.io>
Date: Tue, 16 Apr 2024 16:51:58 +0000
Subject: [PATCH 5/5] Restyled by isort

---
 scripts/tests/py/test_metadata.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/tests/py/test_metadata.py b/scripts/tests/py/test_metadata.py
index 759e89e31bbaa6..8707d483026bfb 100644
--- a/scripts/tests/py/test_metadata.py
+++ b/scripts/tests/py/test_metadata.py
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import tempfile
 import unittest
 from os import path
-import tempfile
 from typing import List
 
 from metadata import Metadata, MetadataReader