Skip to content

Commit

Permalink
MRG: #195 from vocalpy/return-example-after-extracting-bugfix
Browse files Browse the repository at this point in the history
BUG: Make `data.get` return example after extracting, fixes #186
  • Loading branch information
NickleDave committed Jun 17, 2022
2 parents b47d87d + 14ae2b5 commit 685e703
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/crowsetta/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class instance with attributes ``annot_path``
)
if y_or_n.lower().startswith('y') or y_or_n == "":
extract_data_files(user_data_dir)
return _get_example_from_user_data_dir(format, user_data_dir)
else:
print(
"""Not extracting data. Will return a context manager.\n
Expand Down
45 changes: 44 additions & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,52 @@ def test__get_example_from_user_data_dir(format,
FORMATS_PARAMETRIZE_ARGVALUES
)
def test_get_with_extract(format,
format_class):
format_class,
monkeypatch):
"""test that ``crowsetta.data.get`` works
when we **do** extract annotation files
to the local file system
Added as a regression test,
to make sure #186 stays fixed:
https://github.com/vocalpy/crowsetta/issues/186
"""
# set up
delete_default_user_data_dir()

# this will cause the call to ``input`` in ``crowsetta.data.get``
# to return ``Yes``, so that data is extracted
monkeypatch.setattr('builtins.input', lambda _: "Yes")

example = crowsetta.data.get(format)

assert isinstance(example, crowsetta.data.ExampleAnnotFile)
assert hasattr(example, 'annot_path')
assert isinstance(example.annot_path, pathlib.Path)
assert hasattr(example, 'citation')
assert isinstance(example.citation, str)

if format_class is crowsetta.formats.bbox.Raven:
annot_instance = format_class.from_file(example.annot_path,
annot_col='Species')
elif format_class is crowsetta.formats.seq.SimpleSeq:
annot_instance = format_class.from_file(example.annot_path,
columns_map={'start_seconds': 'onset_s',
'stop_seconds': 'offset_s',
'name': 'label'},
read_csv_kwargs={'index_col': 0})
else:
annot_instance = format_class.from_file(example.annot_path)
assert isinstance(annot_instance, format_class)

@pytest.mark.parametrize(
FORMATS_PARAMETRIZE_ARGNAMES,
FORMATS_PARAMETRIZE_ARGVALUES
)
def test_get_with_extracted_already(format,
format_class):
"""test that ``crowsetta.data.get`` works
when annotation files are **already** extracted
to the local file system"""
# set up
delete_default_user_data_dir()
Expand Down

0 comments on commit 685e703

Please sign in to comment.