chore: migrating to ruff and updating pre-commit hooks
This commit is contained in:
@@ -8,7 +8,7 @@ from scrapling import Adaptor
|
||||
class TestParserAutoMatch:
|
||||
def test_element_relocation(self):
|
||||
"""Test relocating element after structure change"""
|
||||
original_html = '''
|
||||
original_html = """
|
||||
<div class="container">
|
||||
<section class="products">
|
||||
<article class="product" id="p1">
|
||||
@@ -21,8 +21,8 @@ class TestParserAutoMatch:
|
||||
</article>
|
||||
</section>
|
||||
</div>
|
||||
'''
|
||||
changed_html = '''
|
||||
"""
|
||||
changed_html = """
|
||||
<div class="new-container">
|
||||
<div class="product-wrapper">
|
||||
<section class="products">
|
||||
@@ -41,25 +41,25 @@ class TestParserAutoMatch:
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
'''
|
||||
"""
|
||||
|
||||
old_page = Adaptor(original_html, url='example.com', auto_match=True)
|
||||
new_page = Adaptor(changed_html, url='example.com', auto_match=True)
|
||||
old_page = Adaptor(original_html, url="example.com", auto_match=True)
|
||||
new_page = Adaptor(changed_html, url="example.com", auto_match=True)
|
||||
|
||||
# 'p1' was used as ID and now it's not and all the path elements have changes
|
||||
# Also at the same time testing auto-match vs combined selectors
|
||||
_ = old_page.css('#p1, #p2', auto_save=True)[0]
|
||||
relocated = new_page.css('#p1', auto_match=True)
|
||||
_ = old_page.css("#p1, #p2", auto_save=True)[0]
|
||||
relocated = new_page.css("#p1", auto_match=True)
|
||||
|
||||
assert relocated is not None
|
||||
assert relocated[0].attrib['data-id'] == 'p1'
|
||||
assert relocated[0].has_class('new-class')
|
||||
assert relocated[0].css('.new-description')[0].text == 'Description 1'
|
||||
assert relocated[0].attrib["data-id"] == "p1"
|
||||
assert relocated[0].has_class("new-class")
|
||||
assert relocated[0].css(".new-description")[0].text == "Description 1"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_element_relocation_async(self):
|
||||
"""Test relocating element after structure change in async mode"""
|
||||
original_html = '''
|
||||
original_html = """
|
||||
<div class="container">
|
||||
<section class="products">
|
||||
<article class="product" id="p1">
|
||||
@@ -72,8 +72,8 @@ class TestParserAutoMatch:
|
||||
</article>
|
||||
</section>
|
||||
</div>
|
||||
'''
|
||||
changed_html = '''
|
||||
"""
|
||||
changed_html = """
|
||||
<div class="new-container">
|
||||
<div class="product-wrapper">
|
||||
<section class="products">
|
||||
@@ -92,20 +92,20 @@ class TestParserAutoMatch:
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
'''
|
||||
"""
|
||||
|
||||
# Simulate async operation
|
||||
await asyncio.sleep(0.1) # Minimal async operation
|
||||
|
||||
old_page = Adaptor(original_html, url='example.com', auto_match=True)
|
||||
new_page = Adaptor(changed_html, url='example.com', auto_match=True)
|
||||
old_page = Adaptor(original_html, url="example.com", auto_match=True)
|
||||
new_page = Adaptor(changed_html, url="example.com", auto_match=True)
|
||||
|
||||
# 'p1' was used as ID and now it's not and all the path elements have changes
|
||||
# Also at the same time testing auto-match vs combined selectors
|
||||
_ = old_page.css('#p1, #p2', auto_save=True)[0]
|
||||
relocated = new_page.css('#p1', auto_match=True)
|
||||
_ = old_page.css("#p1, #p2", auto_save=True)[0]
|
||||
relocated = new_page.css("#p1", auto_match=True)
|
||||
|
||||
assert relocated is not None
|
||||
assert relocated[0].attrib['data-id'] == 'p1'
|
||||
assert relocated[0].has_class('new-class')
|
||||
assert relocated[0].css('.new-description')[0].text == 'Description 1'
|
||||
assert relocated[0].attrib["data-id"] == "p1"
|
||||
assert relocated[0].has_class("new-class")
|
||||
assert relocated[0].css(".new-description")[0].text == "Description 1"
|
||||
|
||||
Reference in New Issue
Block a user