8000 Remove test utils by tushuhei · Pull Request #130 · google/budoux · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove test utils #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions budoux/html_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def handle_starttag(self, tag: str, attrs: HTMLAttr) -> None:
attr_pairs = []
for attr in attrs:
if attr[1] is None:
attr_pairs.append(attr[0])
attr_pairs.append(' ' + attr[0])
else:
attr_pairs.append('%s="%s"' % (attr[0], attr[1]))
encoded_attrs = ' '.join(attr_pairs)
self.output += '<%s %s>' % (tag, encoded_attrs)
attr_pairs.append(' %s="%s"' % (attr[0], attr[1]))
encoded_attrs = ''.join(attr_pairs)
self.output += '<%s%s>' % (tag, encoded_attrs)
self.to_skip = tag.upper() in SKIP_NODES

def handle_endtag(self, tag: str) -> None:
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
8000
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ test_suite = tests
dev =
build
flake8
html5lib
isort
numpy
mypy==0.971
pytest
toml
twine
types-html5lib
types-setuptools
yapf

Expand Down
15 changes: 6 additions & 9 deletions tests/test_html_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import sys
import unittest

from utils import compare_html_string

# module hack
LIB_PATH = os.path.join(os.path.dirname(__file__), '..')
sys.path.insert(0, os.path.abspath(LIB_PATH))
Expand All @@ -45,9 +43,8 @@ def test_output(self) -> None:
expected = '<p>ab<b>c<wbr>de</b>f</p>'
resolver = html_processor.HTMLChunkResolver(['abc', 'def'])
resolver.feed(input)
self.assertTrue(
compare_html_string(resolver.output, expected),
'WBR tags should be inserted as specified by chunks.')
self.assertEqual(resolver.output, expected,
'WBR tags should be inserted as specified by chunks.')


class TestResolve(unittest.TestCase):
Expand All @@ -57,25 +54,25 @@ def test_with_simple_text_input(self) -> None:
html = 'abcdef'
result = html_processor.resolve(chunks, html)
expected = '<span style="word-break: keep-all; overflow-wrap: break-word;">abc<wbr>def</span>'
self.assertTrue(compare_html_string(result, expected))
self.assertEqual(result, expected)

def test_with_standard_html_input(self) -> None:
chunks = ['abc', 'def']
html = 'ab<a href="http://example.com">cd</a>ef'
result = html_processor.resolve(chunks, html)
expected = '<span style="word-break: keep-all; overflow-wrap: break-word;">ab<a href="http://example.com">c<wbr>d</a>ef</span>'
self.assertTrue(compare_html_string(result, expected))
self.assertEqual(result, expected)

def test_with_nodes_to_skip(self) -> None:
chunks = ['abc', 'def']
html = "a<button>bcde</button>f"
result = html_processor.resolve(chunks, html)
expected = '<span style="word-break: keep-all; overflow-wrap: break-word;">a<button>bcde</button>f</span>'
self.assertTrue(compare_html_string(result, expected))
self.assertEqual(result, expected)

def test_with_nothing_to_split(self) -> None:
chunks = ['abcdef']
html = 'abcdef'
result = html_processor.resolve(chunks, html)
expected = '<span style="word-break: keep-all; overflow-wrap: break-word;">abcdef</span>'
self.assertTrue(compare_html_string(result, expected))
self.assertEqual(result, expected)
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_cmdargs_single_html(self) -> None:
self.assertEqual(
output,
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'今日は<b ><wbr>とても<wbr>天気</b>です。</span>')
'今日は<b><wbr>とても<wbr>天気</b>です。</span>')

def test_cmdargs_multi_html(self) -> None:
cmdargs = ['-H', '今日は<b>とても天気</b>です。', 'これは<b>テスト</b>です。']
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_cmdargs_html_stdin(self) -> None:
self.assertEqual(
output,
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'これは<b ><wbr>テスト</b>です。<wbr>\n'
'これは<b><wbr>テスト</b>です。<wbr>\n'
'</span>')


Expand Down
25 changes: 9 additions & 16 deletions tests/test_parser.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import sys
import unittest

from utils import compare_html_string

# module hack
LIB_PATH = os.path.join(os.path.dirname(__file__), '..')
sys.path.insert(0, os.path.abspath(LIB_PATH))
Expand Down Expand Up @@ -66,8 +64,8 @@ def test_translate_html_string(self) -> None:
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'xyz<wbr>abcd</span>')
output_html = p.translate_html_string(input_html)
self.assertTrue(
compare_html_string(output_html, expected_html),
self.assertEqual(
output_html, expected_html,
'Should output a html string with a SPAN parent with proper style attributes.'
)

Expand All @@ -76,36 +74,31 @@ def test_translate_html_string(self) -> None:
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'xyz<script>alert(1);</script>xyz<wbr>abc</span>')
output_html = p.translate_html_string(input_html)
self.assertTrue(
compare_html_string(output_html, expected_html),
'Should pass script tags as is.')
self.assertEqual(output_html, expected_html,
'Should pass script tags as is.')

input_html = 'xyz<code>abc</code>abc'
expected_html = (
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'xyz<code>abc</code><wbr>abc</span>')
output_html = p.translate_html_string(input_html)
self.assertTrue(
compare_html_string(output_html, expected_html),
'Should skip some specific tags.')
self.assertEqual(output_html, expected_html,
'Should skip some specific tags.')

input_html = 'xyza<a href="#" hidden>bc</a>abc'
expected_html = (
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'xyz<wbr>a<a href="#" hidden>bc</a><wbr>abc</span>')
output_html = p.translate_html_string(input_html)
self.assertTrue(
compare_html_string(output_html, expected_html),
'Should not ruin attributes of child elements.')
self.assertEqual(output_html, expected_html,
'Should not ruin attributes of child elements.')

input_html = 'xyza🇯🇵🇵🇹abc'
expected_html = (
'<span style="word-break: keep-all; overflow-wrap: break-word;">'
'xyz<wbr>a🇯🇵🇵🇹<wbr>abc</span>')
output_html = p.translate_html_string(input_html)
self.assertTrue(
compare_html_string(output_html, expected_html),
'Should work with emojis.')
self.assertEqual(output_html, expected_html, 'Should work with emojis.')


class TestDefaultParser(unittest.TestCase):
Expand Down
26 changes: 0 additions & 26 deletions tests/utils.py

This file was deleted.

0