Skip to content

Commit

Permalink
tests/test_target: Read target connection settings from a YAML file
Browse files Browse the repository at this point in the history
This will be useful in automating CI tests without modifying the source
code.

Also fix pylint issues.

Signed-off-by: Metin Kaya <[email protected]>
  • Loading branch information
metin-arm committed Feb 20, 2024
1 parent fb8887f commit 36731c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tests/target_configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LocalLinuxTarget:
connection_settings:
unrooted: True

22 changes: 19 additions & 3 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,31 @@
# limitations under the License.
#

"""Module for testing targets."""

import os
import shutil
import tempfile
from unittest import TestCase

from devlib import LocalLinuxTarget
from devlib.utils.misc import load_struct_from_yaml


class TestReadTreeValues(TestCase):
"""Class testing Target.read_tree_values_flat()"""

TARGETS_CONFIG_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'target_configs.yaml')

def test_read_multiline_values(self):
"""Test Target.read_tree_values_flat()"""

target_configs = load_struct_from_yaml(self.TARGETS_CONFIG_FILE)
if target_configs is None or target_configs.get('LocalLinuxTarget') is None:
print(f'No target(s) specified in {self.TARGETS_CONFIG_FILE}!')
return

data = {
'test1': '1',
'test2': '2\n\n',
Expand All @@ -34,11 +48,13 @@ def test_read_multiline_values(self):
tempdir = tempfile.mkdtemp(prefix='devlib-test-')
for key, value in data.items():
path = os.path.join(tempdir, key)
with open(path, 'w') as wfh:
with open(path, 'w', encoding='utf-8') as wfh:
wfh.write(value)

t = LocalLinuxTarget(connection_settings={'unrooted': True})
raw_result = t.read_tree_values_flat(tempdir)
target = LocalLinuxTarget(
connection_settings=target_configs['LocalLinuxTarget']['connection_settings'],
)
raw_result = target.read_tree_values_flat(tempdir)
result = {os.path.basename(k): v for k, v in raw_result.items()}

shutil.rmtree(tempdir)
Expand Down

0 comments on commit 36731c5

Please sign in to comment.