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