test_diagnostic_information is deficient
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 128
- Forks
- 110
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 10
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with bin/nifake/nifake/unit_tests/test_session.py::test_diagnostic_information and the get_diagnostic_information implementation in bin/nifake/nifake/init.py. Run the test under tox, then cover the Windows, Linux, and other-OS branches by mocking platform.system and winreg. Done means the diagnostic test is platform-independent and exercises all relevant code paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100