Skip to content
Snippets Groups Projects
Commit e9353fee authored by Stefano Borini's avatar Stefano Borini
Browse files

Tested CSV extractor for exceptions

parent 3e756a2a
No related branches found
No related tags found
1 merge request!68Introduced data value object
......@@ -9,16 +9,14 @@ class CSVExtractorDataSource(BaseDataSource):
for rowindex, row in enumerate(reader):
if rowindex < model.row:
continue
if rowindex == model.row:
elif rowindex == model.row:
return [
DataValue(
type=model.cuba_type,
value=float(row[model.column])
)
]
else:
break
raise IndexError("Could not find specified data. "
"Unexistent column.")
raise IndexError("Could not find specified data. Unexistent row.")
raise IndexError("Could not find specified data.")
......@@ -35,3 +35,20 @@ class TestCSVExtractorDataSource(unittest.TestCase):
self.assertEqual(len(result), 1)
self.assertIsInstance(result[0], DataValue)
self.assertEqual(result[0].value, 42)
def test_run_with_exception(self):
ds = CSVExtractorDataSource(self.bundle)
model = CSVExtractorModel(self.bundle)
model.filename = fixtures.get("foo.csv")
mock_params = []
model.row = 30
model.column = 5
with self.assertRaises(IndexError):
ds.run(model, mock_params)
model.row = 3
model.column = 50
with self.assertRaises(IndexError):
ds.run(model, mock_params)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment