source: uri/tests/test_iri.py@ 1357

Last change on this file since 1357 was 230, checked in by wouter, 3 years ago

#91 clone https://pypi.org/project/rfc3986/

File size: 2.2 KB
RevLine 
[230]1# coding: utf-8
2
3import pytest
4import rfc3986
5import sys
6from rfc3986.exceptions import InvalidAuthority
7
8try:
9 import idna
10except ImportError:
11 idna = None
12
13
14requires_idna = pytest.mark.skipif(
15 idna is None, reason="This test requires the 'idna' module"
16)
17iri_to_uri = pytest.mark.parametrize(
18 ["iri", "uri"],
19 [
20 (u"http://Bücher.de", u"http://xn--bcher-kva.de"),
21 (u"http://faß.de", u"http://xn--fa-hia.de"),
22 (
23 u"http://βόλος.com/β/ό?λ#ος",
24 u"http://xn--nxasmm1c.com/%CE%B2/%CF%8C?%CE%BB#%CE%BF%CF%82",
25 ),
26 (u"http://ශ්\u200dරී.com", u"http://xn--10cl1a0b660p.com"),
27 (u"http://نامه\u200cای.com", u"http://xn--mgba3gch31f060k.com"),
28 (u"http://Bü:ẞ@gOoGle.com", u"http://B%C3%BC:%E1%BA%9E@gOoGle.com"),
29 (u"http://ẞ.com:443", u"http://xn--zca.com:443"),
30 (u"http://ẞ.foo.com", u"http://xn--zca.foo.com"),
31 (u"http://Bẞ.com", u"http://xn--b-qfa.com"),
32 (
33 u"http+unix://%2Ftmp%2FTEST.sock/get",
34 "http+unix://%2Ftmp%2FTEST.sock/get",
35 ),
36 ],
37)
38
39
40@requires_idna
41@iri_to_uri
42def test_encode_iri(iri, uri):
43 assert rfc3986.iri_reference(iri).encode().unsplit() == uri
44
45
46@iri_to_uri
47def test_iri_equality(iri, uri):
48 assert rfc3986.iri_reference(iri) == iri
49
50
51def test_iri_equality_special_cases():
52 assert rfc3986.iri_reference(u"http://Bü:ẞ@βόλος.com/β/ό?λ#ος") == (
53 u"http",
54 u"Bü:ẞ@βόλος.com",
55 u"/%CE%B2/%CF%8C",
56 u"%CE%BB",
57 u"%CE%BF%CF%82",
58 )
59
60 with pytest.raises(TypeError):
61 rfc3986.iri_reference(u"http://ẞ.com") == 1
62
63
64@requires_idna
65@pytest.mark.parametrize(
66 "iri",
67 [
68 u"http://♥.net",
69 u"http://\u0378.net",
70 pytest.param(
71 u"http://㛼.com",
72 marks=pytest.mark.skipif(
73 sys.version_info < (3, 3) and sys.maxunicode <= 0xFFFF,
74 reason="Python configured without UCS-4 support",
75 ),
76 ),
77 ],
78)
79def test_encode_invalid_iri(iri):
80 iri_ref = rfc3986.iri_reference(iri)
81 with pytest.raises(InvalidAuthority):
82 iri_ref.encode()
Note: See TracBrowser for help on using the repository browser.