|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from nucleus.dataset import Dataset |
| 6 | +from nucleus.errors import NucleusAPIError |
| 7 | +from tests.helpers import DATASET_WITH_AUTOTAG, running_as_nucleus_pytest_user |
| 8 | + |
1 | 9 | # TODO: Test delete_autotag once API support for autotag creation is added. |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.integration |
| 13 | +def test_update_autotag(CLIENT): |
| 14 | + if running_as_nucleus_pytest_user(CLIENT): |
| 15 | + job = Dataset(DATASET_WITH_AUTOTAG, CLIENT).update_autotag( |
| 16 | + "tag_c5jwvzzde8c00604mkx0" |
| 17 | + ) |
| 18 | + job.sleep_until_complete() |
| 19 | + status = job.status() |
| 20 | + assert status["status"] == "Completed" |
| 21 | + |
| 22 | + |
| 23 | +def test_dataset_export_autotag_training_items(CLIENT): |
| 24 | + # This test can only run for the test user who has an indexed dataset. |
| 25 | + # TODO: if/when we can create autotags via api, create one instead. |
| 26 | + if running_as_nucleus_pytest_user(CLIENT): |
| 27 | + dataset = CLIENT.get_dataset(DATASET_WITH_AUTOTAG) |
| 28 | + |
| 29 | + with pytest.raises(NucleusAPIError) as api_error: |
| 30 | + dataset.autotag_training_items(autotag_name="NONSENSE_GARBAGE") |
| 31 | + assert ( |
| 32 | + f"The autotag NONSENSE_GARBAGE was not found in dataset {DATASET_WITH_AUTOTAG}" |
| 33 | + in str(api_error.value) |
| 34 | + ) |
| 35 | + |
| 36 | + items = dataset.autotag_training_items(autotag_name="PytestTestTag") |
| 37 | + |
| 38 | + assert "autotagPositiveTrainingItems" in items |
| 39 | + assert "autotag" in items |
| 40 | + |
| 41 | + autotagTrainingItems = items["autotagPositiveTrainingItems"] |
| 42 | + autotag = items["autotag"] |
| 43 | + |
| 44 | + assert len(autotagTrainingItems) > 0 |
| 45 | + for item in autotagTrainingItems: |
| 46 | + for column in ["ref_id"]: |
| 47 | + assert column in item |
| 48 | + |
| 49 | + for column in ["id", "name", "status", "autotag_level"]: |
| 50 | + assert column in autotag |
| 51 | + |
| 52 | + |
| 53 | +def test_export_embeddings(CLIENT): |
| 54 | + if running_as_nucleus_pytest_user(CLIENT): |
| 55 | + embeddings = Dataset(DATASET_WITH_AUTOTAG, CLIENT).export_embeddings() |
| 56 | + assert "embedding_vector" in embeddings[0] |
| 57 | + assert "reference_id" in embeddings[0] |
| 58 | + |
| 59 | + |
| 60 | +def test_dataset_export_autotag_tagged_items(CLIENT): |
| 61 | + # This test can only run for the test user who has an indexed dataset. |
| 62 | + # TODO: if/when we can create autotags via api, create one instead. |
| 63 | + if running_as_nucleus_pytest_user(CLIENT): |
| 64 | + dataset = CLIENT.get_dataset(DATASET_WITH_AUTOTAG) |
| 65 | + |
| 66 | + with pytest.raises(NucleusAPIError) as api_error: |
| 67 | + dataset.autotag_items(autotag_name="NONSENSE_GARBAGE") |
| 68 | + assert ( |
| 69 | + f"The autotag NONSENSE_GARBAGE was not found in dataset {DATASET_WITH_AUTOTAG}" |
| 70 | + in str(api_error.value) |
| 71 | + ) |
| 72 | + |
| 73 | + items = dataset.autotag_items(autotag_name="PytestTestTag") |
| 74 | + |
| 75 | + assert "autotagItems" in items |
| 76 | + assert "autotag" in items |
| 77 | + |
| 78 | + autotagItems = items["autotagItems"] |
| 79 | + autotag = items["autotag"] |
| 80 | + |
| 81 | + assert len(autotagItems) > 0 |
| 82 | + for item in autotagItems: |
| 83 | + for column in ["ref_id", "score"]: |
| 84 | + assert column in item |
| 85 | + |
| 86 | + for column in ["id", "name", "status", "autotag_level"]: |
| 87 | + assert column in autotag |
| 88 | + |
| 89 | + |
| 90 | +def test_export_slice_embeddings(CLIENT): |
| 91 | + if running_as_nucleus_pytest_user(CLIENT): |
| 92 | + test_slice = CLIENT.get_slice("slc_c6kcx5mrzr7g0c9d8cng") |
| 93 | + embeddings = test_slice.export_embeddings() |
| 94 | + assert "embedding_vector" in embeddings[0] |
| 95 | + assert "reference_id" in embeddings[0] |
0 commit comments