Skip to content

Commit

Permalink
Use new key validator (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oddant1 authored Apr 24, 2024
1 parent d006faa commit dce4a7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions q2cli/tests/test_cache_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,16 @@ def test_output_key_invalid(self):
art2_path = str(self.cache.path) + ':art2'
art3_path = str(self.cache.path) + ':art3'

out_path = str(self.cache.path) + ':not_valid_identifier$&;'

invalid = 'not_valid_identifier$&;'
out_path = str(self.cache.path) + ':' + invalid
result = self._run_command(
'concatenate-ints', '--i-ints1', art1_path, '--i-ints2', art2_path,
'--i-ints3', art3_path, '--p-int1', '9', '--p-int2', '10',
'--o-concatenated-ints', out_path, '--verbose'
)

self.assertEqual(result.exit_code, 1)
self.assertIn('Keys must be valid Python identifiers',
self.assertIn(f"Key '{invalid}' is not a valid Python identifier",
str(result.exception))

def test_artifact_as_metadata_cache(self):
Expand Down
10 changes: 2 additions & 8 deletions q2cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ def output_in_cache(fp):

try:
if Cache.is_cache(cache_path):
if not key.isidentifier():
raise ValueError(
f"Key '{key}' is not a valid Python identifier. Keys must "
"be valid Python identifiers. Python identifier rules may "
"be found here https://www.askpython.com/python/"
"python-identifiers-rules-best-practices")
else:
return True
Cache.validate_key(key)
return True
except FileNotFoundError as e:
# If cache_path doesn't exist, don't treat this as a cache output
if 'No such file or directory' in str(e):
Expand Down

0 comments on commit dce4a7e

Please sign in to comment.