-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Labels
Milestone
Description
Description of issue
While runing tox on my system, a Mac running macOS Mojave 10.14.6 (18G95), I see that the unit test test_diagnostic_information fails.
bin/nifake/nifake/unit_tests/test_session.py::TestSession::test_buffer_converter PASSED
bin/nifake/nifake/unit_tests/test_session.py::test_diagnostic_information FAILED
bin/nifake/nifake/unit_tests/test_session.py::test_dunder_version Version = 1.1.3.dev0
PASSED
=========================================================================================== FAILURES ============================================================================================
__________________________________________________________________________________ test_diagnostic_information __________________________________________________________________________________
def test_diagnostic_information():
> info = nifake.print_diagnostic_information()
bin/nifake/nifake/unit_tests/test_session.py:1281:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bin/nifake/nifake/__init__.py:85: in print_diagnostic_information
info = get_diagnostic_information()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def get_diagnostic_information():
'''Get diagnostic information about the system state that is suitable for printing or logging
returns: dict
note: Python bitness may be incorrect when running in a virtual environment
'''
import os
import pkg_resources
import platform
import struct
import sys
def is_python_64bit():
return (struct.calcsize("P") == 8)
def is_os_64bit():
return platform.machine().endswith('64')
def is_venv():
return 'VIRTUAL_ENV' in os.environ
info = {}
info['os'] = {}
info['python'] = {}
info['driver'] = {}
info['module'] = {}
if platform.system() == 'Windows':
try:
import winreg as winreg
except ImportError:
import _winreg as winreg
os_name = 'Windows'
try:
driver_version_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\National Instruments\NI-FAKE\CurrentVersion")
driver_version = winreg.QueryValueEx(driver_version_key, "Version")[0]
except WindowsError:
driver_version = 'Unknown'
elif platform.system() == 'Linux':
os_name = 'Linux'
driver_version = 'Unknown'
else:
> raise SystemError('Unsupported platform: {}'.format(platform.system()))
E SystemError: Unsupported platform: Darwin
bin/nifake/nifake/__init__.py:60: SystemError
================================================================================= 1 failed, 127 passed in 9.13s =================================================================================
This reveals that this specific unit test is not mocking the code used to extract information. Specifically platform.system and winreg. This means that when the test runs on a Windows machine, one codepath is taken. When run on Linux a different one, and when run on Mac a different failing path is taken. This also affects code coverage.
The correct thing to do would be to mock those things and to improve the test for the Windows, Linux, other OS cases. This would verify we go through all the codepaths as we should.
Steps to reproduce issue
On a Mac terminal, pull master and then run
tox