Skip to content

Commit

Permalink
BUG: missing metadata column error not raised correctly (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizgehret authored Jan 18, 2024
1 parent 7cf7a7a commit 246f054
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
13 changes: 11 additions & 2 deletions q2cli/click/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,22 @@ def consume_value(self, ctx, opts):

def _consume_metadata(self, ctx, opts):
# double consume
# this consume deals with the metadata file
md_file, source = super().consume_value(ctx, opts)
# consume uses self.name, so mutate but backup for after
backup, self.name = self.name, self.q2_extra_dest
md_col, _ = super().consume_value(ctx, opts)
try:
# this consume deals with the metadata column
md_col, _ = super().consume_value(ctx, opts)
# If `--m-metadata-column` isn't provided, need to set md_col to None
# in order for the click.MissingParameter errors below to be raised
except click.MissingParameter:
md_col = None

self.name = backup

# These branches won't get hit unless there's a value associated with
# md_col - the try/except case above handled the situation where the
# metadata_column parameter itself wasn't provided (vs just a value)
if (md_col is None) != (md_file is None):
# missing one or the other
if md_file is None:
Expand Down
24 changes: 23 additions & 1 deletion q2cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ def test_invalid_metadata_merge(self):


class TestMetadataColumnSupport(MetadataTestsBase):
def test_required_missing(self):
# Neither md file or column params provided
def test_required_missing_file_and_column(self):
result = self._run_command(
'identity-with-metadata-column', '--i-ints', self.input_artifact,
'--o-out', self.output_artifact)
Expand All @@ -578,6 +579,27 @@ def test_required_missing(self):
self.assertTrue(result.output.startswith('Usage:'))
self.assertIn("Missing option '--m-metadata-file'", result.output)

# md file param missing, md column param & value provided
def test_required_missing_file(self):
result = self._run_command(
'identity-with-metadata-column', '--i-ints', self.input_artifact,
'--m-metadata-column', 'a', '--o-out', self.output_artifact)

self.assertEqual(result.exit_code, 1)
self.assertTrue(result.output.startswith('Usage:'))
self.assertIn("Missing option '--m-metadata-file'", result.output)

# md file param & value provided, md column param missing
def test_required_missing_column(self):
result = self._run_command(
'identity-with-metadata-column', '--i-ints', self.input_artifact,
'--m-metadata-file', self.metadata_file1,
'--o-out', self.output_artifact)

self.assertEqual(result.exit_code, 1)
self.assertTrue(result.output.startswith('Usage:'))
self.assertIn("Missing option '--m-metadata-column'", result.output)

def test_optional_metadata_missing(self):
result = self._run_command(
'identity-with-optional-metadata-column', '--i-ints',
Expand Down

0 comments on commit 246f054

Please sign in to comment.