Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

Move test for get_all_text to test_parser_advanced.py

Matt Hillebrand7cbe566acdbc
diff --git a/tests/parser/test_general.py b/tests/parser/test_general.py
index 36241a6..26f6e6c 100644
--- a/tests/parser/test_general.py
+++ b/tests/parser/test_general.py
@@ -327,32 +327,6 @@ def test_getting_all_text(page):
assert page.get_all_text() != ""
-def test_getting_all_text_from_nested_content():
- """Test getting all text preserves interleaved text nodes"""
- html = """
- <html>
- <body>
- <main>
- string1
- <b>string2</b>
- string3
- <div>
- <span>string4</span>
- </div>
- string5
- <script>ignored</script>
- <style>ignored</style>
- </main>
- </body>
- </html>
- """
-
- page = Selector(html, adaptive=False)
- node = page.css("main")[0]
-
- assert node.get_all_text("\n", strip=True) == "string1\nstring2\nstring3\nstring4\nstring5"
-
-
def test_regex_on_text(page):
"""Test regex operations on text"""
element = page.css('[data-id="1"] .price')[0]
diff --git a/tests/parser/test_parser_advanced.py b/tests/parser/test_parser_advanced.py
index 57086ba..f34ba5c 100644
--- a/tests/parser/test_parser_advanced.py
+++ b/tests/parser/test_parser_advanced.py
@@ -183,6 +183,33 @@ class TestAdvancedSelectors:
text = page.get_all_text(valid_values=False)
assert text != ""
+ def test_get_all_text_preserves_interleaved_text_nodes(self):
+ """Test get_all_text preserves interleaved text nodes"""
+ html = """
+ <html>
+ <body>
+ <main>
+ string1
+ <b>string2</b>
+ string3
+ <div>
+ <span>string4</span>
+ </div>
+ string5
+ <script>ignored</script>
+ string6
+ <style>ignored</style>
+ string7
+ </main>
+ </body>
+ </html>
+ """
+
+ page = Selector(html, adaptive=False)
+ node = page.css("main")[0]
+
+ assert node.get_all_text("\n", strip=True) == "string1\nstring2\nstring3\nstring4\nstring5\nstring6\nstring7"
+
class TestTextHandlerAdvanced:
"""Test advanced TextHandler functionality"""