我将测试一个系统是否在多个平台上正确地读写文件(文本模式/二进制模式),至少在linux和windows上是这样。(使用pytest)。
请参阅https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
例如,可以使用pyfakefs模拟文件系统。但是,当在linux上运行测试时,我还没能找到一个mock来模拟在文本模式下打开的文件的windows行为。
是否可以在linux上以文本模式强制转换eol (\r\n到\n)?
发布于 2019-12-04 23:46:15
只是偶然发现了这个问题--虽然这是一个老问题,但也许答案会对其他人有所帮助……在pyfakefs中,你可以使用change your fake file system,例如(pytest中的例子):
def test_windows_stuff_under_linux(fs):
fs.is_windows_fs = True
file_path = 'C:/foo/bar/baz'
with open(file_path, 'w') as f:
f.write('Some content\n with newlines\n')
...https://stackoverflow.com/questions/56025090
复制相似问题