Skip to content

Commit

Permalink
winVersion.WinVersion: add unit test cases. Re nvaccess#11837.
Browse files Browse the repository at this point in the history
Add unit tests for the following:
* winVersion.getWinVer (compared against what Python returns through sys.getwindowsversion)
* Convert a string representation of a Windows release to WinVersion class instance
* See if a specific major.minor.build is returned for a given release
  • Loading branch information
josephsl committed Dec 7, 2020
1 parent 298dd3a commit e746b02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/winVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -81,6 +82,7 @@ def getWinVer():
servicePack=winVersion.service_pack
)


def getWinVerFromVersionText(versionText: str):
major, minor, build = versionText.split(".")
return WinVersion(
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_winVersion.py
Original file line number Diff line number Diff line change
@@ -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)
)

0 comments on commit e746b02

Please sign in to comment.