From b6ef8dafeab599924c42eaab1a70b1e8597919d7 Mon Sep 17 00:00:00 2001 From: "Travis F. Collins" Date: Tue, 9 Apr 2024 09:42:56 -0600 Subject: [PATCH] Fix issue where channel has no attributes and some minor lint issues Signed-off-by: Travis F. Collins --- pytest_libiio/meta.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pytest_libiio/meta.py b/pytest_libiio/meta.py index 8a436f2..9d1ba48 100644 --- a/pytest_libiio/meta.py +++ b/pytest_libiio/meta.py @@ -34,10 +34,13 @@ def __get_value_from_hw( elif ptype == "channel": dev = ctx.find_device(str(dev_name)) ch = dev.find_channel(str(ch_name), is_output) - try: - value = ch.attrs[attr_name].value - except OSError: - value = "ERROR" + if hasattr(ch, "attrs") and attr_name in ch.attrs: + try: + value = ch.attrs[attr_name].value + except OSError: + value = "ERROR" + else: + value = "NO ATTRS FOR CHANNEL" elif ptype == "debug": dev = ctx.find_device(str(dev_name)) try: @@ -150,12 +153,12 @@ def get_emulated_context(ctx: iio.Context): context_fields += ["description"] context_fields = list(set(context_fields)) template = "" + full = template + "".join(context_fields_list) + full = f"{full[:-1]}>" doctype = f"\n\ @@ -181,7 +184,7 @@ def get_emulated_context(ctx: iio.Context): xml_str = etree.tostring( tree, pretty_print=True, xml_declaration=True, doctype=doctype, encoding="utf-8" ) - xml_str = str(xml_str, "utf-8") + xml_str = str(xml_str, "utf-8") # type: ignore return xml_str