Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: missing metadata column error not raised correctly #329

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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