[2.7] bpo-30366: Backport tests for test.support. by serhiy-storchaka · Pull Request #1582 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation4 Commits3 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

serhiy-storchaka

Also backport new functions temp_dir() and python_is_optimized().
temp_cwd() now accepts None as a name (means using tempfile.mkdtemp).
check_syntax_error() now accepts arguments lineno and offset.

@serhiy-storchaka

Also backport new functions temp_dir() and python_is_optimized(). temp_cwd() now accepts None as a name (means using tempfile.mkdtemp). check_syntax_error() now accepts arguments lineno and offset.

@serhiy-storchaka

vstinner

Choose a reason for hiding this comment

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

I didn't compare test_test_support with master. I guess that it's the same code or almost the same. Backported enhancements are fine.

LGTM.

@@ -155,8 +155,12 @@ def get_attribute(obj, name):
try:
attribute = getattr(obj, name)
except AttributeError:
raise unittest.SkipTest("module %s has no attribute %s" % (
obj.__name__, name))
if isinstance(obj, type(sys)):

Choose a reason for hiding this comment

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

I guess that the code is the same in master. I am surprised that types.ModuleType is not used here.

Choose a reason for hiding this comment

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

This code is a hybrid between former 2.7 code and master code. In 2.7 it can be used only for modules, and reports module name on error. In master it can be used for arbitrary objects and reports object's repr on error (this looks worser for modules). I'm going to port this specialization to master.

types.ModuleType is not used because types is not imported in test.support and I don't want to add imports without need.

Choose a reason for hiding this comment

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

types is already imported by test.support through functools ;-) Again, it was just a comment, it's unrelated to the backport itself.

haypo@selma$ ./python -i -S
Python 3.7.0a0 (heads/shutdown_10022:1315e80, May 10 2017, 18:49:18) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
>>> import test
>>> import test.support
>>> import sys
>>> 'types' in sys.modules
True

@serhiy-storchaka