|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2025, Oracle and/or its affiliates. |
| 3 | +# |
| 4 | +# Licensed under the Universal Permissive License v 1.0 as shown at |
| 5 | +# http://oss.oracle.com/licenses/upl. |
| 6 | +# ----------------------------------------------------------------------------- |
| 7 | + |
| 8 | +""" |
| 9 | +2100 - Synthetic data generation tests (async) |
| 10 | +""" |
| 11 | + |
| 12 | +import uuid |
| 13 | + |
| 14 | +import pytest |
| 15 | +import select_ai |
| 16 | +from select_ai import AsyncProfile, ProfileAttributes, SyntheticDataAttributes, SyntheticDataParams |
| 17 | + |
| 18 | +PROFILE_PREFIX = f"PYSAI_2100_{uuid.uuid4().hex.upper()}" |
| 19 | + |
| 20 | + |
| 21 | +def _build_attributes(record_count=1, **kwargs): |
| 22 | + return SyntheticDataAttributes( |
| 23 | + object_name="people", |
| 24 | + record_count=record_count, |
| 25 | + **kwargs, |
| 26 | + ) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture(scope="module") |
| 30 | +def async_synthetic_provider(oci_compartment_id): |
| 31 | + return select_ai.OCIGenAIProvider( |
| 32 | + oci_compartment_id=oci_compartment_id, |
| 33 | + oci_apiformat="GENERIC", |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture(scope="module") |
| 38 | +def async_synthetic_profile_attributes(oci_credential, async_synthetic_provider): |
| 39 | + return ProfileAttributes( |
| 40 | + credential_name=oci_credential["credential_name"], |
| 41 | + object_list=[ |
| 42 | + {"owner": "ADMIN", "name": "people"}, |
| 43 | + {"owner": "ADMIN", "name": "gymnast"}, |
| 44 | + ], |
| 45 | + provider=async_synthetic_provider, |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +@pytest.fixture(scope="module") |
| 50 | +async def async_synthetic_profile(async_synthetic_profile_attributes): |
| 51 | + profile = await AsyncProfile( |
| 52 | + profile_name=f"{PROFILE_PREFIX}_ASYNC", |
| 53 | + attributes=async_synthetic_profile_attributes, |
| 54 | + description="Synthetic data async test profile", |
| 55 | + replace=True, |
| 56 | + ) |
| 57 | + yield profile |
| 58 | + try: |
| 59 | + await profile.delete(force=True) |
| 60 | + except Exception: |
| 61 | + pass |
| 62 | + |
| 63 | + |
| 64 | +@pytest.mark.anyio |
| 65 | +async def test_2100_generate_with_full_params(async_synthetic_profile): |
| 66 | + """Generate synthetic data with full parameter set""" |
| 67 | + params = SyntheticDataParams(sample_rows=10, priority="HIGH") |
| 68 | + attributes = _build_attributes( |
| 69 | + record_count=5, |
| 70 | + params=params, |
| 71 | + user_prompt="age must be greater than 20", |
| 72 | + ) |
| 73 | + result = await async_synthetic_profile.generate_synthetic_data(attributes) |
| 74 | + assert result is None |
| 75 | + |
| 76 | + |
| 77 | +@pytest.mark.anyio |
| 78 | +async def test_2101_generate_minimum_fields(async_synthetic_profile): |
| 79 | + """Generate synthetic data with minimum fields""" |
| 80 | + attributes = _build_attributes() |
| 81 | + result = await async_synthetic_profile.generate_synthetic_data(attributes) |
| 82 | + assert result is None |
| 83 | + |
| 84 | + |
| 85 | +@pytest.mark.anyio |
| 86 | +async def test_2102_generate_zero_sample_rows(async_synthetic_profile): |
| 87 | + """Generate synthetic data with zero sample rows""" |
| 88 | + params = SyntheticDataParams(sample_rows=0, priority="HIGH") |
| 89 | + attributes = _build_attributes(params=params) |
| 90 | + result = await async_synthetic_profile.generate_synthetic_data(attributes) |
| 91 | + assert result is None |
| 92 | + |
| 93 | + |
| 94 | +@pytest.mark.anyio |
| 95 | +async def test_2103_generate_single_sample_row(async_synthetic_profile): |
| 96 | + """Generate synthetic data with single sample row""" |
| 97 | + params = SyntheticDataParams(sample_rows=1, priority="HIGH") |
| 98 | + attributes = _build_attributes(params=params) |
| 99 | + result = await async_synthetic_profile.generate_synthetic_data(attributes) |
| 100 | + assert result is None |
| 101 | + |
| 102 | + |
| 103 | +@pytest.mark.anyio |
| 104 | +async def test_2104_generate_low_priority(async_synthetic_profile): |
| 105 | + """Generate synthetic data with low priority""" |
| 106 | + params = SyntheticDataParams(sample_rows=1, priority="LOW") |
| 107 | + attributes = _build_attributes(params=params) |
| 108 | + result = await async_synthetic_profile.generate_synthetic_data(attributes) |
| 109 | + assert result is None |
| 110 | + |
| 111 | + |
| 112 | +@pytest.mark.anyio |
| 113 | +async def test_2105_generate_missing_object_name(async_synthetic_profile): |
| 114 | + """Missing object_name raises error""" |
| 115 | + attributes = SyntheticDataAttributes(record_count=1) |
| 116 | + with pytest.raises(Exception): |
| 117 | + await async_synthetic_profile.generate_synthetic_data(attributes) |
| 118 | + |
| 119 | + |
| 120 | +@pytest.mark.anyio |
| 121 | +async def test_2106_generate_invalid_priority(async_synthetic_profile): |
| 122 | + """Invalid priority raises error""" |
| 123 | + params = SyntheticDataParams(sample_rows=1, priority="CRITICAL") |
| 124 | + attributes = _build_attributes(params=params) |
| 125 | + with pytest.raises(Exception): |
| 126 | + await async_synthetic_profile.generate_synthetic_data(attributes) |
| 127 | + |
| 128 | + |
| 129 | +@pytest.mark.anyio |
| 130 | +async def test_2107_generate_negative_record_count(async_synthetic_profile): |
| 131 | + """Negative record count raises error""" |
| 132 | + attributes = _build_attributes(record_count=-5) |
| 133 | + with pytest.raises(Exception): |
| 134 | + await async_synthetic_profile.generate_synthetic_data(attributes) |
| 135 | + |
| 136 | + |
| 137 | +@pytest.mark.anyio |
| 138 | +async def test_2108_generate_with_none_attributes(async_synthetic_profile): |
| 139 | + """Passing None as attributes raises error""" |
| 140 | + with pytest.raises(Exception): |
| 141 | + await async_synthetic_profile.generate_synthetic_data(None) |
0 commit comments