Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
 def test_orelse_returns_self(self):
     n = Node(3)
     assert n.orelse(5) is n
Exemplo n.º 4
0
 def setup_method(self, method):
     self.node = Node(BeautifulSoup('<b>hi</b>').b.contents[0])
Exemplo n.º 5
0
 def test_orelse_returns_self(self):
     n = Node(3)
     assert n.orelse(5) is n
Exemplo n.º 6
0
 def test_val(self):
     assert Node(3).val() == 3
Exemplo n.º 7
0
 def test_bool(self):
     assert bool(Node(3))
Exemplo n.º 8
0
 def setup_method(self, method):
     self.node = Node(BeautifulSoup('<b>hi</b>').b.contents[0])