From cd7bea95bce604ee1615e383bf0c0d84d266044a Mon Sep 17 00:00:00 2001 From: Metin Kaya Date: Mon, 5 Feb 2024 08:36:19 +0000 Subject: [PATCH] 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 --- tests/target_configs.yaml | 4 ++++ tests/test_target.py | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/target_configs.yaml diff --git a/tests/target_configs.yaml b/tests/target_configs.yaml new file mode 100644 index 000000000..443cb9489 --- /dev/null +++ b/tests/target_configs.yaml @@ -0,0 +1,4 @@ +LocalLinuxTarget: + connection_settings: + unrooted: True + diff --git a/tests/test_target.py b/tests/test_target.py index 230aa35e6..18c1701fd 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -14,17 +14,30 @@ # 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 = 'tests/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', @@ -34,11 +47,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)