예제 #1
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_clean_markers():
    text = TextHtml(u'купить пластиковые окна')
    mark_with_words([Sentence(u'купить пластиковые')], text)
    text.remove_markers()
    mark_with_words([Sentence(u'пластиковые окна')], text)
    counters = get_marked_words(text)
    assert len(counters) == 1
예제 #2
0
def test_asterisk_in_exact_word():
    words = map(Sentence, [u'игры [*] разработчика', u'игры'])
    text = TextHtml(u'игры находит, но не игры русского разработчика')
    mark_with_words(words, text)
    result, additional_words = find_words(words, text)
    assert additional_words == {}
    assert result[u'игры'] == 1
    assert result[u'игры [*] разработчика'] == 1
    html = u"""<span data-markers="d203f33bb6e9ec9d0238e29d4ccfc97e">игры </span>находит, но не <span data-markers="f350ba1c1103dc72275a99ccc134dc3f inactive-d203f33bb6e9ec9d0238e29d4ccfc97e target-d203f33bb6e9ec9d0238e29d4ccfc97e">игры </span><span data-markers="f350ba1c1103dc72275a99ccc134dc3f target-d203f33bb6e9ec9d0238e29d4ccfc97e">русского </span><span data-markers="f350ba1c1103dc72275a99ccc134dc3f target-d203f33bb6e9ec9d0238e29d4ccfc97e">разработчика</span>"""
    assert text.build_html() == html
예제 #3
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_html_creation():
    html = u'<p class="dialog"><span>Привет </span>Мир!</p>'
    text = TextHtml(html)
    assert len(text) == 1
    assert text.build_html() == html

    html = u"<span>Это обычный текст.Из двух</span> <span>предложений.</span>"
    text = TextHtml(html)
    assert len(text) == 2
    assert text.build_html() == html
예제 #4
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_build_html_with_ol_tags():
    html = u''''<ol>
    <li>
        <p style="text-indent: 20px;">
            <span lang="ru-RU">First item.</span>
        </p>
    </li>
    <li>
        <p style="text-indent: 20px;">
            <span lang="ru-RU">Second item.</span>
        </p>
    </li>
</ol>'''
    text = TextHtml(html)
    mark_with_words([], text)
    html = text.build_html()
    bs = BeautifulSoup(html)
    assert len(bs.select('ol > li')) == 2, "There is two item in ordered list"
예제 #5
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_build_with_markers():
    word = Sentence(u'пластиковые окна')
    text = TextHtml(u'<p>купить пластиковые окна в москве</p>')
    mark_with_words([word], text)
    html = u'<p>купить <span data-markers="inactive-e4ca1dc74c4a889f31a1e24bb690b5c7">пластиковые </span>'\
           u'<span data-markers="inactive-e4ca1dc74c4a889f31a1e24bb690b5c7">окна </span>в москве</p>'
    assert text.build_html() == html

    find_words([word], text)
    html = u'<p>купить <span data-markers="e4ca1dc74c4a889f31a1e24bb690b5c7">пластиковые </span>'\
           u'<span data-markers="e4ca1dc74c4a889f31a1e24bb690b5c7">окна </span>в москве</p>'
    assert text.build_html() == html
    # проверим что множественный билд разметки ничего не сломает(там видоизменяется структура)
    assert text.build_html() == html

    # при повторной проверке уже отмаркированного списка - старые маркировки очищаются
    text = TextHtml(html)
    mark_with_words([word], text)
    find_words([word], text)
    assert text.build_html() == html
예제 #6
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_build_with_ignored_tags():
    word = Sentence(u'пластиковые окна')
    html = u'<p><h2>купить пластиковые окна в москве</h2></p>'
    text = TextHtml(html, ignored_tags=[('h2', )])
    mark_with_words([word], text)
    assert text.build_html() == html
예제 #7
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_ignored_selectors():
    html = u'<span class="ice-del">Удалённое предложение. </span><span>А это нормальное затем, следующее предложение</span>'
    text = TextHtml(html, ignored_tags=[('span', {'class': 'ice-del'})])
    assert len(text) == 1
    assert text.build_html() == html
예제 #8
0
파일: test_text.py 프로젝트: KokocGroup/ta4
def test_simple_text_in_html_creation():
    html = u'Простое предложение. И * затем, следующее предложение'
    text = TextHtml(html)
    assert len(text) == 2
    assert text.build_html() == html