|
1 | 1 | import pytest |
2 | 2 |
|
3 | | -from yarl.quoting import _PyQuoter, _PyUnquoter, _Quoter, _Unquoter |
| 3 | +from yarl._quoting import NO_EXTENSIONS |
4 | 4 |
|
| 5 | +from yarl._quoting_py import _Quoter as _PyQuoter, _Unquoter as _PyUnquoter |
5 | 6 |
|
6 | | -@pytest.fixture(params=[_PyQuoter, _Quoter], ids=["py_quoter", "c_quoter"]) |
7 | | -def quoter(request): |
8 | | - return request.param |
9 | 7 |
|
| 8 | +if not NO_EXTENSIONS: |
| 9 | + from yarl._quoting_c import _Quoter as _CQuoter, _Unquoter as _CUnquoter |
10 | 10 |
|
11 | | -@pytest.fixture(params=[_PyUnquoter, _Unquoter], ids=["py_unquoter", "c_unquoter"]) |
12 | | -def unquoter(request): |
13 | | - return request.param |
| 11 | + @pytest.fixture(params=[_PyQuoter, _CQuoter], ids=["py_quoter", "c_quoter"]) |
| 12 | + def quoter(request): |
| 13 | + return request.param |
| 14 | + |
| 15 | + @pytest.fixture(params=[_PyUnquoter, _CUnquoter], ids=["py_unquoter", "c_unquoter"]) |
| 16 | + def unquoter(request): |
| 17 | + return request.param |
| 18 | + |
| 19 | + |
| 20 | +else: |
| 21 | + |
| 22 | + @pytest.fixture(params=[_PyQuoter], ids=["py_quoter"]) |
| 23 | + def quoter(request): |
| 24 | + return request.param |
| 25 | + |
| 26 | + @pytest.fixture(params=[_PyUnquoter], ids=["py_unquoter"]) |
| 27 | + def unquoter(request): |
| 28 | + return request.param |
14 | 29 |
|
15 | 30 |
|
16 | 31 | def hexescape(char): |
@@ -336,15 +351,15 @@ def test_quote_protected(quoter): |
336 | 351 | assert s == "/path%2Fto/three" |
337 | 352 |
|
338 | 353 |
|
339 | | -def test_quote_fastpath_safe(): |
| 354 | +def test_quote_fastpath_safe(quoter): |
340 | 355 | s1 = "/path/to" |
341 | | - s2 = _Quoter(safe="/")(s1) |
| 356 | + s2 = quoter(safe="/")(s1) |
342 | 357 | assert s1 is s2 |
343 | 358 |
|
344 | 359 |
|
345 | | -def test_quote_fastpath_pct(): |
| 360 | +def test_quote_fastpath_pct(quoter): |
346 | 361 | s1 = "abc%A0" |
347 | | - s2 = _Quoter()(s1) |
| 362 | + s2 = quoter()(s1) |
348 | 363 | assert s1 is s2 |
349 | 364 |
|
350 | 365 |
|
|
0 commit comments