Skip to content

Commit

Permalink
working on v.12 mypy (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanasco committed Jun 8, 2023
1 parent 4e9225a commit db6d6a4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 34 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* drop python 2.7
* initial typing support


0.11.0 | UNRELEASED

* BREAKING CHANGES
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 88
target-version = ['py38']
target-version = ['py36']
exclude = '''
(
/(
Expand Down
Empty file added src/metadata_parser/py.typed
Empty file.
2 changes: 0 additions & 2 deletions tests/_compat.py

This file was deleted.

16 changes: 8 additions & 8 deletions tests/test_document_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,17 @@ class TestEncoders(unittest.TestCase):

_data = {
"unicode_whitespace": {
"raw": u"""Example line with\xa0unicode whitespace.""",
"raw": """Example line with\xa0unicode whitespace.""",
"ascii": """Example line with unicode whitespace.""",
},
"unicode_chars": {
"raw": u"""Example line with\xc2\xa0unicode chars.""",
"raw": """Example line with\xc2\xa0unicode chars.""",
"ascii": """Example line withA unicode chars.""",
},
"decode_html_encoder": {
"html": u"""<html><head><meta name="description" content="Foo&amp;nbsp;Bar, &amp;quot;Biz Bang Bash.&amp;quot;"/></head></html>""",
"parsed": u"Foo&nbsp;Bar, &quot;Biz Bang Bash.&quot;",
"decoded": u'Foo Bar, "Biz Bang Bash."',
"html": """<html><head><meta name="description" content="Foo&amp;nbsp;Bar, &amp;quot;Biz Bang Bash.&amp;quot;"/></head></html>""",
"parsed": "Foo&nbsp;Bar, &quot;Biz Bang Bash.&quot;",
"decoded": 'Foo Bar, "Biz Bang Bash."',
},
}

Expand Down Expand Up @@ -685,7 +685,7 @@ def test_complex_html(self):
dc_subject = parsed.metadata["dc"]["Subject"]
self.assertIs(type(dc_subject), list)
self.assertEqual(len(dc_subject), len(dcSubjectsExpected))
for (idx, _expected) in enumerate(dc_subject):
for idx, _expected in enumerate(dc_subject):
self.assertIs(type(dc_subject[idx]), dict)
self.assertEqual(
len(dc_subject[idx].keys()), len(dcSubjectsExpected[idx].keys())
Expand Down Expand Up @@ -785,7 +785,7 @@ def test_complex_html(self):
dc_mixed_candidates = parsed.metadata["dc"]["TestMixedCandidates2a"]
self.assertIs(type(dc_mixed_candidates), list)
self.assertEqual(len(dc_mixed_candidates), len(dcTestMixedCandidates2aExpected))
for (idx, _expected) in enumerate(dc_mixed_candidates):
for idx, _expected in enumerate(dc_mixed_candidates):
self.assertIs(type(dc_mixed_candidates[idx]), dict)
self.assertEqual(
len(dc_mixed_candidates[idx].keys()),
Expand Down Expand Up @@ -831,7 +831,7 @@ def test_complex_html(self):
dc_mixed_candidates = parsed.metadata["dc"]["TestMixedCandidates2b"]
self.assertIs(type(dc_mixed_candidates), list)
self.assertEqual(len(dc_mixed_candidates), len(dcTestMixedCandidates2bExpected))
for (idx, _expected) in enumerate(dc_mixed_candidates):
for idx, _expected in enumerate(dc_mixed_candidates):
self.assertIs(type(dc_mixed_candidates[idx]), dict)
self.assertEqual(
len(dc_mixed_candidates[idx].keys()),
Expand Down
11 changes: 3 additions & 8 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# local
from metadata_parser import derive_encoding__hook
from ._compat import PY2

# ==============================================================================

Expand Down Expand Up @@ -49,9 +48,7 @@ def test_simple_encoding_found(self):
_content_type = "text/html"
if _header:
_content_type = "text/html; charset=%s" % _header
if PY2:
_body_char = _body_char.decode("utf-8")
_body = u"<html><head></head><body>%s</body></html>" % _body_char
_body = "<html><head></head><body>%s</body></html>" % _body_char
rsps.add(
responses.GET,
url,
Expand All @@ -64,12 +61,10 @@ def test_simple_encoding_found(self):
# set up the meta tests
for url in URLS_META.keys():
(_header, _expected, _body_char) = URLS_META[url]
if PY2:
_body_char = _body_char.decode("utf-8")
_body = u"<html><head></head><body>%s</body></html>" % _body_char
_body = "<html><head></head><body>%s</body></html>" % _body_char
if _header:
_body = (
u'<html><head><meta charset="%s"></head><body>%s</body></html>'
'<html><head><meta charset="%s"></head><body>%s</body></html>'
% (_header, _body_char)
)
rsps.add(
Expand Down
17 changes: 3 additions & 14 deletions tests/test_url_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

# stdlib
import unittest
from urllib.parse import urlparse

# local
import metadata_parser
from ._compat import PY2
from ._compat import urlparse

# ==============================================================================

Expand Down Expand Up @@ -391,14 +390,9 @@ def test_fix_unicode_path(self):
"https://example.com/2017/12/abcdefg%C3%BChijklmnop?a=%20foo",
),
)
for (raw, expected) in _test_pairs:
for raw, expected in _test_pairs:
cleaned = metadata_parser.fix_unicode_url(raw)
self.assertEqual(cleaned, expected)
if PY2:
cleaned = metadata_parser.fix_unicode_url(
raw.decode("utf-8"), encoding="utf-8"
).encode("utf-8")
self.assertEqual(cleaned, expected)

def test_fix_unicode_path_leave_unicode_kwargs(self):
_test_pairs = (
Expand All @@ -407,14 +401,9 @@ def test_fix_unicode_path_leave_unicode_kwargs(self):
"https://example.com/2017/12/abcdefg%C3%BChijklmnop?a=%20foo&b=ü",
),
)
for (raw, expected) in _test_pairs:
for raw, expected in _test_pairs:
cleaned = metadata_parser.fix_unicode_url(raw)
self.assertEqual(cleaned, expected)
if PY2:
cleaned = metadata_parser.fix_unicode_url(
raw.decode("utf-8"), encoding="utf-8"
).encode("utf-8")
self.assertEqual(cleaned, expected)


class TestArgsExceptions(unittest.TestCase, _DocumentCanonicalsMixin):
Expand Down

0 comments on commit db6d6a4

Please sign in to comment.