Skip to content

Commit 574ae23

Browse files
committed
add plaintext ifmt
1 parent d572a7e commit 574ae23

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

nested_diff/cli.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ class App:
2727
default_ifmt = 'auto'
2828
default_ofmt = 'auto'
2929

30-
supported_ifmts = ('auto', 'ini', 'json', 'toml', 'yaml')
30+
supported_ifmts = (
31+
'auto',
32+
'ini',
33+
'json',
34+
'plaintext',
35+
'toml',
36+
'yaml',
37+
)
3138
supported_ofmts = ('auto', 'ini', 'json', 'toml', 'yaml')
3239

3340
version = nested_diff.__version__
@@ -186,6 +193,8 @@ def get_loader(fmt, **kwargs):
186193
return IniLoader(**kwargs)
187194
if fmt == 'toml':
188195
return TomlLoader(**kwargs)
196+
if fmt == 'plaintext':
197+
return Loader(**kwargs)
189198

190199
raise RuntimeError(f'Unsupported input format: {fmt}')
191200

@@ -290,11 +299,11 @@ def decode(self, data): # noqa U100
290299
Args:
291300
data: Data to decode.
292301
293-
Raises:
294-
NotImplementedError: Must be implemented in derivatives.
302+
Returns:
303+
Decoded data structure.
295304
296305
"""
297-
raise NotImplementedError
306+
return data
298307

299308
@staticmethod
300309
def get_opts(opts):

nested_diff/diff_tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ def get_dumper(self, fmt, **kwargs):
211211
fmt = 'term' if self.args.out.isatty() else 'text'
212212

213213
if fmt in FormatterDumper.supported_fmts:
214+
if self.args.ifmt == 'plaintext':
215+
kwargs.setdefault('type_hints', False)
216+
214217
return FormatterDumper(fmt=fmt, values=self.args.values, **kwargs)
215218

216219
return super().get_dumper(fmt, **kwargs)

tests/cli/test_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def test_abstract_dumper_encode():
1515

1616

1717
def test_abstract_loader_decode():
18-
with pytest.raises(NotImplementedError):
19-
cli.Loader().decode('data')
18+
assert cli.Loader().decode('data') == 'data'
2019

2120

2221
def test_dumper_dump_default_with_tty(stringio_tty):

tests/cli/test_diff_tool.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,23 @@ def test_html_ofmt_wrappings(capsys, expected, rpath):
284284
assert captured.out == expected
285285

286286

287+
def test_plaintext_ifmt(capsys, expected, rpath):
288+
exit_code = nested_diff.diff_tool.App(
289+
args=(
290+
rpath('shared.lists.a.json'),
291+
rpath('shared.lists.b.json'),
292+
'--ifmt',
293+
'plaintext',
294+
),
295+
).run()
296+
297+
captured = capsys.readouterr()
298+
assert captured.err == ''
299+
assert exit_code == 1
300+
301+
assert captured.out == expected
302+
303+
287304
def test_text_ofmt(capsys, expected, rpath):
288305
exit_code = nested_diff.diff_tool.App(
289306
args=(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@@ -1,7 +1,8 @@
2+
[
3+
0,
4+
[
5+
- 1
6+
+ 1,
7+
+ 2
8+
],
9+
3
10+
]

0 commit comments

Comments
 (0)