Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_non_matching_header_order_fields_problem(log):
cells = [
goodtables.cells.create_cell('name1', field=Field({'name': 'name4'}), column_number=1),
goodtables.cells.create_cell('name2', field=Field({'name': 'name1'}), column_number=2),
goodtables.cells.create_cell('name3', column_number=3),
]
non_matching_header = NonMatchingHeader(order_fields=True)
errors = non_matching_header.check_headers(cells)
assert log(errors) == [
(None, 2, 'non-matching-header'),
]
# New header cells will be added by the non-matching-header check because
# there are no fields for the "name2" and "name3" headers
assert len(cells) == 4
def test_truncated_values(value):
cell = goodtables.cells.create_cell('value', value)
errors = TruncatedValue().check_row([cell])
assert len(errors) == 1
assert errors[0].code == 'truncated-value'
def test_check_blank_header_problem(log):
errors = []
cells = [
goodtables.cells.create_cell('', column_number=1),
]
errors = blank_header(cells)
assert log(errors) == [
(None, 1, 'blank-header'),
]
assert len(cells) == 1
def test_check_blank_row_problem(log):
cells = [
goodtables.cells.create_cell('name1', '', row_number=1),
]
errors = blank_row(cells)
assert log(errors) == [
(1, None, 'blank-row'),
]
assert len(cells) == 0
def test_check_missing_header_problem(log):
cells = [
goodtables.cells.create_cell('name1', field=Field({'name': 'name1'}), column_number=1),
goodtables.cells.create_cell(None, field=Field({'name': 'name2'}), column_number=2),
]
errors = missing_header(cells, None)
assert log(errors) == [
(None, 2, 'missing-header'),
]
assert len(cells) == 1
def test_check_extra_value(log):
cells = [
goodtables.cells.create_cell('name1', 'value'),
goodtables.cells.create_cell('name2', 'value'),
]
extra_value = ExtraValue()
errors = extra_value.check_row(cells)
assert log(errors) == []
assert len(cells) == 2
def test_check_non_matching_header(log):
cells = [
goodtables.cells.create_cell('name1', field=Field({'name': 'name1'}), column_number=1),
goodtables.cells.create_cell('name2', field=Field({'name': 'name2'}), column_number=2),
goodtables.cells.create_cell('name3', column_number=3),
]
non_matching_header = NonMatchingHeader()
errors = non_matching_header.check_headers(cells)
assert log(errors) == []
assert len(cells) == 3
def test_check_truncated_value_with_dates():
# There was a bug where we didn't catch the correct exception when calling
# int(date)
cell = goodtables.cells.create_cell(
'date',
datetime.datetime.now()
)
errors = TruncatedValue().check_row([cell])
assert not errors
def test_check_duplicate_header(log):
cells = [
goodtables.cells.create_cell('name1', column_number=1),
goodtables.cells.create_cell('name2', column_number=2),
]
errors = duplicate_header(cells)
assert log(errors) == []
assert len(cells) == 2