@@ -142,6 +142,16 @@ def test_urlnetloc_normalize(netlocs):
142142 assert str (netloc ) == result
143143
144144
145+ def test_urlnetloc_normalize_patch (mocker ):
146+
147+ url = "www.ExamplE.com:443"
148+
149+ mocker .patch ("re.search" , return_value = None )
150+ netloc = UrlNetloc .from_netloc (url , normalize = False )
151+
152+ assert url != str (netloc )
153+
154+
145155def test_urlnetloc_str ():
146156 hostname = "www.example.com"
147157
@@ -267,22 +277,45 @@ def test_url_from():
267277 assert str (url ) == "https://www.server.com/path/readme.pdf"
268278
269279
270- def test_anchor ():
271- url = UrlPath ("//server/root/path/readme.pdf" )
280+ def test_url_from_exist (mocker , mock_openurl ):
272281
273- assert url . anchor == "//server/root"
282+ file = "//server/root/path/readme.pdf "
274283
284+ mocker .patch (
285+ "pathlib.Path.resolve" ,
286+ return_value = pathlib .Path (file ),
287+ )
288+ if mock_openurl == 404 :
289+ with pytest .raises (FileNotFoundError ):
290+ _ = url_from (file , "https://www.server.com" , strict = True )
291+ else :
292+ url = url_from (file , "https://www.server.com" , strict = True )
293+ assert str (url ) == "https://www.server.com/path/readme.pdf"
275294
276- def test_with_anchor ():
277- url = UrlPath ("//server/root/path/readme.pdf" )
278295
279- assert (
280- url .with_anchor ("//fubar" , root = True ).__str__ ()
281- == "//fubar/root/path/readme.pdf"
282- )
296+ @pytest .mark .parametrize (
297+ "url,result" ,
298+ [
299+ ("//server/root/path/readme.pdf" , "//server/root" ),
300+ ("//server/root/" , "//server/root" ),
301+ ("//server/" , "//server/" ),
302+ ],
303+ )
304+ def test_anchor (url , result ):
305+
306+ assert UrlPath (url ).anchor == result
283307
284308
285- def test_fubar_anchor ():
286- url = UrlPath ("//server/root/path/readme.pdf" )
309+ @pytest .mark .parametrize (
310+ "anchor,root,result" ,
311+ [
312+ ("//fubar" , False , "//fubar/path/readme.pdf" ),
313+ ("//fubar" , True , "//fubar/root/path/readme.pdf" ),
314+ ("//fubar/share" , False , "//fubar/share/path/readme.pdf" ),
315+ ("//fubar/share" , True , "//fubar/share/root/path/readme.pdf" ),
316+ ],
317+ )
318+ def test_with_anchor (anchor , root , result ):
319+ url = UrlPath ("//server/root/path/readme.pdf" ).with_anchor (anchor , root )
287320
288- assert url . with_anchor ( "//fubar" ). __str__ () == "//fubar/path/readme.pdf"
321+ assert str ( url ) == result
0 commit comments