Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intg: Fix python3 issues #157

Closed
wants to merge 1 commit into from
Closed

Conversation

lslebodn
Copy link
Contributor

Mostly string/bytes related issues.

It looks like my comments to the integration tests
were lost as part of review or due to rebases.

@fidencio
Copy link
Contributor

Patch does make sense, but I don't feel comfortable ACKing python related stuff.
Martin Basti? :-)

Copy link

@MartinBasti MartinBasti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, otherwise LGTM

have you tried to run tests with python3 -bb?

@@ -77,6 +77,7 @@ def _read_contents(self):

def _write_contents(self, contents):
tmp_file = tempfile.NamedTemporaryFile(dir=self.tmp_dir, delete=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If content is unicode, then instead of encoding, NamedTemporaryFile can be opened in textual write mode "w", default mode is binary "w+b"

Would be nice to use with keyword with files, but unrelated to this patch

with tempfile.NamedTemporaryFile("w", dir=self.tmp_dir, delete=False) as tmp_file:
     tmp_file.writelines(contents)
     tmp_file.flush()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know.
Fixed

@fidencio
Copy link
Contributor

@lslebodn: I'd say the changes mentioned by Martin (thanks for the review, btw) could (and do make sense) be part of this "series" (not exactly the same patch though, as already mentioned by Martin).

@fidencio
Copy link
Contributor

@lslebodn:

There's no need to resend the patch, just change it before pushing ...
But, please, add some comment explaining the reason of using 'w' in the NamedTemporaryFile() (just because it's not something obvious).

@MartinBasti
Copy link

IMO the w arg is quite obvious in python

@fidencio
Copy link
Contributor

I'd like to see the whole explanation in the commit message:
'If content is unicode, then instead of encoding, NamedTemporaryFile can be opened in textual write mode "w", default mode is binary "w+b" '

Doesn't seem to be obvious as it ended up caught during the review (and I'm quite dumb on python related stuff). So better having it in the commit message than searching for it on my email if necessary.

@lslebodn
Copy link
Contributor Author

lslebodn commented Feb 17, 2017 via email

@fidencio
Copy link
Contributor

It shouldn't teach people how to use python, true. But it has to have a good explanation why those changes where necessary (and here as much info as possible is desirable, mainly for people who don't do python and may blame this code for reference).

NamedTemporaryFile use the default mode 'w+b'
and we tried to write strings. It is not a problem on python2
but failed on pyhton3

Python module ctypes directly uses C functions from libraries.
C functions usually expect/returns "char *" when string is expected.
But python3 uses unicode for string. Decoding returned bytes
("char *") to unicode strings simplify tests in python3.
Otherwise we would need to convert bytes to string in each assertion.
@fidencio
Copy link
Contributor

@lslebodn, thanks!

Please, go for it.

@lslebodn
Copy link
Contributor Author

lslebodn commented Feb 17, 2017 via email

@lslebodn lslebodn closed this Feb 17, 2017
@lslebodn lslebodn deleted the test_files branch February 17, 2017 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants