diff options
author | Leonard Richardson <leonardr@segfault.org> | 2023-02-02 09:29:17 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2023-02-02 09:29:17 -0500 |
commit | 7713145153f143ebe02657232e36b58ca29bef38 (patch) | |
tree | 8df7dbfd4162ea5b75206a74e56b97ce91141861 /bs4/tests/test_pageelement.py | |
parent | 1896698334a1b0a281f1c646a5a2017d25a68c9f (diff) |
Test implementation.
Diffstat (limited to 'bs4/tests/test_pageelement.py')
-rw-r--r-- | bs4/tests/test_pageelement.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bs4/tests/test_pageelement.py b/bs4/tests/test_pageelement.py index 6674dad..09b0dea 100644 --- a/bs4/tests/test_pageelement.py +++ b/bs4/tests/test_pageelement.py @@ -2,6 +2,7 @@ import copy import pickle import pytest +import types from bs4 import BeautifulSoup from bs4.element import ( @@ -638,6 +639,32 @@ class TestCSSSelectors(SoupTest): for element in soup.find_all(class_=['c1', 'c2']): assert element in selected + def test_closest(self): + inner = self.soup.find("div", id="inner") + closest = inner.css.closest("div[id=main]") + assert closest == self.soup.find("div", id="main") + + def test_match(self): + inner = self.soup.find("div", id="inner") + main = self.soup.find("div", id="main") + assert inner.css.match("div[id=main]") == False + assert main.css.match("div[id=main]") == True + + def test_iselect(self): + gen = self.soup.css.iselect("h2") + assert isinstance(gen, types.GeneratorType) + [header2, header3] = gen + assert header2['id'] == 'header2' + assert header3['id'] == 'header3' + + def test_filter(self): + inner = self.soup.find("div", id="inner") + results = inner.css.filter("h2") + assert len(inner.css.filter("h2")) == 2 + + [result] = inner.css.filter("h2[id=header3]") + assert result['id'] == 'header3' + class TestPersistence(SoupTest): "Testing features like pickle and deepcopy." |