class TestNavigableString(object): """ NavigableStringS do not support all the methods of TagS in BeautifulSoup. Test that we handle them gracefully """ def setup_method(self, method): self.node = Node(BeautifulSoup('<b>hi</b>').b.contents[0]) def test_attrs(self): assert self.node.attrs.val() == {} def test_text(self): assert self.node.text.val() == 'hi' def test_name(self): assert self.node.name.val() == '' @pytest.mark.parametrize('attr', ('children', 'contents', 'descendants')) def test_multi_props(self, attr): assert len(getattr(self.node, attr)) == 0 @pytest.mark.parametrize('attr', ('find',)) def test_single_find(self, attr): assert isinstance(getattr(self.node, attr)('a'), NullNode) @pytest.mark.parametrize('attr', ('find_all', 'select')) def test_multi_find(self, attr): assert len(getattr(self.node, attr)('a')) == 0 def test_prettify(self): assert self.node.prettify() == self.node.val()
class TestNavigableString(object): """ NavigableStringS do not support all the methods of TagS in BeautifulSoup. Test that we handle them gracefully """ def setup_method(self, method): self.node = Node(BeautifulSoup('<b>hi</b>').b.contents[0]) def test_attrs(self): assert self.node.attrs.val() == {} def test_text(self): assert self.node.text.val() == 'hi' def test_name(self): assert self.node.name.val() == '' @pytest.mark.parametrize('attr', ('children', 'contents', 'descendants')) def test_multi_props(self, attr): assert len(getattr(self.node, attr)) == 0 @pytest.mark.parametrize('attr', ('find', )) def test_single_find(self, attr): assert isinstance(getattr(self.node, attr)('a'), NullNode) @pytest.mark.parametrize('attr', ('find_all', 'select')) def test_multi_find(self, attr): assert len(getattr(self.node, attr)('a')) == 0 def test_prettify(self): assert self.node.prettify() == self.node.val()
def test_orelse_returns_self(self): n = Node(3) assert n.orelse(5) is n
def setup_method(self, method): self.node = Node(BeautifulSoup('<b>hi</b>').b.contents[0])
def test_val(self): assert Node(3).val() == 3
def test_bool(self): assert bool(Node(3))