test: adding new tests and updating existing ones
Code Coverage is now 92%
This commit is contained in:
@@ -221,7 +221,7 @@ class TestElementNavigation:
|
||||
"""Test parent and sibling navigation"""
|
||||
table = page.css(".product-list")[0]
|
||||
parent = table.parent
|
||||
assert parent.attrib["id"] == "products"
|
||||
assert parent["id"] == "products"
|
||||
|
||||
parent_siblings = parent.siblings
|
||||
assert len(parent_siblings) == 1
|
||||
@@ -267,7 +267,7 @@ class TestJSONAndAttributes:
|
||||
products = page.css(".product")
|
||||
product_ids = [product.attrib["data-id"] for product in products]
|
||||
assert product_ids == ["1", "2", "3"]
|
||||
assert "data-id" in products[0].attrib
|
||||
assert "data-id" in products[0]
|
||||
|
||||
# Review rating calculations
|
||||
reviews = page.css(".review")
|
||||
@@ -316,7 +316,9 @@ def test_selectors_generation(page):
|
||||
|
||||
def _traverse(element: Selector):
|
||||
assert isinstance(element.generate_css_selector, str)
|
||||
assert isinstance(element.generate_full_css_selector, str)
|
||||
assert isinstance(element.generate_xpath_selector, str)
|
||||
assert isinstance(element.generate_full_xpath_selector, str)
|
||||
for branch in element.children:
|
||||
_traverse(branch)
|
||||
|
||||
|
||||
@@ -1,8 +1,58 @@
|
||||
import re
|
||||
import pytest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from scrapling import Selector, Selectors
|
||||
from scrapling.core.custom_types import TextHandler, TextHandlers
|
||||
from scrapling.core.storage import SQLiteStorageSystem
|
||||
|
||||
|
||||
class TestSelectorAdvancedFeatures:
|
||||
"""Test advanced Selector features like adaptive matching"""
|
||||
|
||||
def test_adaptive_initialization_with_storage(self):
|
||||
"""Test adaptive initialization with custom storage"""
|
||||
html = "<html><body><p>Test</p></body></html>"
|
||||
|
||||
# Use the actual SQLiteStorageSystem for this test
|
||||
selector = Selector(
|
||||
content=html,
|
||||
adaptive=True,
|
||||
storage=SQLiteStorageSystem,
|
||||
storage_args={"storage_file": ":memory:", "url": "https://example.com"}
|
||||
)
|
||||
|
||||
assert selector._Selector__adaptive_enabled is True
|
||||
assert selector._storage is not None
|
||||
|
||||
def test_adaptive_initialization_with_default_storage_args(self):
|
||||
"""Test adaptive initialization with default storage args"""
|
||||
html = "<html><body><p>Test</p></body></html>"
|
||||
url = "https://example.com"
|
||||
|
||||
# Test that adaptive mode uses default storage when no explicit args provided
|
||||
selector = Selector(
|
||||
content=html,
|
||||
url=url,
|
||||
adaptive=True
|
||||
)
|
||||
|
||||
# Should create storage with default args
|
||||
assert selector._storage is not None
|
||||
|
||||
def test_adaptive_with_existing_storage(self):
|
||||
"""Test adaptive initialization with existing storage object"""
|
||||
html = "<html><body><p>Test</p></body></html>"
|
||||
|
||||
mock_storage = Mock()
|
||||
|
||||
selector = Selector(
|
||||
content=html,
|
||||
adaptive=True,
|
||||
_storage=mock_storage
|
||||
)
|
||||
|
||||
assert selector._storage is mock_storage
|
||||
|
||||
|
||||
class TestAdvancedSelectors:
|
||||
|
||||
Reference in New Issue
Block a user