FileContains does not support binary files
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
testtools |
Triaged
|
Wishlist
|
Unassigned |
Bug Description
The code in FileContains.
f = open(path)
try:
return self.matcher.
finally:
opens a file in text mode on Python 3. From open()'s docstring:
The default mode is 'rt' (open for reading text)
...
Python distinguishes between files opened in binary and text modes,
even when the underlying operating system doesn't. Files opened in
binary mode (appending 'b' to the mode argument) return contents as
bytes objects without any decoding. In text mode (the default, or when
't' is appended to the mode argument), the contents of the file are
returned as strings, the bytes having been first decoded using a
platform-
I think it would be kess surprising to open the file in binary mode.
An optional user-defined encoding might be useful too, if text is what
you need.
tags: | added: matchers |
I think it's fair to want to be able to match against binary files, but it's not strictly a defect, it's just you want something we haven't written yet :)