Submitter | Pierre-Yves David |
---|---|
Date | Sept. 18, 2014, 6:50 p.m. |
Message ID | <fa5cfb6d0b03d9fd471b.1411066258@marginatus.alto.octopoid.net> |
Download | mbox | patch |
Permalink | /patch/5871/ |
State | Accepted |
Headers | show |
Comments
Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes: > # HG changeset patch > # User Pierre-Yves David <pierre-yves.david@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) > > +@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
On Fri, Sep 19, 2014 at 02:16:17PM +0200, Martin Geisler wrote: > Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes: > > > # HG changeset patch > > # User Pierre-Yves David <pierre-yves.david@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) > > > > +@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. > > -- > Martin Geisler > > http://google.com/+MartinGeisler > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel
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@ens-lyon.org> writes: >> >>> # HG changeset patch >>> # User Pierre-Yves David <pierre-yves.david@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) >>> >>> +@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.
On Thu, 2014-09-18 at 11:50 -0700, Pierre-Yves David wrote: > # HG changeset patch > # User Pierre-Yves David <pierre-yves.david@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 Queued for default, thanks.
Patch
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) +@check("json", "some json module available") +def has_json(): + try: + if sys.version_info < (2, 7): + import simplejson as json + else: + import json + json.dumps + return True + except ImportError: + return False + @check("outer-repo", "outer repo") def has_outer_repo(): # failing for other reasons than 'no repo' imply that there is a repo return not matchoutput('hg root 2>&1', r'abort: no repository found', True) diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t --- a/tests/test-run-tests.t +++ b/tests/test-run-tests.t @@ -367,10 +367,12 @@ Missing skips or blacklisted skips don't ss Skipped test-bogus.t: Doesn't exist Skipped test-failure.t: blacklisted # Ran 0 tests, 2 skipped, 0 warned, 0 failed. +#if json + test for --json ================== $ $TESTDIR/run-tests.py --with-hg=`which hg` --json @@ -404,5 +406,7 @@ test for --json "test-success.t": [\{] (re) "result": "success", "time": "\s*[\d\.]{5}" (re) } } (no-eol) + +#endif