Skip to content

Commit

Permalink
Shed diff enhancements.
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
jmchilton committed Apr 25, 2015
1 parent d7e735c commit 965511d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
16 changes: 14 additions & 2 deletions planemo/commands/cmd_shed_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
@options.shed_owner_option()
@options.shed_name_option()
@options.shed_target_option()
@click.option(
"-o", "--output",
type=click.Path(file_okay=True, resolve_path=True),
help="Send diff output to specified file.",
default=None,
)
@click.option(
'--shed_target_source',
help="Source Tool Shed to diff against (will ignore local project info"
Expand Down Expand Up @@ -55,7 +61,10 @@ def diff_in(ctx, working, path, **kwds):
shed_target_source = kwds.get("shed_target_source", None)

label_a = "_%s_" % (shed_target_source if shed_target_source else "local")
label_b = "_%s_" % kwds.get("shed_target", "B")
shed_target = kwds.get("shed_target", "B")
if "/" in shed_target:
shed_target = "custom_shed"
label_b = "_%s_" % shed_target

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

shell('cd "%s"; diff -r %s %s' % (working, label_a, label_b))
cmd = 'cd "%s"; diff -r %s %s' % (working, label_a, label_b)
if kwds["output"]:
cmd += "> '%s'" % kwds["output"]
shell(cmd)
30 changes: 30 additions & 0 deletions tests/test_shed_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
""" Integration tests for shed_diff command.
"""

import os
from .test_utils import CliShedTestCase

DIFF_LINES = [
"diff -r _local_/related_file _custom_shed_/related_file",
"< A related non-tool file (modified).",
"> A related non-tool file.",
]


class ShedUploadTestCase(CliShedTestCase):

def test_shed_diff(self):
with self._isolate_repo("single_tool") as f:
upload_command = ["shed_upload", "--force_repository_creation"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
with open(os.path.join(f, "related_file"), "w") as r_f:
r_f.write("A related non-tool file (modified).\n")

diff_command = ["shed_diff", "-o", "diff"]
diff_command.extend(self._shed_args(read_only=True))
self._check_exit_code(diff_command)
with open("diff", "r") as f:
diff = f.read()
for diff_line in DIFF_LINES:
assert diff_line in diff

0 comments on commit 965511d

Please sign in to comment.