Mercurial > hg
annotate tests/test-module-imports.t @ 24545:9e0c67e84896
json: implement {tags} template
Tags is pretty easy to implement. Let's start there.
The output is slightly different from `hg tags -Tjson`. For reference,
the CLI has the following output:
[
{
"node": "e2049974f9a23176c2addb61d8f5b86e0d620490",
"rev": 29880,
"tag": "tip",
"type": ""
},
...
]
Our output has the format:
{
"node": "0aeb19ea57a6d223bacddda3871cb78f24b06510",
"tags": [
{
"node": "e2049974f9a23176c2addb61d8f5b86e0d620490",
"tag": "tag1",
"date": [1427775457.0, 25200]
},
...
]
}
"rev" is omitted because it isn't a reliable identifier. We shouldn't
be exposing them in web APIs and giving the impression it remotely
resembles a stable identifier. Perhaps we could one day hide this behind
a config option (it might be useful to expose when running servers
locally).
The "type" of the tag isn't defined because this information isn't yet
exposed to the hgweb templater (it could be in a follow-up) and because
it is questionable whether different types should be exposed at all.
(Should the web interface really be exposing "local" tags?)
We use an object for the outer type instead of Array for a few reasons.
First, it is extensible. If we ever need to throw more global properties
into the output, we can do that without breaking backwards compatibility
(property additions should be backwards compatible). Second, uniformity
in web APIs is nice. Having everything return objects seems much saner than
a mix of array and object. Third, there are security issues with arrays
in older browsers. The JSON web services world almost never uses arrays
as the main type for this reason.
Another possibly controversial part about this patch is how dates are
defined. While JSON has a Date type, it is based on the JavaScript Date
type, which is widely considered a pile of garbage. It is a non-starter
for this reason.
Many of Mercurial's built-in date filters drop seconds resolution. So
that's a non-starter as well, since we want the API to be lossless where
possible. rfc3339date, rfc822date, isodatesec, and date are all lossless.
However, they each require the client to perform string parsing on top of
JSON decoding. While date parsing libraries are pretty ubiquitous, some
languages don't have them out of the box. However, pretty much every
programming language can deal with UNIX timestamps (which are just
integers or floats). So, we choose to use Mercurial's internal date
representation, which in JSON is modeled as float seconds since UNIX
epoch and an integer timezone offset from UTC (keep in mind
JavaScript/JSON models all "Numbers" as double prevision floating point
numbers, so there isn't a difference between ints and floats in JSON).
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 31 Mar 2015 14:52:21 -0700 |
parents | 642d245ff537 |
children | 02a5618e2fbf |
rev | line source |
---|---|
23894
f388ceae2250
test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents:
22947
diff
changeset
|
1 #require test-repo |
f388ceae2250
test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents:
22947
diff
changeset
|
2 |
20059
385e209377a6
test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents:
20039
diff
changeset
|
3 This code uses the ast module, which was new in 2.6, so we'll skip |
385e209377a6
test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents:
20039
diff
changeset
|
4 this test on anything earlier. |
22947
c63a09b6b337
tests: use $PYTHON instead of hardcoding python
Augie Fackler <raf@durin42.com>
parents:
20519
diff
changeset
|
5 $ $PYTHON -c 'import sys ; assert sys.version_info >= (2, 6)' || exit 80 |
20059
385e209377a6
test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents:
20039
diff
changeset
|
6 |
20039
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
7 $ import_checker="$TESTDIR"/../contrib/import-checker.py |
23894
f388ceae2250
test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents:
22947
diff
changeset
|
8 |
20039
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
9 Run the doctests from the import checker, and make sure |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
10 it's working correctly. |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
11 $ TERM=dumb |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
12 $ export TERM |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
13 $ python -m doctest $import_checker |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
14 |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
15 $ cd "$TESTDIR"/.. |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
16 |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
17 There are a handful of cases here that require renaming a module so it |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
18 doesn't overlap with a stdlib module name. There are also some cycles |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
19 here that we should still endeavor to fix, and some cycles will be |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
20 hidden by deduplication algorithm in the cycle detector, so fixing |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
21 these may expose other cycles. |
05626e87489c
test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
22 |
20395
ab71fb058ebf
tests: test-module-imports.t works on windows (with backslash path sep)
Simon Heimberg <simohe@besonet.ch>
parents:
20392
diff
changeset
|
23 $ hg locate 'mercurial/**.py' | sed 's-\\-/-g' | xargs python "$import_checker" |
24423
01b39e821d00
crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
23894
diff
changeset
|
24 mercurial/crecord.py mixed imports |
01b39e821d00
crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
23894
diff
changeset
|
25 stdlib: fcntl, termios |
01b39e821d00
crecord: conditionalize the imports that are not available on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
23894
diff
changeset
|
26 relative: curses |
20386
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
27 mercurial/dispatch.py mixed imports |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
28 stdlib: commands |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
29 relative: error, extensions, fancyopts, hg, hook, util |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
30 mercurial/fileset.py mixed imports |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
31 stdlib: parser |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
32 relative: error, merge, util |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
33 mercurial/revset.py mixed imports |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
34 stdlib: parser |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
35 relative: discovery, error, hbisect, phases, util |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
36 mercurial/templater.py mixed imports |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
37 stdlib: parser |
20519
cda9d2b6beab
template: add revset() template function
Durham Goode <durham@fb.com>
parents:
20405
diff
changeset
|
38 relative: config, error, templatefilters, templatekw, util |
20386
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
39 mercurial/ui.py mixed imports |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
40 stdlib: formatter |
a05d31b040d7
import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents:
20199
diff
changeset
|
41 relative: config, error, scmutil, util |
24487
642d245ff537
import-checker: fix rotatecycle
Matt Mackall <mpm@selenic.com>
parents:
24423
diff
changeset
|
42 Import cycle: mercurial.cmdutil -> mercurial.context -> mercurial.subrepo -> mercurial.cmdutil |