Show More
@@ -38,6 +38,7 b' import tempfile' | |||||
38 | import textwrap |
|
38 | import textwrap | |
39 | import time |
|
39 | import time | |
40 | import traceback |
|
40 | import traceback | |
|
41 | import warnings | |||
41 | import zlib |
|
42 | import zlib | |
42 |
|
43 | |||
43 | from . import ( |
|
44 | from . import ( | |
@@ -156,6 +157,31 b' def bitsfrom(container):' | |||||
156 | bits |= bit |
|
157 | bits |= bit | |
157 | return bits |
|
158 | return bits | |
158 |
|
159 | |||
|
160 | # python 2.6 still have deprecation warning enabled by default. We do not want | |||
|
161 | # to display anything to standard user so detect if we are running test and | |||
|
162 | # only use python deprecation warning in this case. | |||
|
163 | _dowarn = bool(encoding.environ.get('HGEMITWARNINGS')) | |||
|
164 | if _dowarn: | |||
|
165 | # explicitly unfilter our warning for python 2.7 | |||
|
166 | # | |||
|
167 | # The option of setting PYTHONWARNINGS in the test runner was investigated. | |||
|
168 | # However, module name set through PYTHONWARNINGS was exactly matched, so | |||
|
169 | # we cannot set 'mercurial' and have it match eg: 'mercurial.scmutil'. This | |||
|
170 | # makes the whole PYTHONWARNINGS thing useless for our usecase. | |||
|
171 | warnings.filterwarnings('default', '', DeprecationWarning, 'mercurial') | |||
|
172 | warnings.filterwarnings('default', '', DeprecationWarning, 'hgext') | |||
|
173 | warnings.filterwarnings('default', '', DeprecationWarning, 'hgext3rd') | |||
|
174 | ||||
|
175 | def nouideprecwarn(msg, version, stacklevel=1): | |||
|
176 | """Issue an python native deprecation warning | |||
|
177 | ||||
|
178 | This is a noop outside of tests, use 'ui.deprecwarn' when possible. | |||
|
179 | """ | |||
|
180 | if _dowarn: | |||
|
181 | msg += ("\n(compatibility will be dropped after Mercurial-%s," | |||
|
182 | " update your code.)") % version | |||
|
183 | warnings.warn(msg, DeprecationWarning, stacklevel + 1) | |||
|
184 | ||||
159 | DIGESTS = { |
|
185 | DIGESTS = { | |
160 | 'md5': hashlib.md5, |
|
186 | 'md5': hashlib.md5, | |
161 | 'sha1': hashlib.sha1, |
|
187 | 'sha1': hashlib.sha1, |
@@ -884,6 +884,7 b' class Test(unittest.TestCase):' | |||||
884 | env = os.environ.copy() |
|
884 | env = os.environ.copy() | |
885 | if sysconfig is not None: |
|
885 | if sysconfig is not None: | |
886 | env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') |
|
886 | env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') | |
|
887 | env['HGEMITWARNINGS'] = '1' | |||
887 | env['TESTTMP'] = self._testtmp |
|
888 | env['TESTTMP'] = self._testtmp | |
888 | env['HOME'] = self._testtmp |
|
889 | env['HOME'] = self._testtmp | |
889 | # This number should match portneeded in _getport |
|
890 | # This number should match portneeded in _getport |
@@ -3,7 +3,7 b'' | |||||
3 | > """A small extension that tests our developer warnings |
|
3 | > """A small extension that tests our developer warnings | |
4 | > """ |
|
4 | > """ | |
5 | > |
|
5 | > | |
6 | > from mercurial import cmdutil, repair |
|
6 | > from mercurial import cmdutil, repair, util | |
7 | > |
|
7 | > | |
8 | > cmdtable = {} |
|
8 | > cmdtable = {} | |
9 | > command = cmdutil.command(cmdtable) |
|
9 | > command = cmdutil.command(cmdtable) | |
@@ -58,6 +58,9 b'' | |||||
58 | > def foobar(ui): |
|
58 | > def foobar(ui): | |
59 | > ui.deprecwarn('foorbar is deprecated, go shopping', '42.1337') |
|
59 | > ui.deprecwarn('foorbar is deprecated, go shopping', '42.1337') | |
60 | > foobar(ui) |
|
60 | > foobar(ui) | |
|
61 | > @command('nouiwarning', [], '') | |||
|
62 | > def nouiwarning(ui, repo): | |||
|
63 | > util.nouideprecwarn('this is a test', '13.37') | |||
61 | > EOF |
|
64 | > EOF | |
62 |
|
65 | |||
63 | $ cat << EOF >> $HGRCPATH |
|
66 | $ cat << EOF >> $HGRCPATH | |
@@ -163,4 +166,15 b' Test programming error failure:' | |||||
163 | Traceback (most recent call last): |
|
166 | Traceback (most recent call last): | |
164 | mercurial.error.ProgrammingError: transaction requires locking |
|
167 | mercurial.error.ProgrammingError: transaction requires locking | |
165 |
|
168 | |||
|
169 | Old style deprecation warning | |||
|
170 | ||||
|
171 | $ hg nouiwarning | |||
|
172 | $TESTTMP/buggylocking.py:61: DeprecationWarning: this is a test | |||
|
173 | (compatibility will be dropped after Mercurial-13.37, update your code.) | |||
|
174 | util.nouideprecwarn('this is a test', '13.37') | |||
|
175 | ||||
|
176 | (disabled outside of test run) | |||
|
177 | ||||
|
178 | $ HGEMITWARNINGS= hg nouiwarning | |||
|
179 | ||||
166 | $ cd .. |
|
180 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now