|
4 | 4 | import tomli_w |
5 | 5 |
|
6 | 6 | from hatch.config.constants import ConfigEnvVars |
| 7 | +from hatch.env.lockers.uv import UvLocker |
7 | 8 | from hatch.project.core import Project |
8 | 9 | from hatch.utils.toml import load_toml_file |
9 | 10 |
|
@@ -372,6 +373,46 @@ def test_check_exists(hatch, helpers, temp_dir, config_file): |
372 | 373 | assert "Lockfile is up to date" in result.output |
373 | 374 |
|
374 | 375 |
|
| 376 | +def test_uv_in_sync_ignores_autogenerated_command_header(helpers, monkeypatch, temp_dir): |
| 377 | + lock_path = temp_dir / "pylock.toml" |
| 378 | + lock_body = helpers.dedent( |
| 379 | + """ |
| 380 | + lock-version = "1.0" |
| 381 | + created-by = "uv" |
| 382 | +
|
| 383 | + [[packages]] |
| 384 | + name = "click" |
| 385 | + version = "8.4.1" |
| 386 | + """ |
| 387 | + ) |
| 388 | + lock_path.write_text( |
| 389 | + helpers.dedent( |
| 390 | + """ |
| 391 | + # This file was autogenerated by uv via the following command: |
| 392 | + # uv pip compile /tmp/requirements.txt --output-file /project/pylock.toml |
| 393 | + """ |
| 394 | + ) |
| 395 | + + lock_body, |
| 396 | + encoding="utf-8", |
| 397 | + ) |
| 398 | + |
| 399 | + def generate(_cls, _environment, _dependencies, output_path, **_kwargs): |
| 400 | + output_path.write_text( |
| 401 | + helpers.dedent( |
| 402 | + """ |
| 403 | + # This file was autogenerated by uv via the following command: |
| 404 | + # uv pip compile /tmp/tmpabc/requirements.txt --output-file /tmp/tmpabc/pylock.toml |
| 405 | + """ |
| 406 | + ) |
| 407 | + + lock_body, |
| 408 | + encoding="utf-8", |
| 409 | + ) |
| 410 | + |
| 411 | + monkeypatch.setattr(UvLocker, "generate", classmethod(generate)) |
| 412 | + |
| 413 | + assert UvLocker.in_sync(object(), [], lock_path) |
| 414 | + |
| 415 | + |
375 | 416 | @pytest.mark.usefixtures("mock_locker") |
376 | 417 | def test_check_lockfile_stale(hatch, helpers, temp_dir, config_file): |
377 | 418 | config_file.model.template.plugins["default"]["tests"] = False |
|
0 commit comments