-
Notifications
You must be signed in to change notification settings - Fork 6
open() files in binary if we're going to write bytes #80
Conversation
Can we stop mocking the I don't understand "other Python 3-related issues". This project surely requires Python 3. The Perhaps now's not the time but the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit about not bothering to convert it to a byte string and keeping 'w'
.
The biggest culprit here is that the tests should not mock open
and instead be allowed to write a file and the tests should open the file to check if they're sane.
amo2kinto/generator.py
Outdated
@@ -35,7 +35,7 @@ def sort_records(record): | |||
filename = os.path.join(target_dir, 'index.html') | |||
|
|||
logger.info('Writing %s' % filename) | |||
with open(filename, 'w') as f: | |||
with open(filename, 'wb') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res
is a unicode string so it's correct to use wb
if you're going to convert it to a byte string. But I would instead keep it as a unicode string.
I.e.
res = '🚵♂️'
with open('/tmp/index.html', 'w') as f:
f.write(res)
This works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you prefer this? It seems natural to me to write bytes to disk, since after all a disk contains a string of bytes, not a string of code points.
No, the unit tests are correct to mock/inject the dependencies of the code under test. I have opened #81 to see about adding a functional test.
"Requires Python 3" is another way of saying "is not compatible with Python 2". It is not the same thing as "functions under Python 3".
What do you mean? Both Python 3.5 and 3.6 are visible on the Travis results for this PR. |
Regarding the Travis only running 3.6. I read the file wrong. My bad. |
This is meant to address #79. I'm not sure if there are other Python 3-related issues around this project -- this is just the first one we hit. The tests didn't catch it because they substitute a mock for the open() call.