Skip to content

Commit 43beaa0

Browse files
committed
add plaintext ofmt to patch tool
1 parent a803e71 commit 43beaa0

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

nested_diff/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class App:
3535
'toml',
3636
'yaml',
3737
)
38-
supported_ofmts = ('auto', 'ini', 'json', 'toml', 'yaml')
38+
supported_ofmts = supported_ifmts
3939

4040
version = nested_diff.__version__
4141

@@ -154,6 +154,8 @@ def get_dumper(fmt, **kwargs):
154154
return IniDumper(**kwargs)
155155
if fmt == 'toml':
156156
return TomlDumper(**kwargs)
157+
if fmt == 'plaintext':
158+
return Dumper(**kwargs)
157159

158160
raise RuntimeError(f'Unsupported output format: {fmt}')
159161

@@ -267,11 +269,11 @@ def encode(self, data):
267269
Args:
268270
data: Data to encode.
269271
270-
Raises:
271-
NotImplementedError: Must be implemented in derivatives.
272+
Returns:
273+
Encoded data.
272274
273275
"""
274-
raise NotImplementedError
276+
return data
275277

276278
@staticmethod
277279
def get_opts(opts):

tests/cli/shared.txt.patch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"D": [
3+
{
4+
"I": [
5+
0,
6+
4,
7+
0,
8+
3
9+
]
10+
},
11+
{
12+
"U": "one"
13+
},
14+
{
15+
"U": "two"
16+
},
17+
{
18+
"R": "three"
19+
},
20+
{
21+
"U": ""
22+
}
23+
],
24+
"E": 5
25+
}

tests/cli/test_cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ def encode(self, data):
99
return data
1010

1111

12-
def test_abstract_dumper_encode():
13-
with pytest.raises(NotImplementedError):
14-
cli.Dumper().encode('data')
12+
def test_base_dumper_encode():
13+
assert cli.Dumper().encode('data') == 'data'
1514

1615

17-
def test_abstract_loader_decode():
16+
def test_base_loader_decode():
1817
assert cli.Loader().decode('data') == 'data'
1918

2019

tests/cli/test_patch_tool.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,30 @@ def test_toml_fmt(capsys, content, rpath, tmp_path):
172172
assert content(result_file_name) == expected
173173

174174

175+
def test_plaintext_fmt(capsys, content, rpath, tmp_path):
176+
result_file_name = f'{tmp_path}.got.txt'
177+
copyfile(
178+
rpath('shared.a.txt'),
179+
result_file_name,
180+
)
181+
exit_code = nested_diff.patch_tool.App(
182+
args=(
183+
'--ofmt',
184+
'plaintext',
185+
result_file_name,
186+
rpath('shared.txt.patch.json'),
187+
),
188+
).run()
189+
190+
captured = capsys.readouterr()
191+
assert captured.out == ''
192+
assert captured.err == ''
193+
assert exit_code == 0
194+
195+
expected = content(rpath('shared.b.txt'))
196+
assert content(result_file_name) == expected
197+
198+
175199
def test_entry_point(capsys):
176200
with mock.patch('sys.argv', ['nested_patch', '-h']):
177201
with pytest.raises(SystemExit) as e:

0 commit comments

Comments
 (0)