Skip to content

Commit 36731c5

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 fb8887f commit 36731c5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,31 @@
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 = 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

Comments
 (0)