Skip to content

Commit

Permalink
Merge 7a5c37f into 0cb1c16
Browse files Browse the repository at this point in the history
  • Loading branch information
daka1510 committed Mar 4, 2022
2 parents 0cb1c16 + 7a5c37f commit cc0bde9
Show file tree
Hide file tree
Showing 29 changed files with 211 additions and 238 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,8 @@ jobs:
python-version: [ 3.7, 3.8, 3.9 ]
os: [ "macOS-latest", "ubuntu-latest", "windows-latest" ]
env:
QISKIT_IBM_API_TOKEN: ${{ secrets.QISKIT_IBM_API_TOKEN }}
QISKIT_IBM_API_URL: ${{ secrets.QISKIT_IBM_API_URL }}
QISKIT_IBM_HGP: ${{ secrets.QISKIT_IBM_HGP }}
QISKIT_IBM_PRIVATE_HGP: ${{ secrets.QISKIT_IBM_PRIVATE_HGP }}
LOG_LEVEL: DEBUG
STREAM_LOG: True
QISKIT_TESTS: skip_online
QISKIT_IN_PARALLEL: True
steps:
- uses: actions/checkout@v2
Expand All @@ -96,7 +91,7 @@ jobs:
pip install -c constraints.txt -e .
pip install -U -c constraints.txt -r requirements-dev.txt
- name: Run unit tests
run: make test-coverage
run: make unit-test-coverage
- name: Report coverage to coveralls.io
uses: coverallsapp/github-action@1.1.3
with:
Expand Down Expand Up @@ -136,7 +131,7 @@ jobs:
pip install -c constraints.txt -e .
pip install -U -c constraints.txt -r requirements-dev.txt
- name: Run Tests
run: make test
run: make integration-test
tests-finished:
name: Submit code coverage metrics
needs: [ unit-tests ]
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/cron-prod.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/cron-slow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
pip install -c constraints.txt -e .
pip install -U -c constraints.txt -r requirements-dev.txt
- name: Run Tests
run: make test
run: make integration-test
terra-main:
name: terra-main
runs-on: macOS-latest
Expand All @@ -66,4 +66,4 @@ jobs:
pip install -U git+https://github.com/Qiskit/qiskit-terra.git
pip install -U git+https://github.com/Qiskit/qiskit-aer.git
- name: Run Tests
run: make test
run: make integration-test
41 changes: 0 additions & 41 deletions .github/workflows/cron-staging.yml

This file was deleted.

20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ mypy:

style:
black --check qiskit_ibm_provider test setup.py docs/tutorials
test:
python -m unittest -v

test-coverage:
coverage run -m unittest -v
unit-test:
python -m unittest discover --verbose --top-level-directory . --start-directory test/unit

unit-test-coverage:
coverage run -m unittest discover --verbose --top-level-directory . --start-directory test/unit
coverage lcov

integration-test:
python -m unittest discover --verbose --top-level-directory . --start-directory test/integration

test1:
python -m unittest -v test/ibm/test_ibm_backend.py test/ibm/test_account_client.py test/ibm/test_ibm_job_states.py test/ibm/test_tutorials.py test/ibm/test_basic_server_paths.py test/ibm/test_proxies.py test/ibm/test_ibm_integration.py test/ibm/test_ibm_logger.py test/ibm/test_filter_backends.py test/ibm/test_registration.py
python -m unittest -v test/integration/test_ibm_backend.py test/integration/test_account_client.py test/integration/test_ibm_job_states.py test/integration/test_tutorials.py test/integration/test_basic_server_paths.py test/integration/test_proxies.py test/integration/test_ibm_integration.py test/integration/test_ibm_logger.py test/integration/test_filter_backends.py test/integration/test_registration.py

test2:
python -m unittest -v test/ibm/test_ibm_qasm_simulator.py test/ibm/test_serialization.py test/ibm/test_jupyter.py test/ibm/test_composite_job.py test/ibm/test_ibm_provider.py
python -m unittest -v test/integration/test_ibm_qasm_simulator.py test/integration/test_serialization.py test/integration/test_jupyter.py test/integration/test_composite_job.py test/integration/test_ibm_provider.py

test3:
python -m unittest -v test/ibm/test_ibm_job_attributes.py test/ibm/test_ibm_job.py test/ibm/websocket/test_websocket.py test/ibm/websocket/test_websocket_integration.py
python -m unittest -v test/integration/test_ibm_job_attributes.py test/integration/test_ibm_job.py test/integration/websocket/test_websocket.py test/integration/websocket/test_websocket_integration.py

