def test_read_old_lock_and_write_new(tmpdir): build_only = ('build', ) y = MockPackage('y', [], []) x = MockPackage('x', [y], [build_only]) mock_repo = MockPackageMultiRepo([x, y]) with spack.repo.swap(mock_repo): x = Spec('x') x.concretize() y = x['y'] test_lockfile_dict = create_v1_lockfile_dict([x], [x, y]) test_lockfile_path = str(tmpdir.join('test.lock')) with open(test_lockfile_path, 'w') as f: sjson.dump(test_lockfile_dict, stream=f) _env_create('test', test_lockfile_path, with_view=False) e = ev.read('test') hashes = set(e._to_lockfile_dict()['concrete_specs']) # When the lockfile is rewritten, it should adopt the new hash scheme # which accounts for all dependencies, including build dependencies assert hashes == set([x.build_hash(), y.build_hash()])
def test_read_old_lock_creates_backup(tmpdir): """When reading a version-1 lockfile, make sure that a backup of that file is created. """ y = MockPackage('y', [], []) mock_repo = MockPackageMultiRepo([y]) with spack.repo.swap(mock_repo): y = Spec('y') y.concretize() test_lockfile_dict = create_v1_lockfile_dict([y], [y]) env_root = tmpdir.mkdir('test-root') test_lockfile_path = str(env_root.join(ev.lockfile_name)) with open(test_lockfile_path, 'w') as f: sjson.dump(test_lockfile_dict, stream=f) e = ev.Environment(str(env_root)) assert os.path.exists(e._lock_backup_v1_path) with open(e._lock_backup_v1_path, 'r') as backup_v1_file: lockfile_dict_v1 = sjson.load(backup_v1_file) # Make sure that the backup file follows the v1 hash scheme assert y.dag_hash() in lockfile_dict_v1['concrete_specs']