-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* integration tests with pytest * integration tests with pytest * change action name * added lint and black * remove test_docker from other tests * add build containers * split ServerlessClient import * fix integration tests action * fix docker tests * black formatted * fix docker tests * fix tests * experimental tests * fix test experimental * remove unused imports * fix experimental tests * black * fix test docker * fix file add * fix tests * fix file open * format * add logs * add logs * modify experimental file download * fix format * new simple test * skip tests * format * change filename * upload a function before file * modify tests * fix lint * modified tests * remove skip * fix tests * fix lint * modify tests and create a new folder * fix scripts * fix tests * include docker tests * merge tests * restore file_download file * ignore downloaded file in tests * delete docker build action
- Loading branch information
Showing
29 changed files
with
596 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Integration tests | ||
|
||
on: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
verify-integration: | ||
name: lint, test | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false # keep running if one leg fails | ||
matrix: | ||
python-version: | ||
- '3.11' | ||
|
||
defaults: | ||
run: | ||
working-directory: ./tests | ||
|
||
steps: | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #4.1.7 | ||
- name: Build the containers | ||
run: docker compose -f ../docker-compose-dev.yaml build | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Set up tox environment | ||
run: | | ||
pver=${{ matrix.python-version }} | ||
tox_env="-epy${pver/./}" | ||
echo tox_env | ||
echo TOX_ENV=$tox_env >> $GITHUB_ENV | ||
- name: Install tox | ||
run: | | ||
pip install tox==4.16.0 | ||
- name: Run styles check | ||
run: tox -elint | ||
|
||
- name: Test using tox environment | ||
run: | | ||
tox ${{ env.TOX_ENV }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ nosetests.xml | |
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
tests/**/downloaded_*.tar | ||
|
||
# pyenv | ||
.python-version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# pylint: disable=import-error, invalid-name | ||
""" Fixtures for tests """ | ||
import os | ||
|
||
from pytest import fixture | ||
from testcontainers.compose import DockerCompose | ||
from qiskit_serverless import ServerlessClient, QiskitFunction | ||
|
||
resources_path = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), "source_files" | ||
) | ||
|
||
|
||
@fixture(scope="module") | ||
def serverless_client(): | ||
"""Fixture for testing files.""" | ||
compose = DockerCompose( | ||
resources_path, | ||
compose_file_name="../../../docker-compose-dev.yaml", | ||
pull=True, | ||
) | ||
compose.start() | ||
|
||
connection_url = "http://localhost:8000" | ||
compose.wait_for(f"{connection_url}/backoffice") | ||
|
||
serverless = ServerlessClient( | ||
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"), | ||
host=os.environ.get("GATEWAY_HOST", connection_url), | ||
) | ||
|
||
# Initialize serverless folder for current user | ||
function = QiskitFunction( | ||
title="hello-world", | ||
entrypoint="hello_world.py", | ||
working_dir=resources_path, | ||
) | ||
serverless.upload(function) | ||
|
||
yield serverless | ||
|
||
compose.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from qiskit import QuantumCircuit | ||
|
||
|
||
def create_hello_world_circuit() -> QuantumCircuit: | ||
circuit = QuantumCircuit(2) | ||
circuit.h(0) | ||
circuit.cx(0, 1) | ||
circuit.measure_all() | ||
return circuit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
import tarfile | ||
from qiskit_serverless import save_result | ||
|
||
with tarfile.open("/data/my_file.tar", "r:gz") as tar: | ||
with tar.extractfile("./my_file.txt") as f: | ||
text = f.read() | ||
|
||
print(text) | ||
save_result({"Message": str(text)}) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("Hello World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from qiskit import QuantumCircuit | ||
from qiskit.primitives import StatevectorSampler as Sampler | ||
|
||
from qiskit_serverless import save_result | ||
|
||
# all print statement will be available in job logs | ||
print("Running pattern...") | ||
|
||
# creating circuit | ||
circuit = QuantumCircuit(2) | ||
circuit.h(0) | ||
circuit.cx(0, 1) | ||
circuit.measure_all() | ||
|
||
# running Sampler primitive | ||
sampler = Sampler() | ||
quasi_dists = sampler.run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
# saves results of program execution, | ||
# which will be accessible by calling `.result()` | ||
save_result(quasi_dists) | ||
print("Completed running pattern.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# source_files/program_3.py | ||
|
||
from qiskit_serverless import get_arguments, save_result | ||
|
||
from qiskit.primitives import StatevectorSampler as Sampler | ||
|
||
# get all arguments passed to this program | ||
arguments = get_arguments() | ||
|
||
# get specific argument that we are interested in | ||
circuit = arguments.get("circuit") | ||
|
||
sampler = Sampler() | ||
|
||
quasi_dists = sampler.run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
print(f"Quasi distribution: {quasi_dists}") | ||
|
||
# saving results of a program | ||
save_result({"quasi_dists": quasi_dists}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# source_files/program_4.py | ||
|
||
from qiskit_serverless import save_result | ||
|
||
import pendulum | ||
|
||
dt_toronto = pendulum.datetime(2012, 1, 1, tz="America/Toronto") | ||
dt_vancouver = pendulum.datetime(2012, 1, 1, tz="America/Vancouver") | ||
|
||
diff = dt_vancouver.diff(dt_toronto).in_hours() | ||
|
||
print(diff) | ||
save_result({"hours": diff}) |
Oops, something went wrong.