From 16a3a3bcc8645627ef691e61e15a08d22854e22e Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Sat, 9 Dec 2023 09:21:10 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=94=20Fix=20tests=20on=20Python=203.8=20b?= =?UTF-8?q?y=20backporting=20removeprefix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qurator/mods4pandas/tests/test_page_info.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qurator/mods4pandas/tests/test_page_info.py b/qurator/mods4pandas/tests/test_page_info.py index 441230b..a740ffd 100644 --- a/qurator/mods4pandas/tests/test_page_info.py +++ b/qurator/mods4pandas/tests/test_page_info.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path from lxml import etree as ET @@ -8,6 +9,13 @@ from qurator.mods4pandas.mods4pandas import pages_to_dict TESTS_DATA_DIR = Path(__file__).parent / "data" +def removeprefix(s, prefix): + if sys.version_info < (3,9): + return s[len(prefix):] if s.startswith(prefix) else s + else: + return s.removeprefix(prefix) + + def test_page_info(): """Test creation of page_info""" mets = ET.parse(TESTS_DATA_DIR / "mets-mods" / "PPN821507109-1361-pages.xml") @@ -25,5 +33,5 @@ def test_page_info(): # This is a title page with an illustration, check that we correctly got this info from the # structMap. - struct_types = sorted(k.removeprefix("structMap-LOGICAL_TYPE_") for k, v in page_info_page.items() if k.startswith("structMap-LOGICAL_TYPE_") and v == 1) + struct_types = sorted(removeprefix(k, "structMap-LOGICAL_TYPE_") for k, v in page_info_page.items() if k.startswith("structMap-LOGICAL_TYPE_") and v == 1) assert struct_types == ["illustration", "monograph", "title_page"]