|
51 | 51 | extract_input_hash, |
52 | 52 | install, |
53 | 53 | main, |
| 54 | + make_lock_files, |
54 | 55 | make_lock_spec, |
55 | 56 | render_lockfile_for_platform, |
56 | 57 | run_lock, |
@@ -3478,3 +3479,71 @@ def get_content_hashes_for_lock_file(lock_file: Path) -> dict[str, str]: |
3478 | 3479 | ) |
3479 | 3480 | postupdate_hashes = get_content_hashes_for_lock_file(work_path / "conda-lock.yml") |
3480 | 3481 | assert preupdate_hashes != postupdate_hashes |
| 3482 | + |
| 3483 | + |
| 3484 | +def test_update_with_changed_channels_raises_error( |
| 3485 | + tmp_path: Path, conda_exe: str |
| 3486 | +) -> None: |
| 3487 | + """Test that updating with changed channels raises an error.""" |
| 3488 | + |
| 3489 | + # Create a simple environment file |
| 3490 | + environment_yml = tmp_path / "environment.yml" |
| 3491 | + environment_yml.write_text(""" |
| 3492 | +channels: |
| 3493 | + - conda-forge |
| 3494 | +dependencies: |
| 3495 | + - python=3.9 |
| 3496 | +""") |
| 3497 | + from conda_lock.lockfile.v1.models import ( |
| 3498 | + HashModel, |
| 3499 | + LockedDependency, |
| 3500 | + Lockfile, |
| 3501 | + LockMeta, |
| 3502 | + ) |
| 3503 | + |
| 3504 | + # Create an existing lockfile with different channels |
| 3505 | + lockfile_path = tmp_path / "conda-lock.yml" |
| 3506 | + existing_lockfile = Lockfile( |
| 3507 | + package=[ |
| 3508 | + LockedDependency( |
| 3509 | + name="python", |
| 3510 | + version="3.9.18", |
| 3511 | + manager="conda", |
| 3512 | + platform="linux-64", |
| 3513 | + url="https://conda.anaconda.org/defaults/linux-64/python-3.9.18-h955ad1f_0.conda", |
| 3514 | + hash=HashModel(md5="abc123", sha256="def456"), |
| 3515 | + category="main", |
| 3516 | + optional=False, |
| 3517 | + ) |
| 3518 | + ], |
| 3519 | + metadata=LockMeta( |
| 3520 | + content_hash={"linux-64": "test_hash"}, |
| 3521 | + channels=[ |
| 3522 | + Channel.from_string("defaults") |
| 3523 | + ], # Different from environment.yml |
| 3524 | + platforms=["linux-64"], |
| 3525 | + sources=["environment.yml"], |
| 3526 | + ), |
| 3527 | + ) |
| 3528 | + |
| 3529 | + # Write the existing lockfile |
| 3530 | + with open(lockfile_path, "w") as f: |
| 3531 | + yaml.dump(existing_lockfile.dict_for_output(), f) |
| 3532 | + |
| 3533 | + # Try to update - this should raise an error |
| 3534 | + with pytest.raises(RuntimeError) as exc_info: |
| 3535 | + make_lock_files( |
| 3536 | + conda=conda_exe, |
| 3537 | + src_files=[environment_yml], |
| 3538 | + kinds=["lock"], |
| 3539 | + lockfile_path=lockfile_path, |
| 3540 | + update=["python"], # Try to update python |
| 3541 | + mapping_url=DEFAULT_MAPPING_URL, |
| 3542 | + ) |
| 3543 | + |
| 3544 | + # Verify the error message contains the expected information |
| 3545 | + error_msg = str(exc_info.value) |
| 3546 | + assert "channel configuration has changed" in error_msg |
| 3547 | + assert "defaults" in error_msg |
| 3548 | + assert "conda-forge" in error_msg |
| 3549 | + assert "without the --update flag" in error_msg |
0 commit comments