From fdfb65862fbd3b8973f9ae3bdce53107a9064b70 Mon Sep 17 00:00:00 2001 From: Zsolt Kebel <25386639+zsoltkebel@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:20:08 +0000 Subject: [PATCH] Add unit tests for version check --- .../ibex_install_utils/tests/__init__.py | 0 .../tests/test_version_check.py | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 installation_and_upgrade/ibex_install_utils/tests/__init__.py create mode 100644 installation_and_upgrade/ibex_install_utils/tests/test_version_check.py diff --git a/installation_and_upgrade/ibex_install_utils/tests/__init__.py b/installation_and_upgrade/ibex_install_utils/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/installation_and_upgrade/ibex_install_utils/tests/test_version_check.py b/installation_and_upgrade/ibex_install_utils/tests/test_version_check.py new file mode 100644 index 00000000..96f5d73c --- /dev/null +++ b/installation_and_upgrade/ibex_install_utils/tests/test_version_check.py @@ -0,0 +1,45 @@ +import unittest +from ibex_install_utils.version_check import * + +class TestVersionCheck(unittest.TestCase): + + def test_get_major_minor_patch(self): + # good version patterns + self.assertEqual(get_major_minor_patch("17"), "17.0.0") + self.assertEqual(get_major_minor_patch("17.0"), "17.0.0") + self.assertEqual(get_major_minor_patch("17.23"), "17.23.0") + self.assertEqual(get_major_minor_patch("17.0.7.3"), "17.0.7") + self.assertEqual(get_major_minor_patch("17.0.0.3"), "17.0.0") + + # wrong version patterns + with self.assertRaises(AttributeError): + get_major_minor_patch("17.0.0.3.4") + + with self.assertRaises(AttributeError): + get_major_minor_patch("17.") + + with self.assertRaises(AttributeError): + get_major_minor_patch("java 17.2.4") + + def test_get_file_version(self): + example_file = "\\\\isis.cclrc.ac.uk\shares\ISIS_Experiment_Controls_Public\\third_party_installers\latest_versions\Git-2.38.1-64-bit.exe" + self.assertEqual(get_file_version(example_file), "2.38.1.1") + + def test_get_msi_property(self): + example_file = "\\\\isis.cclrc.ac.uk\shares\ISIS_Experiment_Controls_Public\\third_party_installers\latest_versions\OpenJDK17U-jdk_x64_windows_hotspot_17.0.4.1_1.msi" + version = get_msi_property(example_file, MSI_PRODUCT_VERSION_PROPERTY) + self.assertEqual(version, "17.0.4.101") + + # def test_isupper(self): + # self.assertTrue('FOO'.isupper()) + # self.assertFalse('Foo'.isupper()) + + # def test_split(self): + # s = 'hello world' + # self.assertEqual(s.split(), ['hello', 'world']) + # # check that s.split fails when the separator is not a string + # with self.assertRaises(TypeError): + # s.split(2) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file