Skip to content

Commit

Permalink
move unit test to integration; update Gretel docstring
Browse files Browse the repository at this point in the history
* move unit test to integration; update Gretel docstring

* minor wording update; oss tests are passing

* style... argh

GitOrigin-RevId: 38aeb79b1a1e98565834cb8516f4f9ac90f9c507
  • Loading branch information
johnnygreco committed Sep 24, 2023
1 parent b1b65d2 commit a6f1745
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 46 deletions.
45 changes: 21 additions & 24 deletions src/gretel_client/gretel/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,31 @@ class Gretel:
first job submission. You can change projects using the `set_project` method.
Args:
project_name: Name of new or existing project. If a new project name is given,
it will be created at instantiation. If no name is given, a new project
with a randomized name will be created with the first job submission.
project_display_name: Project display name. If None, will use project name.
This argument is only used when creating a new project.
project_name (str): Name of new or existing project. If a new project name
is given, it will be created at instantiation. If no name given, a new
randomly-named project will be created with the first job submission.
project_display_name (str): Project display name. If `None`, will use the
project name. This argument is only used when creating a new project.
**session_kwargs: kwargs for your Gretel session. See options below.
Keyword Args:
config: The config to update. This config takes precedence over
other parameters such as ``api_key`` or ``endpoint``.
api_key: Configures your Gretel API key. If ``api_key`` is set to
"prompt" and no Api Key is found on the system, ``getpass``
will be used to prompt for the key.
default_runner: Specifies the runner mode. Must be one of "cloud", "local",
"manual", or "hybrid". The default is "cloud".
endpoint: Specifies the Gretel API endpoint. This must be a fully
api_key (str): Your Gretel API key. If set to "prompt" and no API key
is found on the system, you will be prompted for the key.
endpoint (str): Specifies the Gretel API endpoint. This must be a fully
qualified URL. The default is "https://api.gretel.cloud".
artifact_endpoint: Specifies the endpoint for project and model artifacts.
Defaults to "cloud" for running in Gretel Cloud. If working in
hybrid mode, set to the URL of your artifact storage bucket.
cache: Valid options include "yes" and "no". If cache is "no"
the session configuration will not be written to disk. If cache is
"yes", session configuration will be written to disk only if a
configuration doesn't exist.
validate: If set to ``True`` this will check that login credentials
are valid.
clear: If set to ``True`` any existing Gretel credentials will be
removed from the host.
default_runner (str): Specifies the runner mode. Must be one of "cloud",
"local", "manual", or "hybrid". The default is "cloud".
artifact_endpoint (str): Specifies the endpoint for project and model
artifacts. Defaults to "cloud" for running in Gretel Cloud. If
working in hybrid mode, set to the URL of your artifact storage bucket.
cache (str): Valid options are "yes" or "no". If set to "no", the session
configuration will not be written to disk. If set to "yes", the
session configuration will be written to disk only if one doesn't
already exist. The default is "no".
validate (bool): If `True`, will validate the login credentials at
instantiation. The default is `False`.
clear (bool): If `True`, existing Gretel credentials will be removed.
The default is `False.`
"""

def __init__(
Expand Down
20 changes: 19 additions & 1 deletion tests/gretel_client/integration/test_gretel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import pandas as pd
import pytest

from gretel_client.gretel.exceptions import GretelJobSubmissionError
from gretel_client.gretel.exceptions import (
GretelJobSubmissionError,
GretelProjectNotSetError,
)
from gretel_client.gretel.interface import Gretel

NUM_RECORDS = 100
Expand Down Expand Up @@ -129,3 +132,18 @@ def test_gretel_submit_generate_invalid_arguments(gretel: Gretel):
gretel.submit_generate(
model.model_id, num_records=10, seed_data=seed_data_file_path
)


def test_gretel_no_project_set_exceptions():
gretel = Gretel(endpoint="https://api-dev.gretel.cloud")

assert gretel._project is None

with pytest.raises(GretelProjectNotSetError):
gretel.fetch_model(model_id="1234")

with pytest.raises(GretelProjectNotSetError):
gretel.fetch_train_job_results(model_id="1234")

with pytest.raises(GretelProjectNotSetError):
gretel.fetch_generate_job_results(model_id="1234", record_id="1234")
22 changes: 1 addition & 21 deletions tests/gretel_client/test_gretel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
import pytest

from gretel_client.gretel.config_setup import create_model_config_from_base
from gretel_client.gretel.exceptions import (
BaseConfigError,
ConfigSettingError,
GretelProjectNotSetError,
)
from gretel_client.gretel.interface import Gretel
from gretel_client.gretel.exceptions import BaseConfigError, ConfigSettingError


@pytest.fixture
Expand Down Expand Up @@ -67,18 +62,3 @@ def test_create_config_settings_error():
base_config="tabular-actgan",
params="must be a dict",
)


def test_gretel_no_project_set_exceptions():
gretel = Gretel(endpoint="https://api-dev.gretel.cloud")

assert gretel._project is None

with pytest.raises(GretelProjectNotSetError):
gretel.fetch_model(model_id="1234")

with pytest.raises(GretelProjectNotSetError):
gretel.fetch_train_job_results(model_id="1234")

with pytest.raises(GretelProjectNotSetError):
gretel.fetch_generate_job_results(model_id="1234", record_id="1234")

0 comments on commit a6f1745

Please sign in to comment.