-
Notifications
You must be signed in to change notification settings - Fork 5
Adding Profile Tests #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| my_examples | ||
| .idea | ||
| .env | ||
| .venv | ||
| .DS_Store | ||
| select_ai.egg-info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2025, Oracle and/or its affiliates. | ||
| # | ||
| # Licensed under the Universal Permissive License v 1.0 as shown at | ||
| # http://oss.oracle.com/licenses/upl. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| """ | ||
| 2000 - Synthetic data generation tests | ||
| """ | ||
|
|
||
| import uuid | ||
|
|
||
| import pytest | ||
| import select_ai | ||
| from select_ai import ( | ||
| Profile, | ||
| ProfileAttributes, | ||
| SyntheticDataAttributes, | ||
| SyntheticDataParams, | ||
| ) | ||
|
|
||
| PROFILE_PREFIX = f"PYSAI_2000_{uuid.uuid4().hex.upper()}" | ||
|
|
||
|
|
||
| def _build_attributes(record_count=1, **kwargs): | ||
| return SyntheticDataAttributes( | ||
| object_name="people", | ||
| record_count=record_count, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def synthetic_provider(oci_compartment_id): | ||
| return select_ai.OCIGenAIProvider( | ||
| oci_compartment_id=oci_compartment_id, | ||
| oci_apiformat="GENERIC", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def synthetic_profile_attributes(oci_credential, synthetic_provider): | ||
| return ProfileAttributes( | ||
| credential_name=oci_credential["credential_name"], | ||
| object_list=[ | ||
| {"owner": "ADMIN", "name": "people"}, | ||
| {"owner": "ADMIN", "name": "gymnast"}, | ||
| ], | ||
| provider=synthetic_provider, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def synthetic_profile(synthetic_profile_attributes): | ||
| profile = Profile( | ||
| profile_name=f"{PROFILE_PREFIX}_SYNC", | ||
| attributes=synthetic_profile_attributes, | ||
| description="Synthetic data test profile", | ||
| replace=True, | ||
| ) | ||
| yield profile | ||
| try: | ||
| profile.delete(force=True) | ||
| except Exception: | ||
| pass | ||
|
|
||
|
|
||
| def test_2000_generate_with_full_params(synthetic_profile): | ||
| """Generate synthetic data with full parameter set""" | ||
| params = SyntheticDataParams(sample_rows=10, priority="HIGH") | ||
| attributes = _build_attributes( | ||
| record_count=5, | ||
| params=params, | ||
| user_prompt="age must be greater than 20", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert with record_count as well. |
||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to log attributes count of name if static attributes. |
||
| result = synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| def test_2001_generate_minimum_fields(synthetic_profile): | ||
| """Generate synthetic data with minimum fields""" | ||
| attributes = _build_attributes() | ||
| result = synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| def test_2002_generate_zero_sample_rows(synthetic_profile): | ||
| """Generate synthetic data with zero sample rows""" | ||
| params = SyntheticDataParams(sample_rows=0, priority="HIGH") | ||
| attributes = _build_attributes(params=params) | ||
| result = synthetic_profile.generate_synthetic_data(attributes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert data with rows=0 ? |
||
| assert result is None | ||
|
|
||
|
|
||
| def test_2003_generate_single_sample_row(synthetic_profile): | ||
| """Generate synthetic data with single sample row""" | ||
| params = SyntheticDataParams(sample_rows=1, priority="HIGH") | ||
| attributes = _build_attributes(params=params) | ||
| result = synthetic_profile.generate_synthetic_data(attributes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please assert row count, row data if required. Add same for all consecutive tests. |
||
| assert result is None | ||
|
|
||
|
|
||
| def test_2004_generate_low_priority(synthetic_profile): | ||
| """Generate synthetic data with low priority""" | ||
| params = SyntheticDataParams(sample_rows=1, priority="LOW") | ||
| attributes = _build_attributes(params=params) | ||
| result = synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| def test_2005_generate_missing_object_name(synthetic_profile): | ||
| """Missing object_name raises error""" | ||
| attributes = SyntheticDataAttributes(record_count=1) | ||
| with pytest.raises(Exception): | ||
| synthetic_profile.generate_synthetic_data(attributes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert exception code and log exception code if required. |
||
|
|
||
|
|
||
| def test_2006_generate_invalid_priority(synthetic_profile): | ||
| """Invalid priority raises error""" | ||
| params = SyntheticDataParams(sample_rows=1, priority="CRITICAL") | ||
| attributes = _build_attributes(params=params) | ||
| with pytest.raises(Exception): | ||
| synthetic_profile.generate_synthetic_data(attributes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
|
||
|
|
||
| def test_2007_generate_negative_record_count(synthetic_profile): | ||
| """Negative record count raises error""" | ||
| attributes = _build_attributes(record_count=-5) | ||
| with pytest.raises(Exception): | ||
| synthetic_profile.generate_synthetic_data(attributes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert exception code and log it. |
||
|
|
||
|
|
||
| def test_2008_generate_with_none_attributes(synthetic_profile): | ||
| """Passing None as attributes raises error""" | ||
| with pytest.raises(Exception): | ||
| synthetic_profile.generate_synthetic_data(None) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2025, Oracle and/or its affiliates. | ||
| # | ||
| # Licensed under the Universal Permissive License v 1.0 as shown at | ||
| # http://oss.oracle.com/licenses/upl. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| """ | ||
| 2100 - Synthetic data generation tests (async) | ||
| """ | ||
|
|
||
| import uuid | ||
|
|
||
| import pytest | ||
| import select_ai | ||
| from select_ai import ( | ||
| AsyncProfile, | ||
| ProfileAttributes, | ||
| SyntheticDataAttributes, | ||
| SyntheticDataParams, | ||
| ) | ||
|
|
||
| PROFILE_PREFIX = f"PYSAI_2100_{uuid.uuid4().hex.upper()}" | ||
|
|
||
|
|
||
| def _build_attributes(record_count=1, **kwargs): | ||
| return SyntheticDataAttributes( | ||
| object_name="people", | ||
| record_count=record_count, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def async_synthetic_provider(oci_compartment_id): | ||
| return select_ai.OCIGenAIProvider( | ||
| oci_compartment_id=oci_compartment_id, | ||
| oci_apiformat="GENERIC", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def async_synthetic_profile_attributes( | ||
| oci_credential, async_synthetic_provider | ||
| ): | ||
| return ProfileAttributes( | ||
| credential_name=oci_credential["credential_name"], | ||
| object_list=[ | ||
| {"owner": "ADMIN", "name": "people"}, | ||
| {"owner": "ADMIN", "name": "gymnast"}, | ||
| ], | ||
| provider=async_synthetic_provider, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| async def async_synthetic_profile(async_synthetic_profile_attributes): | ||
| profile = await AsyncProfile( | ||
| profile_name=f"{PROFILE_PREFIX}_ASYNC", | ||
| attributes=async_synthetic_profile_attributes, | ||
| description="Synthetic data async test profile", | ||
| replace=True, | ||
| ) | ||
| yield profile | ||
| try: | ||
| await profile.delete(force=True) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add logs to confirm is profile delete is successful |
||
| except Exception: | ||
| pass | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2100_generate_with_full_params(async_synthetic_profile): | ||
| """Generate synthetic data with full parameter set""" | ||
| params = SyntheticDataParams(sample_rows=10, priority="HIGH") | ||
| attributes = _build_attributes( | ||
| record_count=5, | ||
| params=params, | ||
| user_prompt="age must be greater than 20", | ||
| ) | ||
| result = await async_synthetic_profile.generate_synthetic_data(attributes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert data and exception similar as above |
||
| assert result is None | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2101_generate_minimum_fields(async_synthetic_profile): | ||
| """Generate synthetic data with minimum fields""" | ||
| attributes = _build_attributes() | ||
| result = await async_synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2102_generate_zero_sample_rows(async_synthetic_profile): | ||
| """Generate synthetic data with zero sample rows""" | ||
| params = SyntheticDataParams(sample_rows=0, priority="HIGH") | ||
| attributes = _build_attributes(params=params) | ||
| result = await async_synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2103_generate_single_sample_row(async_synthetic_profile): | ||
| """Generate synthetic data with single sample row""" | ||
| params = SyntheticDataParams(sample_rows=1, priority="HIGH") | ||
| attributes = _build_attributes(params=params) | ||
| result = await async_synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2104_generate_low_priority(async_synthetic_profile): | ||
| """Generate synthetic data with low priority""" | ||
| params = SyntheticDataParams(sample_rows=1, priority="LOW") | ||
| attributes = _build_attributes(params=params) | ||
| result = await async_synthetic_profile.generate_synthetic_data(attributes) | ||
| assert result is None | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2105_generate_missing_object_name(async_synthetic_profile): | ||
| """Missing object_name raises error""" | ||
| attributes = SyntheticDataAttributes(record_count=1) | ||
| with pytest.raises(Exception): | ||
| await async_synthetic_profile.generate_synthetic_data(attributes) | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2106_generate_invalid_priority(async_synthetic_profile): | ||
| """Invalid priority raises error""" | ||
| params = SyntheticDataParams(sample_rows=1, priority="CRITICAL") | ||
| attributes = _build_attributes(params=params) | ||
| with pytest.raises(Exception): | ||
| await async_synthetic_profile.generate_synthetic_data(attributes) | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2107_generate_negative_record_count(async_synthetic_profile): | ||
| """Negative record count raises error""" | ||
| attributes = _build_attributes(record_count=-5) | ||
| with pytest.raises(Exception): | ||
| await async_synthetic_profile.generate_synthetic_data(attributes) | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_2108_generate_with_none_attributes(async_synthetic_profile): | ||
| """Passing None as attributes raises error""" | ||
| with pytest.raises(Exception): | ||
| await async_synthetic_profile.generate_synthetic_data(None) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't print credential