From fc9a0bc074b86c23deb40039b8980727f022eeb7 Mon Sep 17 00:00:00 2001 From: cdelnano <79946944+cdelnano@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:10:32 -0400 Subject: [PATCH] 856 toolbox metal test cases (#859) * 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> --- qiskit_metal/tests/test_toolbox_metal.py | 49 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/qiskit_metal/tests/test_toolbox_metal.py b/qiskit_metal/tests/test_toolbox_metal.py index ec6368584..63b80ab49 100644 --- a/qiskit_metal/tests/test_toolbox_metal.py +++ b/qiskit_metal/tests/test_toolbox_metal.py @@ -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 @@ -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.""" @@ -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.""" @@ -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) @@ -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)