Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Oddant1 committed May 28, 2024
1 parent 5b53bd6 commit 6ccbc15
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
10 changes: 5 additions & 5 deletions q2cli/core/artifact_cache_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ def set_used_artifact_cache(args):

# They need to provide some kind of arg to use_cache
if len(args) < use_cache_idx + 2:
exc = ValueError("--use-cache expected an argument but none was "
"provided.")
exc = ValueError('--use-cache expected an argument but none was '
'provided.')
exit_with_error(exc)

cache_path = args[use_cache_idx + 1]

# The arg given should be a path that points to an existing cache
if not Cache.is_cache(cache_path):
exc = ValueError("--use-cache expected a path to an existing cache as "
f"an argument but received {cache_path} which is not "
"a path to an existing cache.")
exc = ValueError('--use-cache expected a path to an existing cache as '
f"an argument but received '{cache_path}' which is "
'not a path to an existing cache.')
exit_with_error(exc)

USED_ARTIFACT_CACHE = Cache(cache_path)
Expand Down
35 changes: 32 additions & 3 deletions q2cli/tests/test_cache_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def test_output_dir_as_cache(self):

self.assertEqual(result.exit_code, 1)
self.assertIn(
'Cache keys cannot be used as output dirs.', str(result.exception))
'Cache keys cannot be used as output dirs.', result.output)

def test_parallel(self):
output = os.path.join(self.tempdir, 'output')
Expand Down Expand Up @@ -935,10 +935,39 @@ def test_parallel_flags_on_non_pipeline(self):
self.assertIn('No such option: --parallel-config', result.output)

def test_no_cache_arg(self):
pass
art_path = os.path.join(self.tempdir, 'art:1.qza')
self.art1.save(art_path)

left_path = os.path.join(self.tempdir, 'left.qza')
right_path = os.path.join(self.tempdir, 'right.qza')

result = self._run_command(
'split-ints', '--i-ints', art_path, '--o-left', left_path,
'--o-right', right_path, '--verbose', '--use-cache'
)

self.assertEqual(result.exit_code, 1)
self.assertIn(
'--use-cache expected an argument but none was provided.',
result.output)

def test_cache_arg_invalid(self):
pass
art_path = os.path.join(self.tempdir, 'art:1.qza')
self.art1.save(art_path)

left_path = os.path.join(self.tempdir, 'left.qza')
right_path = os.path.join(self.tempdir, 'right.qza')

# The path to our artifact is definitely not a cache
result = self._run_command(
'split-ints', '--i-ints', art_path, '--o-left', left_path,
'--o-right', right_path, '--verbose', '--use-cache', art_path
)

self.assertEqual(result.exit_code, 1)
self.assertIn(
f"received '{art_path}' which is not a path to an existing cache",
result.output)

def _load_alias_execution_contexts(self, collection):
execution_contexts = []
Expand Down

0 comments on commit 6ccbc15

Please sign in to comment.