Skip to content

Commit 965511d

Browse files
committed
Shed diff enhancements.
- Add test case. - Add option to write diff out to a file (needed for test, but good functionality on its own). - Improved labelling when using full URLs to tool sheds.
1 parent d7e735c commit 965511d

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

planemo/commands/cmd_shed_diff.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
@options.shed_owner_option()
1818
@options.shed_name_option()
1919
@options.shed_target_option()
20+
@click.option(
21+
"-o", "--output",
22+
type=click.Path(file_okay=True, resolve_path=True),
23+
help="Send diff output to specified file.",
24+
default=None,
25+
)
2026
@click.option(
2127
'--shed_target_source',
2228
help="Source Tool Shed to diff against (will ignore local project info"
@@ -55,7 +61,10 @@ def diff_in(ctx, working, path, **kwds):
5561
shed_target_source = kwds.get("shed_target_source", None)
5662

5763
label_a = "_%s_" % (shed_target_source if shed_target_source else "local")
58-
label_b = "_%s_" % kwds.get("shed_target", "B")
64+
shed_target = kwds.get("shed_target", "B")
65+
if "/" in shed_target:
66+
shed_target = "custom_shed"
67+
label_b = "_%s_" % shed_target
5968

6069
mine = os.path.join(working, label_a)
6170
other = os.path.join(working, label_b)
@@ -87,4 +96,7 @@ def diff_in(ctx, working, path, **kwds):
8796
cmd_template = 'mkdir "%s"; tar -xzf "%s" -C "%s"; rm -rf %s'
8897
shell(cmd_template % (mine, tar_path, mine, tar_path))
8998

90-
shell('cd "%s"; diff -r %s %s' % (working, label_a, label_b))
99+
cmd = 'cd "%s"; diff -r %s %s' % (working, label_a, label_b)
100+
if kwds["output"]:
101+
cmd += "> '%s'" % kwds["output"]
102+
shell(cmd)

tests/test_shed_diff.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
""" Integration tests for shed_diff command.
2+
"""
3+
4+
import os
5+
from .test_utils import CliShedTestCase
6+
7+
DIFF_LINES = [
8+
"diff -r _local_/related_file _custom_shed_/related_file",
9+
"< A related non-tool file (modified).",
10+
"> A related non-tool file.",
11+
]
12+
13+
14+
class ShedUploadTestCase(CliShedTestCase):
15+
16+
def test_shed_diff(self):
17+
with self._isolate_repo("single_tool") as f:
18+
upload_command = ["shed_upload", "--force_repository_creation"]
19+
upload_command.extend(self._shed_args())
20+
self._check_exit_code(upload_command)
21+
with open(os.path.join(f, "related_file"), "w") as r_f:
22+
r_f.write("A related non-tool file (modified).\n")
23+
24+
diff_command = ["shed_diff", "-o", "diff"]
25+
diff_command.extend(self._shed_args(read_only=True))
26+
self._check_exit_code(diff_command)
27+
with open("diff", "r") as f:
28+
diff = f.read()
29+
for diff_line in DIFF_LINES:
30+
assert diff_line in diff

0 commit comments

Comments
 (0)