Skip to content

Commit

Permalink
Add version method to backend, mirroring 'name', and add basic tests (Q…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcapelluto authored and taalexander committed Oct 2, 2019
1 parent 535c68a commit 7b5d8ce
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qiskit/providers/basebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def name(self):
"""
return self._configuration.backend_name

def version(self):
"""Return the backend version.
Returns:
str: the X.X.X version of the backend.
"""
return self._configuration.backend_version

def __str__(self):
return self.name()

Expand Down
45 changes: 45 additions & 0 deletions test/python/providers/test_base_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
#
# 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.

# pylint: disable=missing-docstring

"""Test BaseBackend methods."""

from qiskit.test import QiskitTestCase
from qiskit.test.mock import FakeOpenPulse2Q, FakeMelbourne


class TestBaseBackend(QiskitTestCase):
"""Test the backend methods."""

def setUp(self):
self.pulse_backend = FakeOpenPulse2Q()
self.backend = FakeMelbourne()

def test_name(self):
"""Test that name can be extracted."""
self.assertEqual(self.pulse_backend.name(), 'fake_openpulse_2q')
self.assertEqual(self.backend.name(), 'fake_melbourne')

def test_version(self):
"""Test that name can be extracted."""
self.assertEqual(self.pulse_backend.version(), '0.0.0')
self.assertEqual(self.backend.version(), '0.0.0')

def test_str_and_repr(self):
"""Test the custom __str__ and __repr__ methods."""
self.assertEqual(str(self.pulse_backend), 'fake_openpulse_2q')
self.assertEqual(str(self.backend), 'fake_melbourne')
self.assertEqual(repr(self.pulse_backend),
"<FakeOpenPulse2Q('fake_openpulse_2q') from None()>")

0 comments on commit 7b5d8ce

Please sign in to comment.