runtime_integration:
python -m unittest -v test/ibm/runtime/test_runtime_integration.py

black:
black qiskit_ibm_provider test setup.py docs/tutorials
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Websocket related tests."""
"""Integration tests."""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""Tests for the IBMProvider class."""

import os
from configparser import ConfigParser
from datetime import datetime
from unittest import skipIf, mock

Expand All @@ -30,10 +29,6 @@
from qiskit_ibm_provider.credentials.hub_group_project_id import HubGroupProjectID
from qiskit_ibm_provider.exceptions import (
IBMProviderError,
IBMProviderValueError,
IBMProviderCredentialsInvalidUrl,
IBMProviderCredentialsInvalidToken,
IBMProviderCredentialsNotFound,
)
from qiskit_ibm_provider.ibm_backend import IBMSimulator, IBMBackend
from qiskit_ibm_provider.ibm_backend_service import IBMBackendService
Expand Down Expand Up @@ -73,37 +68,6 @@ def test_pass_unreachable_proxy(self, qe_token, qe_url):
IBMProvider(qe_token, qe_url, proxies=proxies)
self.assertIn("ProxyError", str(context_manager.exception))

def test_provider_init_non_auth_url(self):
"""Test initializing IBMProvider with a non-auth URL."""
qe_token = "invalid"
qe_url = API_URL

with self.assertRaises(IBMProviderCredentialsInvalidUrl) as context_manager:
IBMProvider(token=qe_token, url=qe_url)

self.assertIn("authentication URL", str(context_manager.exception))

def test_provider_init_non_auth_url_with_hub(self):
"""Test initializing IBMProvider with a non-auth URL containing h/g/p."""
qe_token = "invalid"
qe_url = API_URL + "/Hubs/X/Groups/Y/Projects/Z"

with self.assertRaises(IBMProviderCredentialsInvalidUrl) as context_manager:
IBMProvider(token=qe_token, url=qe_url)

self.assertIn("authentication URL", str(context_manager.exception))

def test_provider_init_no_credentials(self):
"""Test initializing IBMProvider with no credentials."""
with custom_qiskitrc(), self.assertRaises(
IBMProviderCredentialsNotFound
) as context_manager, no_envs(CREDENTIAL_ENV_VARS):
IBMProvider()

self.assertIn(
"No IBM Quantum credentials found.", str(context_manager.exception)
)

@requires_qe_access
def test_discover_backend_failed(self, qe_token, qe_url):
"""Test discovering backends failed."""
Expand All @@ -129,15 +93,6 @@ def setUpClass(cls):
super().setUpClass()
cls.token = "API_TOKEN"

def test_save_account(self):
"""Test saving an account."""
with custom_qiskitrc():
IBMProvider.save_account(self.token, url=QISKIT_IBM_API_URL)
stored_cred = IBMProvider.saved_account()

self.assertEqual(stored_cred["token"], self.token)
self.assertEqual(stored_cred["url"], QISKIT_IBM_API_URL)

@requires_qe_access
def test_provider_init_saved_account(self, qe_token, qe_url):
"""Test initializing IBMProvider with credentials from qiskitrc file."""
Expand All @@ -153,61 +108,6 @@ def test_provider_init_saved_account(self, qe_token, qe_url):
self.assertEqual(provider.backend._default_hgp.credentials.token, qe_token)
self.assertEqual(provider.backend._default_hgp.credentials.auth_url, qe_url)

def test_save_account_specified_provider(self):
"""Test saving an account with a specified hub/group/project."""
default_hgp_to_save = "ibm-q/open/main"

with custom_qiskitrc() as custom_qiskitrc_cm:
hgp_id = HubGroupProjectID.from_stored_format(default_hgp_to_save)
IBMProvider.save_account(
token=self.token,
url=QISKIT_IBM_API_URL,
hub=hgp_id.hub,
group=hgp_id.group,
project=hgp_id.project,
)

# Ensure the `default_provider` name was written to the config file.
config_parser = ConfigParser()
config_parser.read(custom_qiskitrc_cm.tmp_file.name)

for name in config_parser.sections():
single_credentials = dict(config_parser.items(name))
self.assertIn("default_provider", single_credentials)
self.assertEqual(
single_credentials["default_provider"], default_hgp_to_save
)

