Download flax_model/alphafold3/common/testing/data.py from OneScience-Group/AlphaFold3: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/OneScience-Group/AlphaFold3/resolve/main/flax_model/alphafold3/common/testing/data.py
- Command line
-
hf download hf://OneScience-Group/AlphaFold3/flax_model/alphafold3/common/testing/data.py
-
curl -L -o data.py https://huggingface.co/OneScience-Group/AlphaFold3/resolve/main/flax_model/alphafold3/common/testing/data.py
1.6 kB
| """Module that provides an abstraction for accessing test data.""" | |
| import os | |
| import pathlib | |
| from typing import Literal, overload | |
| from absl.testing import absltest | |
| class Data: | |
| """Provides an abstraction for accessing test data.""" | |
| def __init__(self, data_dir: os.PathLike[str] | str): | |
| """Initiailizes data wrapper, providing users with high level data access. | |
| Args: | |
| data_dir: Directory containing test data. | |
| """ | |
| self._data_dir = pathlib.Path(data_dir) | |
| def path(self, data_name: str | os.PathLike[str] | None = None) -> str: | |
| """Returns the path to a given test data. | |
| Args: | |
| data_name: the name of the test data file relative to data_dir. If not | |
| set, this will return the absolute path to the data directory. | |
| """ | |
| data_dir_path = ( | |
| pathlib.Path(absltest.get_default_test_srcdir()) / self._data_dir | |
| ) | |
| if data_name: | |
| return str(data_dir_path / data_name) | |
| return str(data_dir_path) | |
| def load( | |
| self, data_name: str | os.PathLike[str], mode: Literal['rt'] = 'rt' | |
| ) -> str: | |
| ... | |
| def load( | |
| self, data_name: str | os.PathLike[str], mode: Literal['rb'] = 'rb' | |
| ) -> bytes: | |
| ... | |
| def load( | |
| self, data_name: str | os.PathLike[str], mode: str = 'rt' | |
| ) -> str | bytes: | |
| """Returns the contents of a given test data. | |
| Args: | |
| data_name: the name of the test data file relative to data_dir. | |
| mode: the mode in which to read the data file. Defaults to text ('rt'). | |
| """ | |
| with open(self.path(data_name), mode=mode) as f: | |
| return f.read() | |