Skip to content

Commit

Permalink
856 toolbox metal test cases (#859)
Browse files Browse the repository at this point in the history
* Added unit test for aligned_pts function.

* Created test to verify that that open_docs in about.py opens qiskit_metal documentation in HTML without any errors.

* Fixed typo in fail print out of test_toolbox_metal_open_docs(). Added unit test to check that orient_me in about.py prints without errors.

* Fixed wording in description of test_toolbox_metal_orient_me(). Added test get_platform_info in about.py. Which returns a string with the platform information if no errors are present.

* Added unit test to instantiate InputError from exceptions.py. Fixed mispelling of exception in test_toolbox_metal_instantiation_qlibrary_gui_exception().

* Added unit test for extract_value_unit in parsing.py

* Modified test_toolbox_metal_extract_value_unit per Thomas's feedback on my original PR.

Co-authored-by: Priti Ashvin Shah <74020801+priti-ashvin-shah-ibm@users.noreply.github.com>
  • Loading branch information
cdelnano and priti-ashvin-shah-ibm authored Oct 13, 2022
1 parent db66978 commit fc9a0bc
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion qiskit_metal/tests/test_toolbox_metal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@

import unittest
import numpy as np
from typing import Union

from qiskit_metal.toolbox_metal import about
from qiskit_metal.toolbox_metal import parsing
from qiskit_metal.toolbox_metal import math_and_overrides
from qiskit_metal.toolbox_metal.bounds_for_path_and_poly_tables import BoundsForPathAndPolyTables
from qiskit_metal.toolbox_metal.exceptions import QiskitMetalExceptions
from qiskit_metal.toolbox_metal.exceptions import QiskitMetalDesignError
from qiskit_metal.toolbox_metal.exceptions import IncorrectQtException
from qiskit_metal.toolbox_metal.exceptions import QLibraryGUIException
from qiskit_metal.toolbox_metal.exceptions import InputError
from qiskit_metal.tests.assertions import AssertionsMixin


Expand Down Expand Up @@ -63,13 +66,20 @@ def test_toolbox_metal_instantiation_incorrect_qt_exception(self):
except Exception:
self.fail("IncorrectQtException failed.")

def test_toolbox_metal_instantiation_qlibrary_gui__excpetion(self):
def test_toolbox_metal_instantiation_qlibrary_gui_exception(self):
"""Test instantiation of QLibraryGUIException."""
try:
QLibraryGUIException("test message")
except Exception:
self.fail("QLibraryGUIException failed.")

def test_toolbox_metal_instantiation_input_error(self):
"""Test instantiation of InputError."""
try:
InputError("test message")
except Exception:
self.fail("InputError failed.")

def test_toolbox_metal_about(self):
"""Test that about in about.py produces about text without any
errors."""
Expand All @@ -78,6 +88,33 @@ def test_toolbox_metal_about(self):
except Exception:
self.fail("about() failed")

def test_toolbox_metal_open_docs(self):
"""Test that open_docs in about.py opens qiskit_metal documentation in HTML without any
errors."""
try:
about.open_docs()
except Exception:
self.fail("open_docs() failed")

def test_toolbox_metal_orient_me(self):
"""Test that orient_me in about.py produces detailed information about the user without any
errors."""
try:
about.orient_me(True)
except Exception:
self.fail("orient_me() failed")
try:
about.orient_me(False)
except Exception:
self.fail("orient_me() failed")

def test_toolbox_metal_get_platform_info(self):
"""Test that get_platform_info in about.py returns a string with the platform information without any errors."""
try:
return about.get_platform_info()
except Exception:
self.fail("get_platform_info() failed")

# pylint: disable-msg=unused-variable
def test_toolbox_metal_parsing_true_str(self):
"""Test that TRUE_STR in parsing.py has not accidentally changed."""
Expand Down Expand Up @@ -256,6 +293,11 @@ def test_toolbox_metal_parse_options(self):
expected[x][i],
rel_tol=1e-3)

def test_toolbox_metal_extract_value_unit(self):
"""Test functionality of extract_value_unit in toolbox_metal.py."""
self.assertEqual(parsing.extract_value_unit("200mm", "mm"), 200.0)
self.assertEqual(parsing.extract_value_unit("20.5", "units"), 20.5)

def test_toolbox_metal_set_decimal_precision(self):
"""Test functionality of set_decimal_precision in toolbox_metal.py."""
self.assertEqual(math_and_overrides.DECIMAL_PRECISION, 10)
Expand All @@ -281,6 +323,11 @@ def test_toolbox_metal_cross(self):
my_array_2 = np.array([12, 14])
self.assertEqual(math_and_overrides.cross(my_array_1, my_array_2), -6)

def test_toolbox_metal_aligned_pts(self):
# """Test functionality of aligned_pts in toolbox_metal.py."""
self.assertTrue(math_and_overrides.aligned_pts([0, 1, 2]))
self.assertFalse(math_and_overrides.aligned_pts([7, 1, 2]))


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit fc9a0bc

Please sign in to comment.