1+ from __future__ import annotations
2+
13import os
24import sys
35import unittest
46from inspect import isclass
5- from typing import Callable , List , Optional , Tuple , Type , Union
7+ from typing import Callable
68from urllib .parse import urlparse
79
810import pytest
3537# input parameters.
3638#
3739# (encoding, input URL, output URL or exception)
38- SAFE_URL_ENCODING_CASES : List [
39- Tuple [Optional [str ], StrOrBytes , Union [str , Type [Exception ]]]
40- ] = [
40+ SAFE_URL_ENCODING_CASES : list [tuple [str | None , StrOrBytes , str | type [Exception ]]] = [
4141 (None , "" , ValueError ),
4242 (None , "https://example.com" , "https://example.com" ),
4343 (None , "https://example.com/©" , "https://example.com/%C2%A9" ),
319319def _test_safe_url_func (
320320 url : StrOrBytes ,
321321 * ,
322- encoding : Optional [ str ] = None ,
323- output : Union [ str , Type [Exception ] ],
322+ encoding : str | None = None ,
323+ output : str | type [Exception ],
324324 func : Callable [..., str ],
325325) -> None :
326326 kwargs = {}
@@ -338,8 +338,8 @@ def _test_safe_url_func(
338338def _test_safe_url_string (
339339 url : StrOrBytes ,
340340 * ,
341- encoding : Optional [ str ] = None ,
342- output : Union [ str , Type [Exception ] ],
341+ encoding : str | None = None ,
342+ output : str | type [Exception ],
343343) -> None :
344344 return _test_safe_url_func (
345345 url ,
@@ -373,7 +373,7 @@ def _test_safe_url_string(
373373 ),
374374)
375375def test_safe_url_string_encoding (
376- encoding : Optional [ str ] , url : StrOrBytes , output : Union [ str , Type [Exception ] ]
376+ encoding : str | None , url : StrOrBytes , output : str | type [Exception ]
377377) -> None :
378378 _test_safe_url_string (url , encoding = encoding , output = output )
379379
@@ -439,9 +439,7 @@ def test_safe_url_string_encoding(
439439 for case in SAFE_URL_URL_CASES
440440 ),
441441)
442- def test_safe_url_string_url (
443- url : StrOrBytes , output : Union [str , Type [Exception ]]
444- ) -> None :
442+ def test_safe_url_string_url (url : StrOrBytes , output : str | type [Exception ]) -> None :
445443 _test_safe_url_string (url , output = output )
446444
447445
@@ -858,6 +856,7 @@ def test_url_query_parameter(self):
858856 url_query_parameter ("product.html?id=" , "id" , keep_blank_values = 1 ), ""
859857 )
860858
859+ @pytest .mark .xfail
861860 def test_url_query_parameter_2 (self ):
862861 """
863862 This problem was seen several times in the feeds. Sometime affiliate URLs contains
@@ -873,14 +872,14 @@ def test_url_query_parameter_2(self):
873872 and the URL extraction will fail, current workaround was made in the spider,
874873 just a replace for ' to %27
875874 """
876- return # FIXME: this test should pass but currently doesnt
877875 # correct case
878876 aff_url1 = "http://www.anrdoezrs.net/click-2590032-10294381?url=http%3A%2F%2Fwww.argos.co.uk%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FArgosCreateReferral%3FstoreId%3D10001%26langId%3D-1%26referrer%3DCOJUN%26params%3Dadref%253DGarden+and+DIY-%3EGarden+furniture-%3EGarden+table+and+chair+sets%26referredURL%3Dhttp%3A%2F%2Fwww.argos.co.uk%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FProductDisplay%253FstoreId%253D10001%2526catalogId%253D1500001501%2526productId%253D1500357199%2526langId%253D-1"
879877 aff_url2 = url_query_parameter (aff_url1 , "url" )
880878 self .assertEqual (
881879 aff_url2 ,
882880 "http://www.argos.co.uk/webapp/wcs/stores/servlet/ArgosCreateReferral?storeId=10001&langId=-1&referrer=COJUN¶ms=adref%3DGarden and DIY->Garden furniture->Garden table and chair sets&referredURL=http://www.argos.co.uk/webapp/wcs/stores/servlet/ProductDisplay%3FstoreId%3D10001%26catalogId%3D1500001501%26productId%3D1500357199%26langId%3D-1" ,
883881 )
882+ assert aff_url2 is not None
884883 prod_url = url_query_parameter (aff_url2 , "referredURL" )
885884 self .assertEqual (
886885 prod_url ,
@@ -893,6 +892,7 @@ def test_url_query_parameter_2(self):
893892 aff_url2 ,
894893 "http://www.argos.co.uk/webapp/wcs/stores/servlet/ArgosCreateReferral?storeId=10001&langId=-1&referrer=COJUN¶ms=adref%3DGarden and DIY->Garden furniture->Children's garden furniture&referredURL=http://www.argos.co.uk/webapp/wcs/stores/servlet/ProductDisplay%3FstoreId%3D10001%26catalogId%3D1500001501%26productId%3D1500357023%26langId%3D-1" ,
895894 )
895+ assert aff_url2 is not None
896896 prod_url = url_query_parameter (aff_url2 , "referredURL" )
897897 # fails, prod_url is None now
898898 self .assertEqual (
@@ -1574,7 +1574,7 @@ def test_mediatype_parameters(self):
15741574 self .assertEqual (result .data , b"\xce \x8e \xce \xa3 \xce \x8e " )
15751575
15761576 def test_base64 (self ):
1577- result = parse_data_uri ("data:text/plain;base64," " SGVsbG8sIHdvcmxkLg%3D%3D" )
1577+ result = parse_data_uri ("data:text/plain;base64,SGVsbG8sIHdvcmxkLg%3D%3D" )
15781578 self .assertEqual (result .media_type , "text/plain" )
15791579 self .assertEqual (result .data , b"Hello, world." )
15801580
@@ -1587,7 +1587,7 @@ def test_base64_spaces(self):
15871587 self .assertEqual (result .data , b"Hello, world." )
15881588
15891589 result = parse_data_uri (
1590- "data:text/plain;base64,SGVsb G8sIH\n " " dvcm xk Lg%3D\n %3D"
1590+ "data:text/plain;base64,SGVsb G8sIH\n dvcm xk Lg%3D\n %3D"
15911591 )
15921592 self .assertEqual (result .media_type , "text/plain" )
15931593 self .assertEqual (result .data , b"Hello, world." )
0 commit comments