comparison tests/test-devel-warnings.t @ 31950:cc70c6dbac30

util: add a way to issue deprecation warning without a UI object Our current deprecation warning mechanism relies on ui object. They are case where we cannot have access to the UI object. On a general basis we avoid using the python mechanism for deprecation warning because up to Python 2.6 it is exposing warning to unsuspecting user who cannot do anything to deal with them. So we build a "safe" strategy to hide this warnings behind a flag in an environment variable. The test runner set this flag so that tests show these warning. This will help us marker API as deprecated for extensions to update their code.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 04 Apr 2017 11:03:29 +0200
parents 35b8bb1ef02b
children 0fb78cb90ca7
comparison
equal deleted inserted replaced
31949:eaf3819631c2 31950:cc70c6dbac30
1 1
2 $ cat << EOF > buggylocking.py 2 $ cat << EOF > buggylocking.py
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)
10 > 10 >
11 > @command('buggylocking', [], '') 11 > @command('buggylocking', [], '')
56 > def oldanddeprecated(ui, repo): 56 > def oldanddeprecated(ui, repo):
57 > """test deprecation warning API""" 57 > """test deprecation warning API"""
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
64 > [extensions] 67 > [extensions]
65 > buggylocking=$TESTTMP/buggylocking.py 68 > buggylocking=$TESTTMP/buggylocking.py
161 ** Mercurial Distributed SCM (*) (glob) 164 ** Mercurial Distributed SCM (*) (glob)
162 ** Extensions loaded: * (glob) 165 ** Extensions loaded: * (glob)
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 ..