summaryrefslogtreecommitdiff
path: root/bs4/tests/test_pageelement.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/tests/test_pageelement.py')
-rw-r--r--bs4/tests/test_pageelement.py27
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."