diff --git a/source/winVersion.py b/source/winVersion.py index 6e9588e4ef6..04182eef812 100644 --- a/source/winVersion.py +++ b/source/winVersion.py @@ -16,6 +16,7 @@ winVersionText+=".%d"%winVersion.service_pack_minor winVersionText+=" %s" % ("workstation","domain controller","server")[winVersion.product_type-1] + @functools.total_ordering class WinVersion(object): """ @@ -81,6 +82,7 @@ def getWinVer(): servicePack=winVersion.service_pack ) + def getWinVerFromVersionText(versionText: str): major, minor, build = versionText.split(".") return WinVersion( diff --git a/tests/unit/test_winVersion.py b/tests/unit/test_winVersion.py new file mode 100644 index 00000000000..9c0b76b7100 --- /dev/null +++ b/tests/unit/test_winVersion.py @@ -0,0 +1,37 @@ +#A part of NonVisual Desktop Access (NVDA) +#This file is covered by the GNU General Public License. +#See the file COPYING for more details. +#Copyright (C) 2020 NV Access Limited, Joseph Lee + +"""Unit tests for the Windows version module.""" + +import unittest +import sys +import winVersion + +class TestWinVersion(unittest.TestCase): + + def test_getWinVer(self): + # Test a 3-tuple consisting of version major, minor, build. + # sys.getwindowsversion() internally returns a named tuple, so comparing tuples is possible. + currentWinVer = winVersion.getWinVer() + winVerPython = sys.getwindowsversion() + self.assertTupleEqual( + (currentWinVer.major, currentWinVer.minor, currentWinVer.build), + winVerPython[:3] + ) + + def test_specificWinVer(self): + # Try detecting Windows 8.1 or later. + win81 = winVersion.WinVersion(release="8.1") + self.assertTupleEqual( + (win81.major, win81.minor, win81.build), + (6, 3, 9600) + ) + + def test_getWinVerFromVersionText(self): + winTenInitial = winVersion.getWinVerFromVersionText("10.0.10240") + self.assertTupleEqual( + (winTenInitial.major, winTenInitial.minor, winTenInitial.build), + (10, 0, 10240) + )