Skip to content

Commit

Permalink
[backend] Set default category if none is provided
Browse files Browse the repository at this point in the history
The default category is now set to the first category listed in the backend's
`CATEGORIES` list. This change is necessary to accommodate the removal of
backend-specific `fetch` methods, which previously handled category assignment.

Updated the tests to validate the default and specific category assignments,
and removed the obsolete `test_fetch_archive_needs_category`.

Signed-off-by: Venu Vardhan Reddy Tekula <vt2182@nyu.edu>
  • Loading branch information
vchrombie committed Sep 3, 2024
1 parent 13fc18c commit 603f1ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
4 changes: 2 additions & 2 deletions perceval/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,9 @@ def parse(self, *args):
"""
parsed_args = self.parser.parse_args(args)

# Category was not set, remove it
# Ensure category is set
if parsed_args.category is None:
delattr(parsed_args, 'category')
parsed_args.category = self._backend.CATEGORIES[0]

if self._from_date:
parsed_args.from_date = str_to_datetime(parsed_args.from_date)
Expand Down
21 changes: 7 additions & 14 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,26 +1093,19 @@ def test_incompatible_fetch_archive_and_no_archive(self):
with self.assertRaises(AttributeError):
_ = parser.parse(*args)

def test_fetch_archive_needs_category(self):
"""Test if fetch-archive needs a category"""

args = ['--fetch-archive']
parser = BackendCommandArgumentParser(MockedBackendCommand.BACKEND,
archive=True)

with self.assertRaises(AttributeError):
_ = parser.parse(*args)

def test_remove_empty_category(self):
"""Test whether category argument is removed when no value is given"""
def test_default_category(self):
"""Test whether a default category is set if none is provided"""

# No category is provided
args = []
parser = BackendCommandArgumentParser(MockedBackendCommand.BACKEND,
archive=True)
parsed_args = parser.parse(*args)

with self.assertRaises(AttributeError):
_ = parsed_args.category
self.assertEqual(parsed_args.category, MockedBackendCommand.BACKEND.DEFAULT_CATEGORY)

def test_specific_category(self):
"""Test whether a specific category is set when provided"""

# An empty string is parsed
args = ['--category', '']
Expand Down

0 comments on commit 603f1ab

Please sign in to comment.