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 = os .path .join (os .path .dirname (os .path .realpath (__file__ )),
32+ 'target_configs.yaml' )
2633
2734 def test_read_multiline_values (self ):
35+ """Test Target.read_tree_values_flat()"""
36+
37+ target_configs = load_struct_from_yaml (self .TARGETS_CONFIG_FILE )
38+ if target_configs is None or target_configs .get ('LocalLinuxTarget' ) is None :
39+ print (f'No target(s) specified in { self .TARGETS_CONFIG_FILE } !' )
40+ return
41+
2842 data = {
2943 'test1' : '1' ,
3044 'test2' : '2\n \n ' ,
@@ -34,11 +48,13 @@ def test_read_multiline_values(self):
3448 tempdir = tempfile .mkdtemp (prefix = 'devlib-test-' )
3549 for key , value in data .items ():
3650 path = os .path .join (tempdir , key )
37- with open (path , 'w' ) as wfh :
51+ with open (path , 'w' , encoding = 'utf-8' ) as wfh :
3852 wfh .write (value )
3953
40- t = LocalLinuxTarget (connection_settings = {'unrooted' : True })
41- raw_result = t .read_tree_values_flat (tempdir )
54+ target = LocalLinuxTarget (
55+ connection_settings = target_configs ['LocalLinuxTarget' ]['connection_settings' ],
56+ )
57+ raw_result = target .read_tree_values_flat (tempdir )
4258 result = {os .path .basename (k ): v for k , v in raw_result .items ()}
4359
4460 shutil .rmtree (tempdir )
0 commit comments