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

Port buildbot_worker.test.unit.test_scripts_runner.TestOptions.test_version to Python 3 #2390

Merged
merged 2 commits into from
Oct 2, 2016

Conversation

rodrigc
Copy link
Contributor

@rodrigc rodrigc commented Sep 4, 2016

No description provided.

@mention-bot
Copy link

@rodrigc, thanks for your PR! By analyzing the annotation information on this pull request, we identified @rutsky and @tardyp to be potential reviewers

@codecov-io
Copy link

codecov-io commented Sep 4, 2016

Current coverage is 86.66% (diff: 100%)

Merging #2390 into master will not change coverage

@@             master      #2390   diff @@
==========================================
  Files           294        294          
  Lines         30554      30554          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits          26480      26480          
  Misses         4074       4074          
  Partials          0          0          

Sunburst

Powered by Codecov. Last update cc3696b...e523abb

if PY3:
self.stdout = StringIO()
else:
self.stdout = BytesIO()
Copy link
Member

Choose a reason for hiding this comment

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

it is weird, as the previous implementation implemented stdout as stringio.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks weird, but the old StringIO and cStringIO modules cannot even be imported
in Python 3. io.StringIO deals strictly with Unicode on Python 2, Python3,
and io.BytesIO deals strictly with bytes on Python 2, Python 3.

sys.stdout / sys.stderr are implemented very differently on Python 3 as I mentioned in the comments,
so in order to keep this code working on both Python 2 and Python 3,
using BytesIO on Python 2, and StringIO on Python 3 is necessary.
For this particular case of overriding sys.stdout, it cannot be avoided.

import errno
import os
import re
import shutil
import sys
from io import BytesIO
Copy link
Contributor

Choose a reason for hiding this comment

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

is this order OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this order is OK. isort accepts it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say it's NOT OK: imports within a "block" must be sorted by the module name.

Copy link
Member

Choose a reason for hiding this comment

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

I'd say its ok. the from are placed after the imports within the stdlib import group

import errno
import os
import re
import shutil
import sys
from io import BytesIO
from io import StringIO

import mock
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect this import to be after the use of future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? isort accepts this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, mock offers the functionality that is:

  • not related to future (=> an empty line)
  • more specific to the content of this file (=> move after imports that are more generic)

self.stdout = cStringIO.StringIO()
#
# sys.stdout is implemented differently
# in Python 2 and Python 3, so we need to
Copy link
Contributor

Choose a reason for hiding this comment

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

why this kind of of formatting? no need to wrap the line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason. Does it really matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

It does not and it does: a split line for no reason is more difficult to read.

# override it differently.
# In Python 2, sys.stdout is a byte stream.
# In Python 3, sys.stdout is a text stream.
if PY3:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect this kind of thing to be handled by future, does it not handle it well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

future doesn't handle this well, because the differences in sys.stdout between Python 2 and Python 3 are quite different and rather tricky.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. OK.

import errno
import os
import re
import shutil
import sys
from io import BytesIO
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say it's NOT OK: imports within a "block" must be sorted by the module name.

import errno
import os
import re
import shutil
import sys
from io import BytesIO
from io import StringIO

import mock
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, mock offers the functionality that is:

  • not related to future (=> an empty line)
  • more specific to the content of this file (=> move after imports that are more generic)


import mock
from future.utils import PY3
from future.utils import string_types
from twisted.python import log
Copy link
Contributor

Choose a reason for hiding this comment

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

On related note, there should be an empty line before this one.

self.stdout = cStringIO.StringIO()
#
# sys.stdout is implemented differently
# in Python 2 and Python 3, so we need to
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not and it does: a split line for no reason is more difficult to read.

# override it differently.
# In Python 2, sys.stdout is a byte stream.
# In Python 3, sys.stdout is a text stream.
if PY3:
Copy link
Contributor

Choose a reason for hiding this comment

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

Right. OK.

@tardyp tardyp merged commit 3e5166f into buildbot:master Oct 2, 2016
@rodrigc rodrigc deleted the stringio branch October 2, 2016 18:40
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.

5 participants