Skip to content

Commit

Permalink
Fix tests to be more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed May 14, 2018
1 parent 891c7cc commit 831583c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
46 changes: 24 additions & 22 deletions tests/test_shed_upload.py
Expand Up @@ -13,6 +13,7 @@
from .test_utils import (
assert_exists,
CliShedTestCase,
test_environ,
TEST_REPOS_DIR,
)

Expand Down Expand Up @@ -130,28 +131,29 @@ def test_tar_from_git(self):

def test_upload_from_git(self):
with self._isolate() as f:
dest = join(f, "single_tool")
self._copy_repo("single_tool", dest)
shell(" && ".join([
"cd %s" % dest,
"git init",
"git add .",
"git commit -m 'initial commit'"
]))
rev = git.rev(None, "single_tool")
upload_command = [
"shed_update", "--force_repository_creation",
"git+single_tool/.git"
]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
self._verify_single_uploaded(f, ["single_tool"])
model = self.mock_shed.model
repo_id = self.repository_by_name("single_tool")["id"]
message = model._repositories_msg[repo_id][0]
assert "planemo upload for repository " in message
assert "repository https://github.com/galaxyproject" in message
assert rev in message
with test_environ({"GIT_AUTHOR_NAME": "planemo developer", "EMAIL": "planemo@galaxyproject.org"}):
dest = join(f, "single_tool")
self._copy_repo("single_tool", dest)
shell(" && ".join([
"cd %s" % dest,
"git init",
"git add .",
"git commit -m 'initial commit'"
]))
rev = git.rev(None, "single_tool")
upload_command = [
"shed_update", "--force_repository_creation",
"git+single_tool/.git"
]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
self._verify_single_uploaded(f, ["single_tool"])
model = self.mock_shed.model
repo_id = self.repository_by_name("single_tool")["id"]
message = model._repositories_msg[repo_id][0]
assert "planemo upload for repository " in message
assert "repository https://github.com/galaxyproject" in message
assert rev in message

def test_create_and_upload(self):
with self._isolate_repo("single_tool") as f:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_utils.py
Expand Up @@ -225,6 +225,29 @@ def target_galaxy_branch():
return os.environ.get("PLANEMO_TEST_GALAXY_BRANCH", "master")


# Taken from Galaxy's test/unit/tools/test_tool_deps.py
@contextlib.contextmanager
def test_environ(values, remove=[]):
"""
Modify the environment for a test, adding/updating values in dict `values` and
removing any environment variables mentioned in list `remove`.
"""
new_keys = set(values.keys()) - set(os.environ.keys())
old_environ = os.environ.copy()
try:
os.environ.update(values)
for to_remove in remove:
try:
del os.environ[remove]
except KeyError:
pass
yield
finally:
os.environ.update(old_environ)
for key in new_keys:
del os.environ[key]


def test_context():
context = cli.Context()
context.planemo_directory = "/tmp/planemo-test-workspace"
Expand Down

0 comments on commit 831583c

Please sign in to comment.