Buckets:
| """Tests for `fpgm.data.ids`'s uuid -> DROID raw bucket path derivation. | |
| Pure-stdlib logic, deliberately: no numpy/h5py/requests import happens on | |
| this path, so these tests run in bare environments (e.g. system python3.10, | |
| before the project's conda env exists). | |
| """ | |
| from __future__ import annotations | |
| import pytest | |
| from fpgm.data.ids import ( | |
| DROID_RAW_BUCKET_ROOT, | |
| episode_base_url, | |
| episode_date, | |
| episode_dirname, | |
| metadata_filename, | |
| ) | |
| from fpgm.types import EpisodeId | |
| # Three uuids verified against PointWorld's own `real/droid_paths.txt`. | |
| DOUBLE_DIGIT_DAY = ("AUTOLab+0d4edc83+2023-10-21-19h-07m-04s", "Sat_Oct_21_19:07:04_2023") | |
| SINGLE_DIGIT_DAY = ("SomeLab+abcdef01+2023-10-06-19h-50m-14s", "Fri_Oct__6_19:50:14_2023") | |
| ANOTHER_DOUBLE_DIGIT_DAY = ("IPRL+12345678+2023-01-15-09h-03m-22s", "Sun_Jan_15_09:03:22_2023") | |
| def test_episode_dirname_matches_verified_examples(uuid: str, expected_dirname: str) -> None: | |
| assert episode_dirname(EpisodeId(uuid)) == expected_dirname | |
| def test_single_digit_day_has_double_underscore() -> None: | |
| """The `%e` space-pad -> `_` substitution trap: single-digit days must NOT | |
| collapse to a single underscore like a naive zero-padded format would. | |
| """ | |
| dirname = episode_dirname(EpisodeId(SINGLE_DIGIT_DAY[0])) | |
| assert "__6" in dirname | |
| assert dirname == "Fri_Oct__6_19:50:14_2023" | |
| def test_double_digit_day_has_single_underscore() -> None: | |
| dirname = episode_dirname(EpisodeId(DOUBLE_DIGIT_DAY[0])) | |
| assert "_21_" in dirname | |
| assert "__" not in dirname | |
| def test_episode_id_uuid_roundtrip(uuid: str, expected_dirname: str) -> None: | |
| """uuid -> (lab, user_id, timestamp) -> dirname round-trips to the verified string.""" | |
| episode_id = EpisodeId(uuid) | |
| lab, user_id, ts_str = uuid.split("+") | |
| assert episode_id.lab == lab | |
| assert episode_id.user_id == user_id | |
| assert episode_id.timestamp.strftime("%Y-%m-%d-%Hh-%Mm-%Ss") == ts_str | |
| assert episode_dirname(episode_id) == expected_dirname | |
| def test_episode_date_is_iso_and_independent_of_dirname_format() -> None: | |
| episode_id = EpisodeId(DOUBLE_DIGIT_DAY[0]) | |
| assert episode_date(episode_id) == "2023-10-21" | |
| def test_metadata_filename_percent_encodes_plus() -> None: | |
| episode_id = EpisodeId(DOUBLE_DIGIT_DAY[0]) | |
| filename = metadata_filename(episode_id) | |
| assert filename.startswith("metadata_") | |
| assert filename.endswith(".json") | |
| assert "+" not in filename | |
| assert "%2B" in filename | |
| def test_episode_base_url_percent_encodes_colon_and_has_expected_shape() -> None: | |
| episode_id = EpisodeId(SINGLE_DIGIT_DAY[0]) | |
| url = episode_base_url(episode_id, "success") | |
| assert url.startswith(DROID_RAW_BUCKET_ROOT) | |
| assert "/SomeLab/success/2023-10-06/" in url | |
| # The scheme's own "://" is not part of the path, so only the path is checked. | |
| path = url[len(DROID_RAW_BUCKET_ROOT) :] | |
| assert ":" not in path # the timestamp's colons must be percent-encoded | |
| assert "%3A" in path | |
| assert url.endswith("/") | |
| def test_episode_base_url_rejects_unknown_outcome() -> None: | |
| episode_id = EpisodeId(DOUBLE_DIGIT_DAY[0]) | |
| with pytest.raises(ValueError): | |
| episode_base_url(episode_id, "maybe") | |
Xet Storage Details
- Size:
- 3.46 kB
- Xet hash:
- e1e2aeb9fdba2ba2d8c3e1577c00791720697c32cc4e8ae26f95e88c2a92f019
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.