def test_save_account_specified_provider_invalid(self):
"""Test saving an account without specifying all the hub/group/project fields."""
invalid_hgp_ids_to_save = [
HubGroupProjectID("", "default_group", ""),
HubGroupProjectID("default_hub", None, "default_project"),
]
for invalid_hgp_id in invalid_hgp_ids_to_save:
with self.subTest(invalid_hgp_id=invalid_hgp_id), custom_qiskitrc():
with self.assertRaises(IBMProviderValueError) as context_manager:
IBMProvider.save_account(
token=self.token,
url=QISKIT_IBM_API_URL,
hub=invalid_hgp_id.hub,
group=invalid_hgp_id.group,
project=invalid_hgp_id.project,
)
self.assertIn(
"The hub, group, and project parameters must all be specified",
str(context_manager.exception),
)

def test_delete_account(self):
"""Test deleting an account."""
with custom_qiskitrc():
IBMProvider.save_account(self.token, url=QISKIT_IBM_API_URL)
IBMProvider.delete_account()
stored_cred = IBMProvider.saved_account()

self.assertEqual(len(stored_cred), 0)

@requires_qe_access
def test_load_account_saved_provider(self, qe_token, qe_url):
"""Test loading an account that contains a saved hub/group/project."""
Expand Down Expand Up @@ -283,30 +183,6 @@ def test_load_saved_account_invalid_hgp(self, qe_token, qe_url):
str(context_manager.exception),
)

def test_load_saved_account_invalid_hgp_format(self):
"""Test loading an account that contains a saved provider in an invalid format."""
# Format {'test_case_input': 'error message from raised exception'}
invalid_hgps = {
"hub_group_project": 'Use the "<hub_name>/<group_name>/<project_name>" format',
"default_hub//default_project": "Every field must be specified",
"default_hub/default_group/": "Every field must be specified",
}

for invalid_hgp, error_message in invalid_hgps.items():
with self.subTest(invalid_hgp=invalid_hgp):
with custom_qiskitrc() as temp_qiskitrc, no_envs(CREDENTIAL_ENV_VARS):
# Save the account.
IBMProvider.save_account(token=self.token, url=QISKIT_IBM_API_URL)
# Add an invalid provider field to the account stored.
with open(
temp_qiskitrc.tmp_file.name, "a", encoding="utf-8"
) as _file:
_file.write("default_provider = {}".format(invalid_hgp))
# Ensure an error is raised if the stored provider is in an invalid format.
with self.assertRaises(IBMProviderError) as context_manager:
IBMProvider()
self.assertIn(error_message, str(context_manager.exception))

@requires_qe_access
def test_active_account(self, qe_token, qe_url):
"""Test get active account"""
Expand All @@ -316,21 +192,6 @@ def test_active_account(self, qe_token, qe_url):
self.assertEqual(active_account["token"], qe_token)
self.assertEqual(active_account["url"], qe_url)

def test_save_token_invalid(self):
"""Test saving an account with invalid tokens. See #391."""
invalid_tokens = [None, "", 0]
for invalid_token in invalid_tokens:
with self.subTest(invalid_token=invalid_token):
with self.assertRaises(
IBMProviderCredentialsInvalidToken
) as context_manager:
IBMProvider.save_account(
token=invalid_token, url=QISKIT_IBM_API_URL
)
self.assertIn(
"Invalid IBM Quantum token found", str(context_manager.exception)
)


class TestIBMProviderHubGroupProject(IBMTestCase):
"""Tests for IBMProvider HubGroupProject related methods."""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from qiskit.test.reference_circuits import ReferenceCircuits

from qiskit_ibm_provider.api.clients import AccountClient, websocket
from ...decorators import requires_provider, requires_device
from ...ibm_test_case import IBMTestCase
from ...proxy_server import MockProxyServer, use_proxies
from ...utils import most_busy_backend, cancel_job
from ..decorators import requires_provider, requires_device
from ..ibm_test_case import IBMTestCase
from ..proxy_server import MockProxyServer, use_proxies
from ..utils import most_busy_backend, cancel_job


class TestWebsocketIntegration(IBMTestCase):
Expand Down
4 changes: 2 additions & 2 deletions test/ibm/__init__.py → test/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -10,4 +10,4 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Tests for IBM Quantum Provider."""
"""Unit tests."""
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit cc0bde9

Please sign in to comment.