From 7df47f2e39731690db2dd3d18490d0d915308a8a Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 20 Mar 2024 03:25:29 -0500 Subject: [PATCH] fix: Test xml.etree.ElementTree.Element truth value by 'is not None' * In Python 3.14 testing the truth value of an xml.etree.ElementTree.Element is deprecated and will raise an exception. As of Python 3.12 this behavior will raise a DeprecationWarning: ``` DeprecationWarning: Testing an element's truth value will raise an exception in future versions. Use specific 'len(elem)' or 'elem is not None' test instead. ``` To avoid this, determine the truth element by using the 'elem is not None' method. --- src/pyhf/writexml.py | 2 +- tests/test_export.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pyhf/writexml.py b/src/pyhf/writexml.py index 8d3ecd3ca3..ff7aac800b 100644 --- a/src/pyhf/writexml.py +++ b/src/pyhf/writexml.py @@ -56,7 +56,7 @@ def _export_root_histogram(hist_name, data): # https://stackoverflow.com/a/4590052 def indent(elem, level=0): i = "\n" + level * " " - if elem: + if elem is not None: if not elem.text or not elem.text.strip(): elem.text = i + " " if not elem.tail or not elem.tail.strip(): diff --git a/tests/test_export.py b/tests/test_export.py index bba0aa224e..5c1ebed6e2 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -447,7 +447,7 @@ def test_integer_data(datadir, mocker): mocker.patch("pyhf.writexml._ROOT_DATA_FILE") channel = pyhf.writexml.build_channel(spec, channel_spec, {}) - assert channel + assert channel is not None @pytest.mark.parametrize(