Download data/tests/test_libio.py from introvoyz042/haddock3: direct link, hf CLI and curl.
- Browser
- Download file 3.33 kB
-
https://huggingface.co/datasets/introvoyz042/haddock3/resolve/main/data/tests/test_libio.py
- Command line
-
hf download hf://datasets/introvoyz042/haddock3/data/tests/test_libio.py
-
curl -L -o test_libio.py https://huggingface.co/datasets/introvoyz042/haddock3/resolve/main/data/tests/test_libio.py
3.33 kB
| """Test libio.""" | |
| import tempfile | |
| from pathlib import Path | |
| import shutil | |
| import pytest | |
| from haddock.libs.libio import ( | |
| clean_suffix, | |
| dot_suffix, | |
| extract_files_flat, | |
| file_exists, | |
| folder_exists, | |
| read_from_yaml, | |
| write_dic_to_file, | |
| write_nested_dic_to_file, | |
| ) | |
| from . import emptycfg, haddock3_yaml_cfg_examples | |
| from . import golden_data | |
| def test_read_from_yaml(cfg): | |
| """Test read from yaml file.""" | |
| result = read_from_yaml(cfg) | |
| assert isinstance(result, dict) | |
| def test_write_nested_dic_to_file(): | |
| """Test write nested dictionary to file.""" | |
| f = tempfile.NamedTemporaryFile(delete=False) | |
| write_nested_dic_to_file( | |
| data_dict={1: {"something": "something"}}, | |
| output_fname=f.name) | |
| assert Path(f.name).exists() | |
| assert Path(f.name).stat().st_size != 0 | |
| Path(f.name).unlink() | |
| def test_write_dic_to_file(): | |
| """Test write dictionary to file.""" | |
| f = tempfile.NamedTemporaryFile(delete=False) | |
| write_dic_to_file( | |
| data_dict={"something": "something"}, | |
| output_fname=f.name) | |
| assert Path(f.name).exists() | |
| assert Path(f.name).stat().st_size != 0 | |
| Path(f.name).unlink() | |
| def test_dot_suffix(in_, expected): | |
| result = dot_suffix(in_) | |
| assert result == expected | |
| def test_clean_suffix(in_, expected): | |
| result = clean_suffix(in_) | |
| assert result == expected | |
| def test_file_exists(i, expected): | |
| """.""" | |
| r = file_exists(i) | |
| assert r == expected | |
| def test_file_exists_wrong(i): | |
| """.""" | |
| with pytest.raises(ValueError): | |
| file_exists(i) | |
| def test_folder_exists(): | |
| """.""" | |
| r = folder_exists(Path(__file__).parent) | |
| assert r == Path(__file__).parent | |
| def test_folder_exists_wrong(i): | |
| """.""" | |
| with pytest.raises(ValueError): | |
| folder_exists(i) | |
| def test_folder_exists_wrong_othererror(): | |
| with pytest.raises(TypeError): | |
| folder_exists("some_bad_path", exception=TypeError) | |
| def test_extract_files_flat(monkeypatch): | |
| """Test extract_files_flat.""" | |
| with tempfile.TemporaryDirectory() as tempdir: | |
| reference_archive = Path(golden_data, "ambig.tbl.tgz") | |
| shutil.copy(reference_archive, tempdir) | |
| monkeypatch.chdir(tempdir) | |
| archive = Path(reference_archive.name) | |
| # extract the archive | |
| extract_files_flat(archive, ".") | |
| assert Path("ambig_1.tbl").exists() | |