localize some argcomplete-related functionality
This commit is contained in:
		
							parent
							
								
									8b1e53f6d3
								
							
						
					
					
						commit
						694c6fd0e7
					
				|  | @ -2,15 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| import py | import py | ||||||
| import sys, os | import sys, os | ||||||
| from _pytest.core import PluginManager |  | ||||||
| import pytest | import pytest | ||||||
| from _pytest._argcomplete import try_argcomplete, filescompleter |  | ||||||
| 
 |  | ||||||
| # enable after some grace period for plugin writers |  | ||||||
| TYPE_WARN = False |  | ||||||
| if TYPE_WARN: |  | ||||||
|     import warnings |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| def pytest_cmdline_parse(pluginmanager, args): | def pytest_cmdline_parse(pluginmanager, args): | ||||||
|     config = Config(pluginmanager) |     config = Config(pluginmanager) | ||||||
|  | @ -82,6 +74,7 @@ class Parser: | ||||||
|         self._anonymous.addoption(*opts, **attrs) |         self._anonymous.addoption(*opts, **attrs) | ||||||
| 
 | 
 | ||||||
|     def parse(self, args): |     def parse(self, args): | ||||||
|  |         from _pytest._argcomplete import try_argcomplete, filescompleter | ||||||
|         self.optparser = optparser = MyOptionParser(self) |         self.optparser = optparser = MyOptionParser(self) | ||||||
|         groups = self._groups + [self._anonymous] |         groups = self._groups + [self._anonymous] | ||||||
|         for group in groups: |         for group in groups: | ||||||
|  | @ -142,6 +135,8 @@ class Argument: | ||||||
|         'int': int, |         'int': int, | ||||||
|         'string': str, |         'string': str, | ||||||
|         } |         } | ||||||
|  |     # enable after some grace period for plugin writers | ||||||
|  |     TYPE_WARN = False | ||||||
| 
 | 
 | ||||||
|     def __init__(self, *names, **attrs): |     def __init__(self, *names, **attrs): | ||||||
|         """store parms in private vars for use in add_argument""" |         """store parms in private vars for use in add_argument""" | ||||||
|  | @ -149,11 +144,11 @@ class Argument: | ||||||
|         self._short_opts = [] |         self._short_opts = [] | ||||||
|         self._long_opts = [] |         self._long_opts = [] | ||||||
|         self.dest = attrs.get('dest') |         self.dest = attrs.get('dest') | ||||||
|         if TYPE_WARN: |         if self.TYPE_WARN: | ||||||
|             try: |             try: | ||||||
|                 help = attrs['help'] |                 help = attrs['help'] | ||||||
|                 if '%default' in help: |                 if '%default' in help: | ||||||
|                     warnings.warn( |                     py.std.warnings.warn( | ||||||
|                         'py.test now uses argparse. "%default" should be' |                         'py.test now uses argparse. "%default" should be' | ||||||
|                         ' changed to "%(default)s" ', |                         ' changed to "%(default)s" ', | ||||||
|                         FutureWarning, |                         FutureWarning, | ||||||
|  | @ -168,8 +163,8 @@ class Argument: | ||||||
|             # this might raise a keyerror as well, don't want to catch that |             # this might raise a keyerror as well, don't want to catch that | ||||||
|             if isinstance(typ, str): |             if isinstance(typ, str): | ||||||
|                 if typ == 'choice': |                 if typ == 'choice': | ||||||
|                     if TYPE_WARN: |                     if self.TYPE_WARN: | ||||||
|                         warnings.warn( |                         py.std.warnings.warn( | ||||||
|                             'type argument to addoption() is a string %r.' |                             'type argument to addoption() is a string %r.' | ||||||
|                             ' For parsearg this is optional and when supplied ' |                             ' For parsearg this is optional and when supplied ' | ||||||
|                             ' should be a type.' |                             ' should be a type.' | ||||||
|  | @ -180,8 +175,8 @@ class Argument: | ||||||
|                     # the type of the first element |                     # the type of the first element | ||||||
|                     attrs['type'] = type(attrs['choices'][0]) |                     attrs['type'] = type(attrs['choices'][0]) | ||||||
|                 else: |                 else: | ||||||
|                     if TYPE_WARN: |                     if self.TYPE_WARN: | ||||||
|                         warnings.warn( |                         py.std.warnings.warn( | ||||||
|                             'type argument to addoption() is a string %r.' |                             'type argument to addoption() is a string %r.' | ||||||
|                             ' For parsearg this should be a type.' |                             ' For parsearg this should be a type.' | ||||||
|                             ' (options: %s)' % (typ, names), |                             ' (options: %s)' % (typ, names), | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue