How to use the goodtables.cells.create_cell function in goodtables

To help you get started, we’ve selected a few goodtables examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frictionlessdata / goodtables-py / tests / checks / test_extra_header.py View on Github external
def test_check_extra_header_infer_with_empty_data(log):
    cells = [
        goodtables.cells.create_cell('name1', field=Field({'name': 'name1'}), column_number=1),
        goodtables.cells.create_cell('name2', column_number=2),
    ]
    sample = [
        ['123', ''],
        ['456', ''],
        ['789', ''],
    ]
    extra_header = ExtraHeader(infer_fields=True)
    errors = extra_header.check_headers(cells, sample=sample)
    assert log(errors) == []
    assert len(cells) == 2
    assert cells[1]['field'].name == 'name2'
    assert cells[1]['field'].type == 'string'
github frictionlessdata / goodtables-py / tests / checks / test_type_or_format_error.py View on Github external
def test_check_type_or_format_error(log):
    field = Field({'name': 'name', 'type': 'integer'})
    cells = [
        goodtables.cells.create_cell('name1', '1', field, column_number=1)
    ]
    errors = type_or_format_error(cells)
    assert log(errors) == []
    assert len(cells) == 1
github frictionlessdata / goodtables-py / tests / checks / test_non_matching_header.py View on Github external
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
github frictionlessdata / goodtables-py / tests / checks / test_extra_value.py View on Github external
def test_check_extra_value_problem(log):
    cells = [
        goodtables.cells.create_cell('name1', 'value', row_number=1, column_number=1),
        goodtables.cells.create_cell(None, 'value', row_number=1, column_number=2),
    ]
    extra_value = ExtraValue()
    errors = extra_value.check_row(cells)
    assert log(errors) == [
        (1, 2, 'extra-value'),
    ]
    assert len(cells) == 1
github frictionlessdata / goodtables-py / tests / test_cells.py View on Github external
def test_create_header_cells(self):
        # Header cells are cells that have no value
        # (The value becomes the header's value)
        headers = [
            'name',
            'value',
        ]
        schema_fields = [
            'name_schema',
            'value_schema',
        ]

        cells = goodtables.cells.create_cells(headers, schema_fields)
        expected_cells = [
            goodtables.cells.create_cell('name', 'name', 'name_schema', 1),
            goodtables.cells.create_cell('value', 'value', 'value_schema', 2),
        ]

        assert cells == expected_cells
github frictionlessdata / goodtables-py / tests / checks / test_missing_header.py View on Github external
def test_check_missing_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),
    ]
    errors = missing_header(cells, None)
    assert log(errors) == []
    assert len(cells) == 2
github frictionlessdata / goodtables-py / tests / checks / test_duplicate_header.py View on Github external
def test_check_duplicate_headers_show_all_duplicates_except_the_first():
    cells = [
        goodtables.cells.create_cell('name', column_number=1),
        goodtables.cells.create_cell('name', column_number=2),
        goodtables.cells.create_cell('name', column_number=3),
    ]
    errors = duplicate_header(cells)

    assert '1, 3' in errors[0].message
    assert '1, 2' in errors[1].message
github frictionlessdata / goodtables-py / tests / checks / test_extra_header.py View on Github external
def test_check_extra_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),
    ]
    sample = []
    extra_header = ExtraHeader()
    errors = extra_header.check_headers(cells, sample=sample)
    assert log(errors) == []
    assert len(cells) == 2
github frictionlessdata / goodtables-py / tests / checks / test_non_matching_header.py View on Github external
def test_check_non_matching_header_problem(log):
    cells = [
        goodtables.cells.create_cell('name1', field=Field({'name': 'name2'}), 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()
    errors = non_matching_header.check_headers(cells)
    assert log(errors) == [
        (None, 1, 'non-matching-header'),
        (None, 2, 'non-matching-header'),
    ]
    assert len(cells) == 1
github frictionlessdata / goodtables-py / tests / checks / test_non_matching_header.py View on Github external
def test_check_non_matching_header_order_fields(log):
    cells = [
        goodtables.cells.create_cell('name1', field=Field({'name': 'name2'}), 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) == []
    # A new header cell will be added by the non-matching-header check because
    # there is no field for the "name3" header
    assert len(cells) == 4