Commit d6ebc64a authored by Pierre Dittgen's avatar Pierre Dittgen

Update tests

parent 2f777b6e
......@@ -10,6 +10,11 @@ def gen_dataset(rows):
return tablib.Dataset(*rows[1:], headers=rows[0])
def err_msg_data(err):
"""Shortcut"""
return dict(err)['message-data']
ASTRONAUTS_ROWS = [
['Name', 'Country', 'Year'],
['Neil Armstrong', 'USA', 1958],
......@@ -42,7 +47,7 @@ def test_reorder_columns(astronauts_dataset):
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('USA', 1958, 'Neil Armstrong')
assert len(report) == 1
assert report[0].get('type') == 'wrong-header-order'
assert report[0].code == 'wrong-headers-order'
def test_missing_column_at_start():
......@@ -54,8 +59,8 @@ def test_missing_column_at_start():
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('', 'USA', 1958)
assert len(report) == 1
assert report[0].get('type') == 'missing-column'
assert report[0].get('data').get('column-name') == 'Name'
assert report[0].code == 'missing-header'
assert err_msg_data(report[0]).get('column-name') == 'Name'
def test_missing_column_inside():
......@@ -67,8 +72,8 @@ def test_missing_column_inside():
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('Neil Armstrong', '', 1958)
assert len(report) == 1
assert report[0].get('type') == 'missing-column'
assert report[0].get('data').get('column-name') == 'Country'
assert report[0].code == 'missing-header'
assert err_msg_data(report[0]).get('column-name') == 'Country'
def test_missing_column_at_end():
......@@ -80,8 +85,8 @@ def test_missing_column_at_end():
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('Neil Armstrong', 'USA', '')
assert len(report) == 1
assert report[0].get('type') == 'missing-column'
assert report[0].get('data').get('column-name') == 'Year'
assert report[0].code == 'missing-header'
assert err_msg_data(report[0]).get('column-name') == 'Year'
def test_empty_column_at_start():
......@@ -93,7 +98,7 @@ def test_empty_column_at_start():
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('Neil Armstrong', 'USA', 1958)
assert len(report) == 1
assert report[0].get('type') == 'empty-column'
assert report[0].code == 'blank-header'
def test_empty_column_at_end():
......@@ -105,7 +110,7 @@ def test_empty_column_at_end():
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('Neil Armstrong', 'USA', 1958)
assert len(report) == 1
assert report[0].get('type') == 'empty-column'
assert report[0].code == 'blank-header'
def test_empty_column_inside():
......@@ -117,7 +122,7 @@ def test_empty_column_inside():
assert fixed_dataset != source_dataset
assert fixed_dataset[0] == ('Neil Armstrong', 'USA', 1958)
assert len(report) == 1
assert report[0].get('type') == 'empty-column'
assert report[0].code == 'blank-header'
def test_wrong_named_column(astronauts_dataset):
......@@ -131,5 +136,5 @@ def test_wrong_named_column(astronauts_dataset):
assert fixed_dataset.headers == ['Name', 'Country', 'Year', 'Land']
assert fixed_dataset[0] == ('Neil Armstrong', '', 1958, 'USA')
assert len(report) == 2
assert any(r.get('type') == 'unknown-column' and r['data'].get('column-name') == 'Land' for r in report)
assert any(r.get('type') == 'missing-column' and r['data'].get('column-name') == 'Country' for r in report)
assert any(r.code == 'extra-header' and err_msg_data(r).get('column-name') == 'Land' for r in report)
assert any(r.code == 'missing-header' and err_msg_data(r).get('column-name') == 'Country' for r in report)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment