You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pci.PCIDevices: Use Popen(lspci -mn, universal_newlines=True)
Fixes one part of #21 by calling Popen(lspci -nm, universal_newlines=True)
This makes Popen().stdout it return an __inter__: string, which the code
expects (otherwise, it opens the stdout pipe as binary stream):
From: https://docs.python.org/3.6/library/subprocess.html#popen-constructor:
"If encoding or errors are specified, the file objects stdin, stdout and stderr
are opened in text mode with the specified encoding and errors, as described
above in Frequently Used Arguments.
If universal_newlines is True, they are opened in text mode with default
encoding. >>>__Otherwise, they are opened as binary streams.__<<<"
The new test tests xcp.pci.PCIDevices() by setting PATH to a shell script which
simluates "lspci -mn" with "cat tests/data/lspci-mn", so calls the real Popen.
Final thoughts on using mock:
Mocking xcp.pci.subprocess.Popen.stdout using open("tests/data/lspci-mn")
does not model the actual behavior of subprocess.Popen().std* in Python3:
By it's nature, mocking Popen() does not validate it's correct use in xcp.pci
and therfore, it failed to detect the Python3 problem in `xcp/pci.py`
Correctly modeling subprocess.Popen() without really calling it is nontrivial,
and would require something like the testfixtures library and even that would
still be a mock and use the actual subprocess class. Mocking is better suited
when the test knows how an API must be called, which isn't the case here.
Signed-off-by: Bernhard Kaindl <[email protected]>
0 commit comments