|
1 | 1 | from mxdev.config import Configuration |
2 | 2 | from mxdev.state import State |
| 3 | +from mxdev.uv import _constraints_to_uv |
3 | 4 | from mxdev.uv import UvPyprojectUpdater |
4 | 5 |
|
5 | 6 | import pytest |
@@ -459,3 +460,30 @@ def fake_import(name, *args, **kw): |
459 | 460 |
|
460 | 461 | # Should not raise any error, even though tomlkit import is mocked to fail |
461 | 462 | hook.write(state) |
| 463 | + |
| 464 | + |
| 465 | +def test_constraints_to_uv_filters_and_preserves_order(): |
| 466 | + constraints = [ |
| 467 | + "#" * 79 + "\n", |
| 468 | + "# begin constraints from: https://example.com/a.txt\n", |
| 469 | + "\n", |
| 470 | + "Zope==6.0\n", |
| 471 | + "# AccessControl==7.3 -> mxdev disabled (source)\n", |
| 472 | + 'backports.tarfile==1.2.0 ; python_version < "3.12"\n', |
| 473 | + "--hash=sha256:deadbeef\n", |
| 474 | + "# end constraints from: https://example.com/a.txt\n", |
| 475 | + "#" * 79 + "\n", |
| 476 | + ] |
| 477 | + result = _constraints_to_uv(constraints) |
| 478 | + assert result == [ |
| 479 | + ("comment", "begin constraints from: https://example.com/a.txt"), |
| 480 | + ("entry", "Zope==6.0"), |
| 481 | + ("comment", "AccessControl==7.3 -> mxdev disabled (source)"), |
| 482 | + ("entry", 'backports.tarfile==1.2.0 ; python_version < "3.12"'), |
| 483 | + ("comment", "end constraints from: https://example.com/a.txt"), |
| 484 | + ] |
| 485 | + |
| 486 | + |
| 487 | +def test_constraints_to_uv_empty_input(): |
| 488 | + assert _constraints_to_uv([]) == [] |
| 489 | + assert _constraints_to_uv(["\n", "#" * 79 + "\n", " \n"]) == [] |
0 commit comments