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");
16
15
import os
17
16
import unittest
18
17
from os import path
18
+ import tempfile
19
+ from typing import List
19
20
20
21
from metadata import Metadata , MetadataReader
21
22
22
23
23
24
class TestMetadataReader (unittest .TestCase ):
24
- path_under_test = path_under_test = path .join (path .dirname (__file__ ), "simple_run_args.txt" )
25
+ path_under_test = path .join (path .dirname (__file__ ), "simple_run_args.txt" )
25
26
26
27
def setUp (self ):
27
-
28
28
# build the reader object
29
29
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
30
38
- expected_runs_metadata = []
31
+ def assertMetadataParse (self , file_content : str , expected : List [Metadata ]):
32
+ with tempfile .NamedTemporaryFile (mode = 'w' , delete = False ) as fp :
33
+ fp .write (file_content )
34
+ fp .close ()
35
+ for e in expected :
36
+ e .py_script_path = fp .name
37
+ actual = self .reader .parse_script (fp .name )
38
+ self .assertEqual (actual , expected )
39
39
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 )
48
40
41
+ def test_parse_single_run (self ):
42
+ self .assertMetadataParse ('''
43
+ # test-runner-runs: run1
44
+ # test-runner-run/run1: app/all-clusters discriminator passcode
45
+ ''' ,
46
+ [
47
+ Metadata (app = "out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app" ,
48
+ discriminator = 1234 , py_script_path = self .path_under_test , run = "run1" , passcode = 20202021 )
49
+ ]
50
+ )
49
51
50
52
if __name__ == "__main__" :
51
- unittest .main ()
53
+ unittest .main ()
0 commit comments