__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
"""Tests of classes in element.py.

The really big classes -- Tag, PageElement, and NavigableString --
are tested in separate files.
"""

import pytest
from bs4.element import (
    HTMLAttributeDict,
    XMLAttributeDict,
    CharsetMetaAttributeValue,
    ContentMetaAttributeValue,
    NamespacedAttribute,
    ResultSet,
)

class TestNamedspacedAttribute:
    def test_name_may_be_none_or_missing(self):
        a = NamespacedAttribute("xmlns", None)
        assert a == "xmlns"

        a = NamespacedAttribute("xmlns", "")
        assert a == "xmlns"

        a = NamespacedAttribute("xmlns")
        assert a == "xmlns"

    def test_namespace_may_be_none_or_missing(self):
        a = NamespacedAttribute(None, "tag")
        assert a == "tag"

        a = NamespacedAttribute("", "tag")
        assert a == "tag"

    def test_attribute_is_equivalent_to_colon_separated_string(self):
        a = NamespacedAttribute("a", "b")
        assert "a:b" == a

    def test_attributes_are_equivalent_if_prefix_and_name_identical(self):
        a = NamespacedAttribute("a", "b", "c")
        b = NamespacedAttribute("a", "b", "c")
        assert a == b

        # The actual namespace is not considered.
        c = NamespacedAttribute("a", "b", None)
        assert a == c

        # But name and prefix are important.
        d = NamespacedAttribute("a", "z", "c")
        assert a != d

        e = NamespacedAttribute("z", "b", "c")
        assert a != e


class TestAttributeValueWithCharsetSubstitution:
    """Certain attributes are designed to have the charset of the
    final document substituted into their value.
    """

    def test_charset_meta_attribute_value(self):
        # The value of a CharsetMetaAttributeValue is whatever
        # encoding the string is in.
        value = CharsetMetaAttributeValue("euc-jp")
        assert "euc-jp" == value
        assert "euc-jp" == value.original_value
        assert "utf8" == value.substitute_encoding("utf8")
        assert "ascii" == value.substitute_encoding("ascii")

        # If the target encoding is a Python internal encoding,
        # no encoding will be mentioned in the output HTML.
        assert "" == value.substitute_encoding("palmos")

    def test_content_meta_attribute_value(self):
        value = ContentMetaAttributeValue("text/html; charset=euc-jp")
        assert "text/html; charset=euc-jp" == value
        assert "text/html; charset=euc-jp" == value.original_value
        assert "text/html; charset=utf8" == value.substitute_encoding("utf8")
        assert "text/html; charset=ascii" == value.substitute_encoding("ascii")

        # If the target encoding is a Python internal encoding, the
        # charset argument will be omitted altogether.
        assert "text/html" == value.substitute_encoding("palmos")


class TestAttributeDicts:
    def test_xml_attribute_value_handling(self):
        # Verify that attribute values are processed according to the
        # XML spec's rules.
        d = XMLAttributeDict()
        d["v"] = 100
        assert d["v"] == "100"
        d["v"] = 100.123
        assert d["v"] == "100.123"

        # This preserves Beautiful Soup's old behavior in the absence of
        # guidance from the spec.
        d["v"] = False
        assert d["v"] is False

        d["v"] = True
        assert d["v"] is True

        d["v"] = None
        assert d["v"] == ""

    def test_html_attribute_value_handling(self):
        # Verify that attribute values are processed according to the
        # HTML spec's rules.
        d = HTMLAttributeDict()
        d["v"] = 100
        assert d["v"] == "100"
        d["v"] = 100.123
        assert d["v"] == "100.123"

        d["v"] = False
        assert "v" not in d

        d["v"] = None
        assert "v" not in d

        d["v"] = True
        assert d["v"] == "v"

        attribute = NamespacedAttribute("prefix", "name", "namespace")
        d[attribute] = True
        assert d[attribute] == "name"


class TestResultSet:
    def test_getattr_exception(self):
        rs = ResultSet(None)
        with pytest.raises(AttributeError) as e:
            rs.name
        assert (
            """ResultSet object has no attribute "name". You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?"""
            == str(e.value)
        )

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
fuzz Folder 0755
__init__.py File 51.04 KB 0644
test_builder.py File 1.07 KB 0644
test_builder_registry.py File 4.95 KB 0644
test_css.py File 18.19 KB 0644
test_dammit.py File 17.42 KB 0644
test_element.py File 4.27 KB 0644
test_filter.py File 26.4 KB 0644
test_formatter.py File 6.78 KB 0644
test_fuzz.py File 6.96 KB 0644
test_html5lib.py File 8.99 KB 0644
test_htmlparser.py File 6.51 KB 0644
test_lxml.py File 7.28 KB 0644
test_navigablestring.py File 4.98 KB 0644
test_pageelement.py File 15.82 KB 0644
test_soup.py File 22.14 KB 0644
test_tag.py File 9.46 KB 0644
test_tree.py File 53.55 KB 0644
Filemanager