Skip to content

Commit

Permalink
init model directly for unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
deigen committed Jan 24, 2025
1 parent a05a8b3 commit e851890
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/runners/test_runners.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This test will create dummy runner and start the runner at first
# Testing outputs received by client and programmed outputs of runner server
#
import importlib
import os
import threading
import uuid
Expand All @@ -13,7 +14,6 @@

from clarifai.client import BaseClient, Model, User
from clarifai.client.auth.helper import ClarifaiAuthHelper
from clarifai.runners.models.model_builder import ModelBuilder
from clarifai.runners.models.model_runner import ModelRunner

MY_MODEL_PATH = os.path.join(os.path.dirname(__file__), "dummy_runner_models", "1", "model.py")
Expand All @@ -26,6 +26,14 @@
TEXT_URL = "https://samples.clarifai.com/negative_sentence_12.txt"


def _get_model_instance(model_path, model_name="MyModel"):
spec = importlib.util.spec_from_file_location(model_name, model_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
cls = getattr(module, model_name)
return cls()


def init_components(
auth: ClarifaiAuthHelper,
client: BaseClient,
Expand Down Expand Up @@ -150,7 +158,7 @@ def setup_class(cls):
pat=cls.AUTH.pat,
)

cls.runner_model = ModelBuilder(MY_MODEL_PATH).create_model_instance()
cls.runner_model = _get_model_instance(MY_MODEL_PATH)

cls.runner = ModelRunner(
model=cls.runner_model,
Expand Down Expand Up @@ -470,7 +478,7 @@ def setup_class(cls):
cls.COMPUTE_CLUSTER_ID,
)

cls.runner_model = ModelBuilder(MY_WRAPPER_MODEL_PATH).create_model_instance()
cls.runner_model = _get_model_instance(MY_WRAPPER_MODEL_PATH)

cls.runner = ModelRunner(
model=cls.runner_model,
Expand Down

0 comments on commit e851890

Please sign in to comment.