This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年08月10日 02:03 by denversc, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| test_argparse.py.COLUMNS.patch | denversc, 2010年08月10日 02:56 | Suggested Patch | review | |
| test_argparse.py.COLUMNS.update1.patch | denversc, 2010年08月11日 03:18 | Suggested Patch (update #1) | review | |
| test_argparse.py.COLUMNS.update2.patch | denversc, 2010年08月11日 23:32 | Suggested Patch (update #2) | review | |
| Messages (11) | |||
|---|---|---|---|
| msg113504 - (view) | Author: Denver Coneybeare (denversc) * | Date: 2010年08月10日 02:03 | |
If the COLUMNS environment variable is set to a value other than 80 then test_argparse.py yields 80 failures. The value of the COLUMNS environment variable affects line wrapping of the help output and the test cases assume line wraps at 80 columns. So setting COLUMNS=160, for example, then running the tests will reproduce the failures. The fix is to invoke: os.environ["COLUMNS"] = "80". A proposed patch for py3k/Lib/test/test_argparse.py is attached (test_argparse.py.COLUMNS.patch) |
|||
| msg113506 - (view) | Author: Brian Curtin (brian.curtin) * (Python committer) | Date: 2010年08月10日 02:56 | |
Shouldn't the tests calculate line wrapping based on what is set, rather than brute forcing it to be 80? |
|||
| msg113515 - (view) | Author: Steven Bethard (bethard) * (Python committer) | Date: 2010年08月10日 09:44 | |
The best solution would be to make sure that a few different column widths are tested. However, in the meantime, the tests do assume 80 columns, so I think it's correct to specify that using os.environ as suggested. One problem with the proposed patch is that it makes the change globally, and we should be restoring the original setting after the end of the argparse tests. |
|||
| msg113526 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年08月10日 11:53 | |
There's a handy utility for this in test.support: EnvironmentVarGuard. |
|||
| msg113564 - (view) | Author: Eric V. Smith (eric.smith) * (Python committer) | Date: 2010年08月10日 22:17 | |
I agree with Steven: for the current tests we should specify (and restore) 80 columns. We might want to add additional tests at different column widths. |
|||
| msg113583 - (view) | Author: Denver Coneybeare (denversc) * | Date: 2010年08月11日 03:18 | |
That is a very good point, bethard, that setting os.environ["COLUMNS"] in my suggested patch (test_argparse.py.COLUMNS.patch) is global and should be test-local. I've attached an updated patch (test_argparse.py.COLUMNS.update1.patch) which uses setUp() and tearDown() to prepare and restore the COLUMNS environment variable. The one difference from my previous patch is that instead of setting the COLUMNS environment variable to 80 I just unset it. I also considered EnvironmentVarGuard, as suggested by r.david.murray, but I'm not sure it's designed for global setting of environment variables. EnvironmentVarGuard appears to have been designed to be used as a context manager for an individual test, but the COLUMNS environment variable needs to be adjusted for *every* test. |
|||
| msg113600 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年08月11日 15:06 | |
Your code is fine (though to my tastes a bit verbose...if it were me I'd just put the code in the setUp and tearDown methods and hardcode 'COLUMNS' (it isn't like the name COLUMNS is going to change)...but that's just personal style). The EnviormentVarGuard version would look like this (untested): def setUp(self): self.guard = EnvironmentVarGuard() self.environ = self.guard.__enter__() # Current tests expect 80 column terminal width. self.environ['COLUMNS'] = 80 def tearDown(self): self.guard.__exit__(None, None, None) You could of course delete COLUMNS as you did, but I thought setting it to 80 would be more explicit. Another comment about the patch: by inspection it appears that adding setUp and tearDown to TestCase isn't enough, since subclasses and mixins define those without calling the superclass versions. |
|||
| msg113642 - (view) | Author: Denver Coneybeare (denversc) * | Date: 2010年08月11日 23:32 | |
Thanks for the input, r.david.murray. I've updated my patch and attached it to take into consideration your comments: test_argparse.py.COLUMNS.update2.patch. The updated patch uses EnviormentVarGuard as suggested, except that it slightly tweaks EnviormentVarGuard so the context manager protocol methods don't have to be invoked directly. It was also pointed out that "adding setUp and tearDown to TestCase isn't enough, since subclasses and mixins define those without calling the superclass versions", which is true. However, the tests that override setUp() happen to be those that don't depend on the COLUMNS environment variable. |
|||
| msg113697 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年08月12日 18:26 | |
I don't think it is worthwhile to jump through hoops to avoid calling the special methods. Your patch also creates an unnecessary dependency on the internal implementation of EnvironmentVarGuard (ie: the fact that currently __enter__ happens to return self...this is *not* part of EnvironmentVarGuard's interface contract). |
|||
| msg119934 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2010年10月29日 19:54 | |
As noted in issue10235, this is responsible for buildbot failures: http://www.python.org/dev/buildbot/all/builders/PPC%20Leopard%203.x/builds/685/steps/test/logs/stdio |
|||
| msg120129 - (view) | Author: Steven Bethard (bethard) * (Python committer) | Date: 2010年11月01日 14:22 | |
Fixed with a variant of Denver's last patch in r86080 for 3.X and r86083 for 2.7. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:05 | admin | set | github: 53762 |
| 2010年11月01日 14:22:38 | bethard | set | status: open -> closed assignee: bethard resolution: fixed messages: + msg120129 |
| 2010年10月29日 19:54:03 | pitrou | set | nosy:
+ pitrou, janssen messages: + msg119934 |
| 2010年10月29日 19:53:36 | pitrou | link | issue10235 superseder |
| 2010年08月12日 18:26:49 | r.david.murray | set | messages:
+ msg113697 stage: test needed -> patch review |
| 2010年08月11日 23:32:12 | denversc | set | files:
+ test_argparse.py.COLUMNS.update2.patch messages: + msg113642 |
| 2010年08月11日 15:06:12 | r.david.murray | set | messages: + msg113600 |
| 2010年08月11日 03:18:23 | denversc | set | files:
+ test_argparse.py.COLUMNS.update1.patch messages: + msg113583 |
| 2010年08月10日 22:17:33 | eric.smith | set | messages: + msg113564 |
| 2010年08月10日 22:15:48 | eric.araujo | set | nosy:
+ eric.araujo |
| 2010年08月10日 11:53:39 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg113526 |
| 2010年08月10日 09:44:37 | bethard | set | messages: + msg113515 |
| 2010年08月10日 02:57:00 | brian.curtin | set | versions:
+ Python 3.2, - Python 3.3 nosy: + brian.curtin messages: + msg113506 stage: test needed |
| 2010年08月10日 02:56:04 | denversc | set | files: + test_argparse.py.COLUMNS.patch |
| 2010年08月10日 02:55:52 | denversc | set | files: - test_argparse.py.COLUMNS.patch |
| 2010年08月10日 02:53:51 | denversc | set | type: behavior |
| 2010年08月10日 02:03:20 | denversc | create | |