|
10 | 10 | "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f " |
11 | 11 | ) |
12 | 12 | _VERTICAL_COLON = "\ufe13" # normalizes to ":" |
13 | | -_FULL_WITH_NUMBER_SIGN = "\uFF03" # normalizes to "#" |
| 13 | +_FULL_WITH_NUMBER_SIGN = "\uff03" # normalizes to "#" |
14 | 14 | _ACCOUNT_OF = "\u2100" # normalizes to "a/c" |
15 | 15 |
|
16 | 16 |
|
@@ -1240,6 +1240,47 @@ def test_with_path_fragment(): |
1240 | 1240 | assert str(url.with_path("/test")) == "http://example.com/test" |
1241 | 1241 |
|
1242 | 1242 |
|
| 1243 | +@pytest.mark.parametrize( |
| 1244 | + ("original_url", "keep_query", "keep_fragment", "expected_url"), |
| 1245 | + [ |
| 1246 | + pytest.param( |
| 1247 | + "http://example.com?a=b#frag", |
| 1248 | + True, |
| 1249 | + False, |
| 1250 | + "http://example.com/test?a=b", |
| 1251 | + id="query-only", |
| 1252 | + ), |
| 1253 | + pytest.param( |
| 1254 | + "http://example.com?a=b#frag", |
| 1255 | + False, |
| 1256 | + True, |
| 1257 | + "http://example.com/test#frag", |
| 1258 | + id="fragment-only", |
| 1259 | + ), |
| 1260 | + pytest.param( |
| 1261 | + "http://example.com?a=b#frag", |
| 1262 | + True, |
| 1263 | + True, |
| 1264 | + "http://example.com/test?a=b#frag", |
| 1265 | + id="all", |
| 1266 | + ), |
| 1267 | + pytest.param( |
| 1268 | + "http://example.com?a=b#frag", |
| 1269 | + False, |
| 1270 | + False, |
| 1271 | + "http://example.com/test", |
| 1272 | + id="none", |
| 1273 | + ), |
| 1274 | + ], |
| 1275 | +) |
| 1276 | +def test_with_path_keep_query_keep_fragment_flags( |
| 1277 | + original_url, keep_query, keep_fragment, expected_url |
| 1278 | +): |
| 1279 | + url = URL(original_url) |
| 1280 | + url2 = url.with_path("/test", keep_query=keep_query, keep_fragment=keep_fragment) |
| 1281 | + assert str(url2) == expected_url |
| 1282 | + |
| 1283 | + |
1243 | 1284 | def test_with_path_empty(): |
1244 | 1285 | url = URL("http://example.com/test") |
1245 | 1286 | assert str(url.with_path("")) == "http://example.com" |
@@ -1319,6 +1360,47 @@ def test_with_name(): |
1319 | 1360 | assert url2.path == "/a/c" |
1320 | 1361 |
|
1321 | 1362 |
|
| 1363 | +@pytest.mark.parametrize( |
| 1364 | + ("original_url", "keep_query", "keep_fragment", "expected_url"), |
| 1365 | + [ |
| 1366 | + pytest.param( |
| 1367 | + "http://example.com/path/to?a=b#frag", |
| 1368 | + True, |
| 1369 | + False, |
| 1370 | + "http://example.com/path/newname?a=b", |
| 1371 | + id="query-only", |
| 1372 | + ), |
| 1373 | + pytest.param( |
| 1374 | + "http://example.com/path/to?a=b#frag", |
| 1375 | + False, |
| 1376 | + True, |
| 1377 | + "http://example.com/path/newname#frag", |
| 1378 | + id="fragment-only", |
| 1379 | + ), |
| 1380 | + pytest.param( |
| 1381 | + "http://example.com/path/to?a=b#frag", |
| 1382 | + True, |
| 1383 | + True, |
| 1384 | + "http://example.com/path/newname?a=b#frag", |
| 1385 | + id="all", |
| 1386 | + ), |
| 1387 | + pytest.param( |
| 1388 | + "http://example.com/path/to?a=b#frag", |
| 1389 | + False, |
| 1390 | + False, |
| 1391 | + "http://example.com/path/newname", |
| 1392 | + id="none", |
| 1393 | + ), |
| 1394 | + ], |
| 1395 | +) |
| 1396 | +def test_with_name_keep_query_keep_fragment_flags( |
| 1397 | + original_url, keep_query, keep_fragment, expected_url |
| 1398 | +): |
| 1399 | + url = URL(original_url) |
| 1400 | + url2 = url.with_name("newname", keep_query=keep_query, keep_fragment=keep_fragment) |
| 1401 | + assert str(url2) == expected_url |
| 1402 | + |
| 1403 | + |
1322 | 1404 | def test_with_name_for_naked_path(): |
1323 | 1405 | url = URL("http://example.com") |
1324 | 1406 | url2 = url.with_name("a") |
@@ -1409,6 +1491,47 @@ def test_with_suffix(): |
1409 | 1491 | assert url2.path == "/a/b.c" |
1410 | 1492 |
|
1411 | 1493 |
|
| 1494 | +@pytest.mark.parametrize( |
| 1495 | + ("original_url", "keep_query", "keep_fragment", "expected_url"), |
| 1496 | + [ |
| 1497 | + pytest.param( |
| 1498 | + "http://example.com/path/to.txt?a=b#frag", |
| 1499 | + True, |
| 1500 | + False, |
| 1501 | + "http://example.com/path/to.md?a=b", |
| 1502 | + id="query-only", |
| 1503 | + ), |
| 1504 | + pytest.param( |
| 1505 | + "http://example.com/path/to.txt?a=b#frag", |
| 1506 | + False, |
| 1507 | + True, |
| 1508 | + "http://example.com/path/to.md#frag", |
| 1509 | + id="fragment-only", |
| 1510 | + ), |
| 1511 | + pytest.param( |
| 1512 | + "http://example.com/path/to.txt?a=b#frag", |
| 1513 | + True, |
| 1514 | + True, |
| 1515 | + "http://example.com/path/to.md?a=b#frag", |
| 1516 | + id="all", |
| 1517 | + ), |
| 1518 | + pytest.param( |
| 1519 | + "http://example.com/path/to.txt?a=b#frag", |
| 1520 | + False, |
| 1521 | + False, |
| 1522 | + "http://example.com/path/to.md", |
| 1523 | + id="none", |
| 1524 | + ), |
| 1525 | + ], |
| 1526 | +) |
| 1527 | +def test_with_suffix_keep_query_keep_fragment_flags( |
| 1528 | + original_url, keep_query, keep_fragment, expected_url |
| 1529 | +): |
| 1530 | + url = URL(original_url) |
| 1531 | + url2 = url.with_suffix(".md", keep_query=keep_query, keep_fragment=keep_fragment) |
| 1532 | + assert str(url2) == expected_url |
| 1533 | + |
| 1534 | + |
1412 | 1535 | def test_with_suffix_for_naked_path(): |
1413 | 1536 | url = URL("http://example.com") |
1414 | 1537 | with pytest.raises(ValueError) as excinfo: |
|
0 commit comments