From 8fa1d16d54b86a1501020a563c12608898969de0 Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Wed, 2 Nov 2022 22:09:28 +0100 Subject: [PATCH 1/3] Tries to fix docs buiild on RTD --- docs/conf.py | 2 +- docs/rtd-dependencies.txt | 6 +++--- pyproject.toml | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a07204dc..919b0648 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -276,7 +276,7 @@ def predicate(self, name, attr, meta): and meta.get("category") is None and is_really_public(name) # deprecation wrapper from 961b8b822ed9d8e33a4f9a63b71e64f30188cc67 - and not attr.__qualname__.startswith("_better") + and not getattr(attr, "__qualname__", "").startswith("_better") ) diff --git a/docs/rtd-dependencies.txt b/docs/rtd-dependencies.txt index e9cc7b0b..f31a2163 100644 --- a/docs/rtd-dependencies.txt +++ b/docs/rtd-dependencies.txt @@ -1,5 +1,5 @@ -autoclasstoc>=1.1.1 -requests -sphinx>=3 +autoclasstoc @ git+https://github.com/kalekundert/autoclasstoc.git@ba868daf4fecc72bd1a8957c565760d4c41eb71a +httpx +sphinx sphinxcontrib-fulltoc sphinx-readable-theme diff --git a/pyproject.toml b/pyproject.toml index 481fc3f5..1cdeb427 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,9 +107,10 @@ dependencies = ["cff-from-621"] skip-install = true [tool.hatch.envs.docs] -python = "3.10" # TODO drop when a successor of 1.5.2 is released, also mind .github/workflows/quality-checks.yml + # TODO drop when a successor of 1.5.2 is released, also mind .github/workflows/quality-checks.yml and docs/rtd-dependencies.txt +python = "3.10" dependencies = [ - # TODO switch to PyPI when this is fixed: + # TODO switch to PyPI when this is fixed: https://github.com/kalekundert/autoclasstoc/issues/33 "autoclasstoc @ git+https://github.com/kalekundert/autoclasstoc.git@ba868daf4fecc72bd1a8957c565760d4c41eb71a", "sphinxcontrib-fulltoc", "sphinx-readable-theme" From ab0a182e89c42dbf5be5950eb8ae87cefbef0161 Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Fri, 10 Mar 2023 10:12:00 +0100 Subject: [PATCH 2/3] docs: Update rtd-dependencies.txt --- docs/rtd-dependencies.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rtd-dependencies.txt b/docs/rtd-dependencies.txt index f31a2163..5c58325a 100644 --- a/docs/rtd-dependencies.txt +++ b/docs/rtd-dependencies.txt @@ -1,5 +1,5 @@ autoclasstoc @ git+https://github.com/kalekundert/autoclasstoc.git@ba868daf4fecc72bd1a8957c565760d4c41eb71a -httpx +httpx[http2] sphinx sphinxcontrib-fulltoc sphinx-readable-theme From b54e8fcd2f33723569cbc02eea32e134036ef999 Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Thu, 1 Jun 2023 23:13:01 +0200 Subject: [PATCH 3/3] Fixes translation of CSS selectors (cherry picked from commit 4997d62ccb6fd3a8d9ceb90cc0bb6851725202be) --- _delb/xpath/__init__.py | 2 +- tests/test_attributes.py | 2 +- tests/test_css_select.py | 10 +++++++++- tests/test_transform.py | 5 +++-- tests/test_xpath_results.py | 5 ----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/_delb/xpath/__init__.py b/_delb/xpath/__init__.py index efb1804d..b7cffbf3 100644 --- a/_delb/xpath/__init__.py +++ b/_delb/xpath/__init__.py @@ -167,7 +167,7 @@ def size(self) -> int: # TODO make cachesize configurable via environment variable? @lru_cache(maxsize=64) def _css_to_xpath(expression: str) -> str: - return _css_translator.css_to_xpath(expression, prefix="descendant-or-self::") + return _css_translator.css_to_xpath(expression, prefix="descendant::") def evaluate( diff --git a/tests/test_attributes.py b/tests/test_attributes.py index ab8b3beb..4fecc31d 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -63,7 +63,7 @@ def test_attribute_object(): def test_delete_namespaced_attribute(): root = Document('').root - node = root.css_select("root > node")[0] + node = root.css_select("node").first assert len(node.attributes) == 2 del node.attributes["ns":"a"] assert len(node.attributes) == 1 diff --git a/tests/test_css_select.py b/tests/test_css_select.py index 57e2f4c2..f4dfe5fc 100644 --- a/tests/test_css_select.py +++ b/tests/test_css_select.py @@ -1,4 +1,7 @@ +import pytest + from delb import Document +from _delb.xpath import _css_to_xpath def test_css_considers_xml_namespace(files_path): @@ -21,8 +24,13 @@ def test_css_select_or(files_path): assert {x.local_name for x in result} == {"author", "title"} +@pytest.mark.parametrize(("_in", "out"), (("metadata", "descendant::metadata"),)) +def test_css_to_xpath(_in, out): + assert _css_to_xpath(_in) == out + + def test_quotes_in_css_selector(): - document = Document('') + document = Document('') assert document.css_select('a[href^="https://super.test/"]').size == 1 assert document.css_select('a[href|="https://super.test/123"]').size == 1 assert document.css_select('a[href*="super"]').size == 1 diff --git a/tests/test_transform.py b/tests/test_transform.py index d3be0f99..b362fc9f 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -137,14 +137,15 @@ def test_transformation_sequence_sequence(): """, parser_options=ParserOptions(collapse_whitespace=True), ) - root = Document("
    ").root + root = Document("
      ").root transformation = TransformationSequence( DoNothing, TransformationSequence(ResolveItems, DoNothing()), TransformationSequence(ResolveItemList), ) assert str(transformation(root, document)) == ( - "
      • abla fahita
      • caro
      • boudi
      " + "
      • abla fahita
      • " + "
      • caro
      • boudi
      " ) with pytest.raises(TypeError): diff --git a/tests/test_xpath_results.py b/tests/test_xpath_results.py index 1935c01c..2206ca65 100644 --- a/tests/test_xpath_results.py +++ b/tests/test_xpath_results.py @@ -1,5 +1,3 @@ -import pytest - from delb import Document from tests.utils import assert_nodes_are_in_document_order @@ -38,9 +36,6 @@ def test_equality(): assert word_nodes == word_nodes.as_list() assert word_nodes == tuple(reversed(word_nodes.as_list())) assert word_nodes != 2 * word_nodes.as_list() - assert [document.root] == document.css_select("root") - with pytest.raises(TypeError): - document.css_select("root") == document.root def test_filtered_by(queries_sample):