1414# limitations under the License.
1515#
1616
17+ ''' Module for testing targets. '''
18+
1719import os
1820import shutil
1921import tempfile
2022from unittest import TestCase
2123
2224from devlib import LocalLinuxTarget
25+ from devlib .utils .misc import load_struct_from_yaml
2326
2427
2528class TestReadTreeValues (TestCase ):
29+ ''' Class testing Target.read_tree_values_flat() '''
30+
31+ TARGETS_CONFIG_FILE = 'tests/target_configs.yaml'
2632
2733 def test_read_multiline_values (self ):
34+ ''' Test Target.read_tree_values_flat() '''
35+
36+ target_configs = load_struct_from_yaml (self .TARGETS_CONFIG_FILE )
37+ if target_configs is None or target_configs .get ('LocalLinuxTarget' ) is None :
38+ print (f'No target(s) specified in { self .TARGETS_CONFIG_FILE } !' )
39+ return
40+
2841 data = {
2942 'test1' : '1' ,
3043 'test2' : '2\n \n ' ,
@@ -34,11 +47,13 @@ def test_read_multiline_values(self):
3447 tempdir = tempfile .mkdtemp (prefix = 'devlib-test-' )
3548 for key , value in data .items ():
3649 path = os .path .join (tempdir , key )
37- with open (path , 'w' ) as wfh :
50+ with open (path , 'w' , encoding = 'utf-8' ) as wfh :
3851 wfh .write (value )
3952
40- t = LocalLinuxTarget (connection_settings = {'unrooted' : True })
41- raw_result = t .read_tree_values_flat (tempdir )
53+ target = LocalLinuxTarget (
54+ connection_settings = target_configs ['LocalLinuxTarget' ]['connection_settings' ],
55+ )
56+ raw_result = target .read_tree_values_flat (tempdir )
4257 result = {os .path .basename (k ): v for k , v in raw_result .items ()}
4358
4459 shutil .rmtree (tempdir )
0 commit comments