[PATCH default-tests-fix] test: protect the run-tests.py --json test behind an hghave rule

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Sep 23 13:13:32 CDT 2014



On 09/23/2014 11:09 AM, Augie Fackler wrote:
> On Fri, Sep 19, 2014 at 02:16:17PM +0200, Martin Geisler wrote:
>> Pierre-Yves David <pierre-yves.david at ens-lyon.org> writes:
>>
>>> # HG changeset patch
>>> # User Pierre-Yves David <pierre-yves.david at fb.com>
>>> # Date 1411065827 25200
>>> #      Thu Sep 18 11:43:47 2014 -0700
>>> # Node ID fa5cfb6d0b03d9fd471b920d9f5fe0ac358cdbb1
>>> # Parent  48791c2bea1ceda4e4f28bc11651e281d636ce1a
>>> test: protect the run-tests.py --json test behind an hghave rule
>>>
>>> We add a rules to detect availability of a json module and skip if json is not
>>> available.
>>>
>>> diff --git a/tests/hghave.py b/tests/hghave.py
>>> --- a/tests/hghave.py
>>> +++ b/tests/hghave.py
>>> @@ -279,10 +279,22 @@ def has_pygments():
>>>
>>>   @check("python243", "python >= 2.4.3")
>>>   def has_python243():
>>>       return sys.version_info >= (2, 4, 3)
>>>
>>> + at check("json", "some json module available")
>>> +def has_json():
>>> +    try:
>>> +        if sys.version_info < (2, 7):
>>> +            import simplejson as json
>>
>> Should this not test with Python 2.6 instead? That was the first version
>> that shipped with a json stdlib module:
>>
>>    https://docs.python.org/2/whatsnew/2.6.html#the-json-module-javascript-object-notation
>
> It'd probably be even better to just do
>
> try:
>    import json
> except ImportError:
>    try:
>      import simplejson as json
>    except ImportError:
>      return False
> return True
>
> so that then if someone has a backported json module in 2.5 or
> whatever, things Just Work.

I'm using the very same code as the place where json is imported. one 
could import both import in a later patch.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list