Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
New test file for session in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
merav-aharoni committed Jul 23, 2023
1 parent 766c36e commit 79607f8
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/unit/test_session.py
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)

0 comments on commit 79607f8

Please sign in to comment.