Skip to content

Commit

Permalink
Importer logs warning if no data could be imported
Browse files Browse the repository at this point in the history
  • Loading branch information
tillbiskup committed Dec 12, 2024
1 parent 635be8a commit af6d9cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0.dev53
0.12.0.dev54
3 changes: 2 additions & 1 deletion aspecd/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ def import_into(self, dataset=None):
else:
self.dataset = dataset
self._import()
# Untested due to lack of ideas how to test
if self.dataset.data.data.size == 0:
logger.warning('Could not read data from "%s"', self.source)
# pylint: disable=protected-access
self.dataset._origdata = copy.deepcopy(self.dataset.data)
self.dataset.id = self.source
Expand Down
22 changes: 22 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ def test_import_into_does_not_override_label(self):
self.importer.import_into(test_dataset)
self.assertEqual("foobar", test_dataset.label)

def test_import_copies_data_to_origdata(self):
class MockImporter(io.DatasetImporter):
def _import(self):
self.dataset.data.data = np.ones(5)

test_dataset = dataset.Dataset()
importer = MockImporter()
importer.source = "foobar"
importer.import_into(test_dataset)
np.testing.assert_array_equal(
test_dataset.data.data, test_dataset._origdata.data
)

def test_import_with_no_data_read_logs_warning(self):
test_dataset = dataset.Dataset()
self.importer.source = "/path/to/filename.ext"
with self.assertLogs(__package__, level="WARN") as cm:
self.importer.import_into(test_dataset)
self.assertIn(
f'Could not read data from "{self.importer.source}"', cm.output[0]
)


class TestDatasetExporter(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit af6d9cf

Please sign in to comment.