Skip to content

Commit 4eff1a6

Browse files
authored
Merge pull request #183 from dartmouth-pbs/bf-pretty-json
BF: do not remove all spaces after a number
2 parents f88e57b + 7f35085 commit 4eff1a6

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

heudiconv/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def json_dumps_pretty(j, indent=2, sort_keys=True):
200200
# uniform no spaces before ]
201201
js_ = re.sub(" *\]", "]", js_)
202202
# uniform spacing before numbers
203-
js_ = re.sub(' *("?[-+.0-9e]+"?)[ \n]*', r' \1', js_)
203+
js_ = re.sub(' *("?[-+.0-9e]+"?)(?P<space> ?)[ \n]*',
204+
r' \1\g<space>', js_)
204205
# no spaces after [
205206
js_ = re.sub('\[ ', '[', js_)
206207
# the load from the original dump and reload from tuned up

tests/test_main.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from heudiconv.cli.run import main as runner
44
from heudiconv import __version__
55
from heudiconv.utils import (create_file_if_missing,
6-
json_dumps_pretty,
76
set_readonly,
87
is_readonly)
98
from heudiconv.bids import (populate_bids_templates,
@@ -17,7 +16,6 @@
1716
import csv
1817
import os
1918
import pytest
20-
import stat
2119
import sys
2220

2321
from mock import patch
@@ -154,15 +152,6 @@ def test_prepare_for_datalad(tmpdir):
154152
assert '.heudiconv/dummy.nii.gz' not in ds.repo.get_files()
155153

156154

157-
def test_json_dumps_pretty():
158-
pretty = json_dumps_pretty
159-
assert pretty({}) == "{}"
160-
assert pretty({"a": -1, "b": "123", "c": [1, 2, 3], "d": ["1.0", "2.0"]}) \
161-
== '{\n "a": -1,\n "b": "123",\n "c": [1, 2, 3],\n "d": ["1.0", "2.0"]\n}'
162-
assert pretty({'a': ["0.3", "-1.9128906358217845e-12", "0.2"]}) \
163-
== '{\n "a": ["0.3", "-1.9128906358217845e-12", "0.2"]\n}'
164-
165-
166155
def test_get_formatted_scans_key_row():
167156
item = [
168157
('%s/01-fmap_acq-3mm/1.3.12.2.1107.5.2.43.66112.2016101409263663466202201.dcm'

tests/test_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from heudiconv.utils import (
44
get_known_heuristics_with_descriptions,
55
get_heuristic_description,
6-
load_heuristic
7-
)
6+
load_heuristic,
7+
json_dumps_pretty)
88

99
import pytest
1010
from .utils import HEURISTICS_PATH
@@ -40,4 +40,15 @@ def test_load_heuristic():
4040
load_heuristic('unknownsomething')
4141

4242
with pytest.raises(ImportError):
43-
load_heuristic(op.join(HEURISTICS_PATH, 'unknownsomething.py'))
43+
load_heuristic(op.join(HEURISTICS_PATH, 'unknownsomething.py'))
44+
45+
46+
def test_json_dumps_pretty():
47+
pretty = json_dumps_pretty
48+
assert pretty({"SeriesDescription": "Trace:Nov 13 2017 14-36-14 EST"}) \
49+
== '{\n "SeriesDescription": "Trace:Nov 13 2017 14-36-14 EST"\n}'
50+
assert pretty({}) == "{}"
51+
assert pretty({"a": -1, "b": "123", "c": [1, 2, 3], "d": ["1.0", "2.0"]}) \
52+
== '{\n "a": -1,\n "b": "123",\n "c": [1, 2, 3],\n "d": ["1.0", "2.0"]\n}'
53+
assert pretty({'a': ["0.3", "-1.9128906358217845e-12", "0.2"]}) \
54+
== '{\n "a": ["0.3", "-1.9128906358217845e-12", "0.2"]\n}'

utils/test-compare-two-versions.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
PS1=+
88
set -eu
99

10-
outdir=${OUTDIR:=compare-versions/$(basename $1)}
10+
outdir=${OUTDIR:=compare-versions}
1111

1212
RUN=echo
1313
RUN=
@@ -33,14 +33,15 @@ function run() {
3333
$RUN heudiconv --random-seed 1 -c dcm2niix -o $out --datalad --bids "$@" >| $out.log 2>&1
3434
}
3535

36-
run heudiconv rolando -f heudiconv/heuristics/dbic_bids.py "$@"
37-
run heudiconv-master master -f reproin --files "$@"
36+
other=other
37+
run heudiconv $other "$@"
38+
run heudiconv-master master "$@"
3839

3940
cd $outdir
4041
#git remote add rolando "$outdir/rolando"
4142
#git fetch rolando
4243
# git diff --stat rolando/master..
43-
if diff -Naur --exclude=.git --ignore-matching-lines='^\s*id\s*=.*' rolando master >| diff.patch; then
44+
if diff -Naur --exclude=.git --ignore-matching-lines='^\s*id\s*=.*' $other master >| diff.patch; then
4445
echo "Results are identical"
4546
else
4647
echo "Results differ: $PWD/diff.patch"

0 commit comments

Comments
 (0)