Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
korgan00 committed Nov 28, 2024
1 parent bc13524 commit a449a96
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
11 changes: 4 additions & 7 deletions tests/basic/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_running_program(self, serverless_client: ServerlessClient):
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

def test_arguments_and_resluts(self, serverless_client: ServerlessClient):
def test_arguments(self, serverless_client: ServerlessClient):
"""Integration test for Functions."""
circuit = QuantumCircuit(2)
circuit.h(0)
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_distributed_workloads(self, serverless_client: ServerlessClient):
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

def test_retrieving_past_results(self, serverless_client: ServerlessClient):
def test_multiple_runs(self, serverless_client: ServerlessClient):
"""Integration test for Functions."""

circuits = [random_circuit(2, 2) for _ in range(3)]
Expand Down Expand Up @@ -182,11 +182,7 @@ def test_function(self, serverless_client: ServerlessClient):

my_functions = serverless_client.functions()

# ???
for function in my_functions:
print("Name: " + function.title)
print(function.description)
print()
assert len(my_functions)

my_function = serverless_client.function("custom-image-function")
job = my_function.run(message="Argument for the custum function")
Expand All @@ -195,6 +191,7 @@ def test_function(self, serverless_client: ServerlessClient):

with raises(QiskitServerlessException):
job.result()

assert isinstance(job.logs(), str)

jobs = my_function.jobs()
Expand Down
1 change: 1 addition & 0 deletions tests/experimental/source_files/hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello World!")
88 changes: 46 additions & 42 deletions tests/experimental/test_docker_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
os.path.dirname(os.path.abspath(__file__)), "./source_files"
)

filename = f"{resources_path}/data.tar"


class TestDockerExperimental:
"""Test class for integration testing with docker."""
Expand All @@ -33,41 +35,22 @@ def serverless_client(self):
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", connection_url),
)
yield serverless

compose.stop()

@mark.skip(reason="Speeding up testing with github jobs: delete before merge")
def test_file_download(self, serverless_client: ServerlessClient):
"""Integration test for files."""

# Initialize serverless folder for current user
function = QiskitFunction(
title="file-producer-for-download",
entrypoint="produce_files.py",
title="hello-world",
entrypoint="hello_world.py",
working_dir=resources_path,
)
serverless_client.upload(function)

function = serverless_client.function("file-producer-for-download")
job = function.run()
assert job is not None
serverless.upload(function)

assert job.result() is not None
assert job.status() == "DONE"
assert isinstance(job.logs(), str)

print("::: JOB LOGS :::")
print(job.logs())
print("::: JOB RESULT :::")
print(job.result())

available_files = serverless_client.files()
assert available_files is not None
assert len(available_files) > 0
yield serverless

assert serverless_client.file_download(available_files[0]) is not None
compose.stop()

@mark.skip(reason="Speeding up testing with github jobs: delete before merge")
@mark.skip(
reason="File producing and consuming is not working. Maybe write permissions for functions?"
)
@mark.order(1)
def test_file_producer(self, serverless_client: ServerlessClient):
"""Integration test for files."""
Expand Down Expand Up @@ -95,7 +78,9 @@ def test_file_producer(self, serverless_client: ServerlessClient):

assert len(serverless_client.files()) > 0

@mark.skip(reason="Speeding up testing with github jobs: delete before merge")
@mark.skip(
reason="File producing and consuming is not working. Maybe write permissions for functions?"
)
@mark.order(2)
def test_file_consumer(self, serverless_client: ServerlessClient):
"""Integration test for files."""
Expand Down Expand Up @@ -126,18 +111,10 @@ def test_file_consumer(self, serverless_client: ServerlessClient):

assert (file_count - len(serverless_client.files())) == 1

def test_simple(self, serverless_client: ServerlessClient):
@mark.order(1)
def test_upload(self, serverless_client: ServerlessClient):
"""Integration test for files."""

function = QiskitFunction(
title="file-consumer",
entrypoint="consume_files.py",
working_dir=resources_path,
)
serverless_client.upload(function)

filename = f"{resources_path}/data.tar"

print("::: file_upload :::")
print(serverless_client.file_upload(filename))

Expand All @@ -146,17 +123,44 @@ def test_simple(self, serverless_client: ServerlessClient):
print(files)

assert files is not None
assert len(files) > 0

file_count = len(files)
print("::: file_count :::")
print(file_count)

assert file_count > 0

@mark.order(2)
def test_download(self, serverless_client: ServerlessClient):
"""Integration test for files."""

files = serverless_client.files()
file_count = len(files)
print("::: files before download :::")
print(files)

print("::: file_download :::")
assert serverless_client.file_download(filename) is not None

files = serverless_client.files()
print("::: files after download :::")
print(files)

assert file_count == len(files)

@mark.order(3)
def test_delete(self, serverless_client: ServerlessClient):
files = serverless_client.files()
print("::: files before delete :::")
print(files)
file_count = len(files)

print("::: file_delete :::")
print(serverless_client.file_delete(filename))

print("::: files :::")
print(serverless_client.files())
print("::: files after delete:::")
files = serverless_client.files()
print(files)

assert (file_count - len(serverless_client.files())) == 1
assert (file_count - len(files)) == 1

0 comments on commit a449a96

Please sign in to comment.