Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests to client #9

Merged
merged 34 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ad988b1
add pre commit hooks
marcorossi5 Dec 11, 2023
867b98a
add dev pytest and coverage ti dev dependencies
marcorossi5 Dec 11, 2023
1698ad4
client initialization unit tests
marcorossi5 Dec 12, 2023
2c3b674
client with invalid token circuit post test
marcorossi5 Dec 12, 2023
e887d1e
test post circuit
marcorossi5 Dec 13, 2023
6c558a6
test StreamingHttpResponse related function
marcorossi5 Dec 13, 2023
89dc8b5
improve coverage to 97%
marcorossi5 Dec 14, 2023
d2426c9
complete tiiprovider test coverage
marcorossi5 Dec 14, 2023
4e50501
remove double lines
marcorossi5 Dec 14, 2023
1020618
add tests workflows
marcorossi5 Dec 14, 2023
0687e93
modify workflow to use poetry
marcorossi5 Dec 14, 2023
6a411a8
fix target python version
marcorossi5 Dec 14, 2023
c3ac8bc
update poetry lock
marcorossi5 Dec 14, 2023
8578a7a
test commands in workflow
marcorossi5 Dec 14, 2023
8b4aa9b
use poetry to run pytest
marcorossi5 Dec 14, 2023
ef72aea
do not test on windows
marcorossi5 Dec 14, 2023
13774dd
publish to pypi workflow
marcorossi5 Dec 14, 2023
bb482f5
remove unuseful name
marcorossi5 Dec 14, 2023
af2554d
add requests timeouts and do some linting
marcorossi5 Dec 14, 2023
0712d5e
conform to qibo workflow policies
marcorossi5 Dec 14, 2023
8a84bdb
remove unused import
marcorossi5 Dec 14, 2023
a6b9b0a
fix poe test task command
marcorossi5 Dec 14, 2023
0ddb793
fix workflow poetry extra groups
marcorossi5 Dec 14, 2023
788ff23
reduce matrix
marcorossi5 Dec 14, 2023
5ccfd8f
fix poetry group called in workflow
marcorossi5 Dec 14, 2023
b849d13
add pylint to venv
marcorossi5 Dec 14, 2023
8857ec1
do not build docs in CI CD
marcorossi5 Dec 14, 2023
b5d68c9
test on more python versions
marcorossi5 Dec 15, 2023
06f91d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2023
06c53ae
rename ttiq_provider -> tii_qrc_provider
marcorossi5 Dec 15, 2023
4987e0c
tiiq_provider -> tii_qrc_provider
marcorossi5 Dec 15, 2023
40c500d
add newlines
marcorossi5 Dec 15, 2023
a7f0054
Merge remote-tracking branch 'origin/add_tests_first_impl' into add_t…
marcorossi5 Dec 15, 2023
ad4224d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A single CI script with github workflow
name: Build wheels and deploy

on:
workflow_dispatch:
push:
merge_group:
release:
types:
- published

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9, '3.10', '3.11']
uses: qiboteam/workflows/.github/workflows/deploy-pip-poetry.yml@main
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
publish: ${{ github.event_name == 'release' && github.event.action == 'published' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
poetry-extras: "--with dev"
secrets: inherit
22 changes: 22 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Tests

on:
workflow_dispatch:
push:
merge_group:
pull_request:
types: [labeled]

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'run-workflow') || github.event_name == 'push'
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9, '3.10', '3.11']
uses: qiboteam/workflows/.github/workflows/rules-poetry.yml@main
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
poetry-extras: "--with dev"
secrets: inherit
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ci:
autofix_prs: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: [--config=pyproject.toml]
3 changes: 2 additions & 1 deletion examples/run_error_job.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import qibo

from qibo_tii_provider import TiiProvider

# create the circuit you want to run
circuit = qibo.models.QFT(11)

# read the token from file
with open("token.txt", "r") as f:
with open("token.txt") as f:
token = f.read()

# authenticate to server through the client instance
Expand Down
3 changes: 2 additions & 1 deletion examples/run_successful_job.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import qibo

from qibo_tii_provider import TIIProvider

# create the circuit you want to run
circuit = qibo.models.QFT(5)

# read the token from file
with open("token.txt", "r") as f:
with open("token.txt") as f:
token = f.read()

# authenticate to server through the client instance
Expand Down
270 changes: 268 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ packages = [{ include = "qibo_tii_provider", from = "src" }]
python = ">=3.8,<3.12"
qibo = ">=0.2.2"
requests = "^2.31.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
pylint = "^3.0.3"

[tool.poe.tasks]
test = "pytest"
lint = "pylint --errors-only src"
lint-warnings = "pylint --exit-zero src"

[tool.pylint.reports]
output-format = "colorized"

[tool.pytest.ini_options]
testpaths = ['tests/']
filterwarnings = ['ignore::RuntimeWarning']
addopts = [
'--cov=src/qibo_tii_provider',
'--cov-report=xml',
'--cov-report=html',
]
1 change: 1 addition & 0 deletions src/qibo_tii_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""The `qibo_tii_provider` package"""
from qibo_tii_provider.tiiprovider import TIIProvider
23 changes: 23 additions & 0 deletions src/qibo_tii_provider/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""This module implements some constants and custom exceptions"""


class MalformedResponseError(Exception):
"""Exception raised when server responsed body does not contain expected keys"""

def __init__(
self, message="Server response body does not contain all the expected keys"
):
self.message = message
super().__init__(self.message)


class JobPostServerError(Exception):
"""Exception raised when server fails to post the job to the queue.

The client should handle such error to aknowledge that job submission was
not successful without crashing.
"""

def __init__(self, message="Server failed to post job to queue"):
self.message = message
super().__init__(self.message)
Loading