Skip to content

Commit 7756317

Browse files
committed
tests/test_target: Read target connection settings from a YAML file
This will be useful in automating CI tests without modifying the source code. Also fix pylint issues. Signed-off-by: Metin Kaya <metin.kaya@arm.com>
1 parent c5f3e92 commit 7756317

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

tests/target_configs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LocalLinuxTarget:
2+
connection_settings:
3+
unrooted: True
4+

tests/test_target.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,30 @@
1414
# limitations under the License.
1515
#
1616

17+
''' Module for testing targets. '''
18+
1719
import os
1820
import shutil
1921
import tempfile
2022
from unittest import TestCase
2123

2224
from devlib import LocalLinuxTarget
25+
from devlib.utils.misc import load_struct_from_yaml
2326

2427

2528
class 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

Comments
 (0)