Skip to content

Commit

Permalink
add localclient to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
korgan00 committed Dec 10, 2024
1 parent edac72a commit 27ad061
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
19 changes: 18 additions & 1 deletion tests/docker/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@
from pytest import fixture
from testcontainers.compose import DockerCompose
from qiskit_serverless import ServerlessClient, QiskitFunction
from qiskit_serverless.core.clients.local_client import LocalClient

resources_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "source_files"
)


@fixture(scope="module", params=["serverless", "local"])
def any_client(request):
"""Fixture for testing files with every client."""
if request.param == "serverless":
yield serverless_client()
return serverless_client()

return local_client()


@fixture(scope="module")
def local_client():
"""Fixture for testing files with local client."""
return LocalClient()


@fixture(scope="module")
def serverless_client():
"""Fixture for testing files."""
"""Fixture for testing files with serverless client."""
compose = DockerCompose(
resources_path,
compose_file_name="../../../docker-compose-dev.yaml",
Expand Down
35 changes: 17 additions & 18 deletions tests/docker/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from qiskit import QuantumCircuit
from qiskit.circuit.random import random_circuit

from qiskit_serverless import ServerlessClient, QiskitFunction
from qiskit_serverless import QiskitFunction
from qiskit_serverless.core.client import BaseClient
from qiskit_serverless.exception import QiskitServerlessException


Expand All @@ -29,16 +30,14 @@ def simple_function(self):
)

@mark.order(1)
def test_simple_function(
self, serverless_client: ServerlessClient, simple_function: QiskitFunction
):
def test_simple_function(self, client: BaseClient, simple_function: QiskitFunction):
"""Integration test function uploading."""

runnable_function = serverless_client.upload(simple_function)
runnable_function = client.upload(simple_function)

assert runnable_function is not None

runnable_function = serverless_client.function(simple_function.title)
runnable_function = client.function(simple_function.title)

assert runnable_function is not None

Expand All @@ -49,7 +48,7 @@ def test_simple_function(
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

def test_function_with_arguments(self, serverless_client: ServerlessClient):
def test_function_with_arguments(self, client: BaseClient):
"""Integration test for Functions with arguments."""
circuit = QuantumCircuit(2)
circuit.h(0)
Expand All @@ -63,7 +62,7 @@ def test_function_with_arguments(self, serverless_client: ServerlessClient):
working_dir=resources_path,
)

runnable_function = serverless_client.upload(arguments_function)
runnable_function = client.upload(arguments_function)

job = runnable_function.run(circuit=circuit)

Expand All @@ -72,7 +71,7 @@ def test_function_with_arguments(self, serverless_client: ServerlessClient):
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

def test_dependencies_function(self, serverless_client: ServerlessClient):
def test_dependencies_function(self, client: BaseClient):
"""Integration test for Functions with dependencies."""
function = QiskitFunction(
title="pattern-with-dependencies",
Expand All @@ -81,7 +80,7 @@ def test_dependencies_function(self, serverless_client: ServerlessClient):
dependencies=["pendulum"],
)

runnable_function = serverless_client.upload(function)
runnable_function = client.upload(function)

job = runnable_function.run()

Expand All @@ -90,7 +89,7 @@ def test_dependencies_function(self, serverless_client: ServerlessClient):
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

def test_distributed_workloads(self, serverless_client: ServerlessClient):
def test_distributed_workloads(self, client: BaseClient):
"""Integration test for Functions for distributed workloads."""

circuits = [random_circuit(2, 2) for _ in range(3)]
Expand All @@ -102,7 +101,7 @@ def test_distributed_workloads(self, serverless_client: ServerlessClient):
entrypoint="pattern_with_parallel_workflow.py",
working_dir=resources_path,
)
runnable_function = serverless_client.upload(function)
runnable_function = client.upload(function)

job = runnable_function.run(circuits=circuits)

Expand All @@ -111,7 +110,7 @@ def test_distributed_workloads(self, serverless_client: ServerlessClient):
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

def test_multiple_runs(self, serverless_client: ServerlessClient):
def test_multiple_runs(self, client: BaseClient):
"""Integration test for run functions multiple times."""

circuits = [random_circuit(2, 2) for _ in range(3)]
Expand All @@ -123,7 +122,7 @@ def test_multiple_runs(self, serverless_client: ServerlessClient):
entrypoint="pattern.py",
working_dir=resources_path,
)
runnable_function = serverless_client.upload(function)
runnable_function = client.upload(function)

job1 = runnable_function.run()
job2 = runnable_function.run()
Expand All @@ -133,16 +132,16 @@ def test_multiple_runs(self, serverless_client: ServerlessClient):

assert job1.job_id != job2.job_id

retrieved_job1 = serverless_client.job(job1.job_id)
retrieved_job2 = serverless_client.job(job2.job_id)
retrieved_job1 = client.job(job1.job_id)
retrieved_job2 = client.job(job2.job_id)

assert retrieved_job1.result() is not None
assert retrieved_job2.result() is not None

assert isinstance(retrieved_job1.logs(), str)
assert isinstance(retrieved_job2.logs(), str)

def test_error(self, serverless_client: ServerlessClient):
def test_error(self, client: BaseClient):
"""Integration test to force an error."""

description = """
Expand All @@ -161,7 +160,7 @@ def test_error(self, serverless_client: ServerlessClient):
description=description,
)

runnable_function = serverless_client.upload(function_with_custom_image)
runnable_function = client.upload(function_with_custom_image)

job = runnable_function.run(message="Argument for the custum function")

Expand Down

0 comments on commit 27ad061

Please sign in to comment.