summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bs4/element.py20
-rw-r--r--bs4/tests/test_tree.py16
2 files changed, 13 insertions, 23 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 5cadfc9..75d5d9d 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -302,38 +302,38 @@ class PageElement(object):
#NavigableStrings and Tags.
@property
def next_elements(self):
- i = self
+ i = self.next_element
while i is not None:
- i = i.next_element
yield i
+ i = i.next_element
@property
def next_siblings(self):
- i = self
+ i = self.next_sibling
while i is not None:
- i = i.next_sibling
yield i
+ i = i.next_sibling
@property
def previous_elements(self):
- i = self
+ i = self.previous_element
while i is not None:
- i = i.previous_element
yield i
+ i = i.previous_element
@property
def previous_siblings(self):
- i = self
+ i = self.previous_sibling
while i is not None:
- i = i.previous_sibling
yield i
+ i = i.previous_sibling
@property
def parents(self):
- i = self
+ i = self.parent
while i is not None:
- i = i.parent
yield i
+ i = i.parent
# Old non-property versions of the generators, for backwards
# compatibility with BS3.
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index f14a746..60b9b91 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -357,15 +357,9 @@ class TestNextOperations(ProximityTest):
start = self.tree.find(text="Two")
successors = [node for node in start.next_elements]
# There are two successors: the final <b> tag and its text contents.
- # Then we go off the end.
- tag, contents, none = successors
+ tag, contents = successors
self.assertEqual(tag['id'], '3')
self.assertEqual(contents, "Three")
- self.assertEqual(none, None)
-
- # XXX Should next_elements really return None? Seems like it
- # should just stop.
-
class TestPreviousOperations(ProximityTest):
@@ -410,16 +404,12 @@ class TestPreviousOperations(ProximityTest):
predecessors = [node for node in start.previous_elements]
# There are four predecessors: the <b> tag containing "One"
- # the <body> tag, the <head> tag, and the <html> tag. Then we
- # go off the end.
- b, body, head, html, none = predecessors
+ # the <body> tag, the <head> tag, and the <html> tag.
+ b, body, head, html = predecessors
self.assertEqual(b['id'], '1')
self.assertEqual(body.name, "body")
self.assertEqual(head.name, "head")
self.assertEqual(html.name, "html")
- self.assertEqual(none, None)
-
- # Again, we shouldn't be returning None.
class SiblingTest(TreeTest):