Skip to content

Commit

Permalink
repr(ElementList()) should return repr() of the internal container (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler authored Jun 10, 2022
1 parent 6f3029c commit 3ba4be7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 11 additions & 6 deletions splinter/element_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@


class ElementList:
"""
List of elements. Each member of the list is (usually) an instance
"""Collection of elements.
Each member of the collection is by default an instance
of :class:`ElementAPI <splinter.driver.ElementAPI>`.
Beyond the traditional list methods, the ``ElementList`` provides some
Beyond the traditional list methods, ``ElementList`` provides some
other methods, listed below.
There is a peculiar behavior on ElementList: you never get an
``IndexError``. Instead, you can an :class:`ElementDoesNotExist
``IndexError``. Instead, you get an :class:`ElementDoesNotExist
<splinter.exceptions.ElementDoesNotExist>` exception when trying to
access an inexistent item in the list:
access a non-existent item:
>>> element_list = ElementList([])
>>> element_list[0] # raises ElementDoesNotExist
Expand Down Expand Up @@ -64,7 +65,7 @@ def last(self):
"""
return self[-1]

def is_empty(self):
def is_empty(self) -> bool:
"""Check if the ElementList is empty.
Returns:
Expand Down Expand Up @@ -92,3 +93,7 @@ def __iter__(self):
def __len__(self):
"""__len__ checks the internal container."""
return len(self._container)

def __repr__(self):
"""Return the repr of the internal container."""
return repr(self._container)
9 changes: 9 additions & 0 deletions tests/test_element_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,12 @@ def test_not_found_exception_with_query_and_method():

expected_message = 'no elements could be found with id "menu"'
assert expected_message == str(e.value)


def test_elementlist_repr():
"""repr() of ElementList is identical to repr() of the internal container.
"""
the_list = [Person(), Person()]
elementlist = ElementList(the_list)

assert repr(elementlist) == repr(the_list)

0 comments on commit 3ba4be7

Please sign in to comment.