def test_convert_search_result():
    """Test that we can convert a find_all search result."""
    soup = BeautifulSoup(html_doc, 'html.parser').find_all('a')
    dict_result = convert(soup)

    assert 'a' in dict_result
    assert len(dict_result['a']) == 3
def test_conversion():
    """Create soup and convert it to dict."""
    soup = BeautifulSoup(html_doc, 'html.parser')

    dict_result = convert(soup)
    assert isinstance(dict_result, dict)
    assert len(dict_result)
def test_sub_elements_allways_array():
    """Create soup and check elements are arrays."""
    soup = BeautifulSoup(html_doc, 'html.parser')

    dict_result = convert(soup)

    assert len(dict_result['main']) == 2
    assert len(dict_result['main'][1]['sub']) == 3
def test_attributes_are_at_prepended():
    """Test that attributes are picked up and prepended with @."""
    html_doc = """
    <main class="bob arne" abc="test" style="color: red;" />
    """
    soup = BeautifulSoup(html_doc, 'html.parser')
    main_element = convert(soup)['main'][0]
    assert main_element['@class'] == ['bob', 'arne']
    assert main_element['@abc'] == 'test'
    assert main_element['@style'] == 'color: red;'
예제 #5
0
def test_tag_name_are_arrays():
    """Create soup and check elements are arrays."""
    html_doc = """
    <main>
        <!-- Html comment -->
    </main>
    """
    soup = BeautifulSoup(html_doc, 'html.parser')
    dict_result = convert(soup)
    assert dict_result['main'][0]['comment'] == ['Html comment']
예제 #6
0
def test_cdata_stringified():
    """Create soup and check elements are arrays."""
    html_doc = """
    <main>
        <![CDATA[A CDATA block]]>
    </main>
    """
    soup = BeautifulSoup(html_doc, 'html.parser')
    main = convert(soup)['main'][0]
    assert main['cdata'] == ['A CDATA block']
예제 #7
0
def test_template_contains_templatestring():
    """Template element contains templatestring array."""
    html_doc = """
    <main>
        <template>test</template>
    </main>
    """
    soup = BeautifulSoup(html_doc, 'html.parser')
    main = convert(soup)['main'][0]
    assert main['template'][0]['templatestring'] == ['test']
예제 #8
0
def test_direct_descendants_text_are_caught():
    """Create soup and check elements are arrays."""
    html_doc = """
    <main>
        Hello
        <b>can you hear me</b>
        <div><div>test</div></div>
        Hello
    </main>
    """
    soup = BeautifulSoup(html_doc, 'html.parser')
    main = convert(soup)['main'][0]

    assert main['#text'] == 'Hello can you hear me test Hello'
    assert main['b'][0]['#text'] == 'can you hear me'