This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New test file for session in unit test
- Loading branch information
1 parent
766c36e
commit 79607f8
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
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,55 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021. | ||
# | ||
# 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 | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""IBMBackend Test.""" | ||
|
||
from qiskit import QuantumCircuit | ||
from qiskit.test.reference_circuits import ReferenceCircuits | ||
|
||
from qiskit_ibm_provider import IBMProvider | ||
from qiskit_ibm_provider.session import Session | ||
from qiskit_ibm_provider.exceptions import IBMInputValueError | ||
|
||
from ..ibm_test_case import IBMTestCase | ||
|
||
|
||
class TestSession(IBMTestCase): | ||
"""Test Session module.""" | ||
|
||
def test_provider_and_no_backend(self): | ||
"""Test missing backend.""" | ||
circ = ReferenceCircuits.bell() | ||
backend = "ibmq_qasm_simulator" | ||
session = Session() | ||
provider = IBMProvider(session=session) | ||
_ = provider.backends(name=backend)[0] | ||
self.assertTrue(session.backend() is None) | ||
self.assertEqual(provider._session, session) | ||
|
||
def test_passing_ibm_backend(self): | ||
"""Test passing in IBMBackend instance.""" | ||
backend_name = "ibm_gotham" | ||
session = Session(backend_name=backend_name) | ||
self.assertEqual(session.backend(), "ibm_gotham") | ||
|
||
def test_max_time(self): | ||
"""Test max time.""" | ||
max_times = [ | ||
(42, 42), | ||
("1h", 1 * 60 * 60), | ||
("2h 30m 40s", 2 * 60 * 60 + 30 * 60 + 40), | ||
("40s 1h", 40 + 1 * 60 * 60), | ||
] | ||
for max_t, expected in max_times: | ||
with self.subTest(max_time=max_t): | ||
session = Session(backend_name="ibm_gotham", max_time=max_t) | ||
self.assertEqual(session._max_time, expected) |