def test_install_overwrite( mock_packages, mock_archive, mock_fetch, config, install_mockery ): # It's not possible to overwrite something that is not yet installed with pytest.raises(AssertionError): install('--overwrite', 'libdwarf') # --overwrite requires a single spec with pytest.raises(AssertionError): install('--overwrite', 'libdwarf', 'libelf') # Try to install a spec and then to reinstall it. spec = Spec('libdwarf') spec.concretize() install('libdwarf') assert os.path.exists(spec.prefix) expected_md5 = fs.hash_directory(spec.prefix) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(spec.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_md5 = fs.hash_directory(spec.prefix) assert bad_md5 != expected_md5 install('--overwrite', '-y', 'libdwarf') assert os.path.exists(spec.prefix) assert fs.hash_directory(spec.prefix) == expected_md5 assert fs.hash_directory(spec.prefix) != bad_md5
def test_install_overwrite(mock_packages, mock_archive, mock_fetch, config, install_mockery): # Try to install a spec and then to reinstall it. spec = Spec('libdwarf') spec.concretize() install('libdwarf') # Ignore manifest and install times manifest = os.path.join(spec.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name) ignores = [manifest, spec.package.times_log_path] assert os.path.exists(spec.prefix) expected_md5 = fs.hash_directory(spec.prefix, ignore=ignores) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(spec.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_md5 = fs.hash_directory(spec.prefix, ignore=ignores) assert bad_md5 != expected_md5 install('--overwrite', '-y', 'libdwarf') assert os.path.exists(spec.prefix) assert fs.hash_directory(spec.prefix, ignore=ignores) == expected_md5 assert fs.hash_directory(spec.prefix, ignore=ignores) != bad_md5
def test_install_overwrite(mock_packages, mock_archive, mock_fetch, config, install_mockery): # It's not possible to overwrite something that is not yet installed with pytest.raises(AssertionError): install('--overwrite', 'libdwarf') # --overwrite requires a single spec with pytest.raises(AssertionError): install('--overwrite', 'libdwarf', 'libelf') # Try to install a spec and then to reinstall it. spec = Spec('libdwarf') spec.concretize() install('libdwarf') assert os.path.exists(spec.prefix) expected_md5 = fs.hash_directory(spec.prefix) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(spec.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_md5 = fs.hash_directory(spec.prefix) assert bad_md5 != expected_md5 install('--overwrite', '-y', 'libdwarf') assert os.path.exists(spec.prefix) assert fs.hash_directory(spec.prefix) == expected_md5 assert fs.hash_directory(spec.prefix) != bad_md5
def test_move_transaction_commit(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') old_md5 = fs.hash_directory(str(tmpdir)) with fs.replace_directory_transaction(str(tmpdir.join('lib'))): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') new_md5 = fs.hash_directory(str(tmpdir)) assert old_md5 != fs.hash_directory(str(tmpdir)) assert new_md5 == fs.hash_directory(str(tmpdir))
def test_move_transaction_commit(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') old_md5 = fs.hash_directory(str(tmpdir)) with fs.replace_directory_transaction(str(tmpdir.join('lib'))): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') new_md5 = fs.hash_directory(str(tmpdir)) assert old_md5 != fs.hash_directory(str(tmpdir)) assert new_md5 == fs.hash_directory(str(tmpdir))
def test_move_transaction_rollback(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') h = fs.hash_directory(str(tmpdir)) try: with fs.replace_directory_transaction(str(tmpdir.join('lib'))): assert h != fs.hash_directory(str(tmpdir)) fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') raise RuntimeError('') except RuntimeError: pass assert h == fs.hash_directory(str(tmpdir))
def test_move_transaction_rollback(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') h = fs.hash_directory(str(tmpdir)) try: with fs.replace_directory_transaction(str(tmpdir.join('lib'))): assert h != fs.hash_directory(str(tmpdir)) fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') raise RuntimeError('') except RuntimeError: pass assert h == fs.hash_directory(str(tmpdir))
def test_install_overwrite_multiple( mock_packages, mock_archive, mock_fetch, config, install_mockery ): # Try to install a spec and then to reinstall it. libdwarf = Spec('libdwarf') libdwarf.concretize() install('libdwarf') cmake = Spec('cmake') cmake.concretize() install('cmake') ld_manifest = os.path.join(libdwarf.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name) ld_ignores = [ld_manifest, libdwarf.package.times_log_path] assert os.path.exists(libdwarf.prefix) expected_libdwarf_md5 = fs.hash_directory(libdwarf.prefix, ignore=ld_ignores) cm_manifest = os.path.join(cmake.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name) cm_ignores = [cm_manifest, cmake.package.times_log_path] assert os.path.exists(cmake.prefix) expected_cmake_md5 = fs.hash_directory(cmake.prefix, ignore=cm_ignores) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(libdwarf.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') with open(os.path.join(cmake.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_libdwarf_md5 = fs.hash_directory(libdwarf.prefix, ignore=ld_ignores) bad_cmake_md5 = fs.hash_directory(cmake.prefix, ignore=cm_ignores) assert bad_libdwarf_md5 != expected_libdwarf_md5 assert bad_cmake_md5 != expected_cmake_md5 install('--overwrite', '-y', 'libdwarf', 'cmake') assert os.path.exists(libdwarf.prefix) assert os.path.exists(cmake.prefix) ld_hash = fs.hash_directory(libdwarf.prefix, ignore=ld_ignores) cm_hash = fs.hash_directory(cmake.prefix, ignore=cm_ignores) assert ld_hash == expected_libdwarf_md5 assert cm_hash == expected_cmake_md5 assert ld_hash != bad_libdwarf_md5 assert cm_hash != bad_cmake_md5
def test_install_overwrite_multiple(mock_packages, mock_archive, mock_fetch, config, install_mockery): # Try to install a spec and then to reinstall it. libdwarf = Spec('libdwarf') libdwarf.concretize() install('libdwarf') cmake = Spec('cmake') cmake.concretize() install('cmake') assert os.path.exists(libdwarf.prefix) expected_libdwarf_md5 = fs.hash_directory(libdwarf.prefix) assert os.path.exists(cmake.prefix) expected_cmake_md5 = fs.hash_directory(cmake.prefix) # Modify the first installation to be sure the content is not the same # as the one after we reinstalled with open(os.path.join(libdwarf.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') with open(os.path.join(cmake.prefix, 'only_in_old'), 'w') as f: f.write('This content is here to differentiate installations.') bad_libdwarf_md5 = fs.hash_directory(libdwarf.prefix) bad_cmake_md5 = fs.hash_directory(cmake.prefix) assert bad_libdwarf_md5 != expected_libdwarf_md5 assert bad_cmake_md5 != expected_cmake_md5 install('--overwrite', '-y', 'libdwarf', 'cmake') assert os.path.exists(libdwarf.prefix) assert os.path.exists(cmake.prefix) assert fs.hash_directory(libdwarf.prefix) == expected_libdwarf_md5 assert fs.hash_directory(cmake.prefix) == expected_cmake_md5 assert fs.hash_directory(libdwarf.prefix) != bad_libdwarf_md5 assert fs.hash_directory(cmake.prefix) != bad_cmake_md5