Beispiel #1
0
def test_excluded_logging(empty_app, caplog, activation_state):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path('excluded_logging.xlsx')
    config_path = get_test_data_path('excluded_' + activation_state + '_logging.json')
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
    assert 2 in data
    assert data[2]['Enum'] == 'ape'
    assert 3 not in data
    assert 4 in data
    assert data[4]['Enum'] == 'cat'
    assert 'The row 3 was excluded due to an exclude filter on cell B3 (dog not in [ape, cat])' in caplog.text

    if sys.version.startswith('2.7'):
        str_type = 'unicode'
        type_class = 'type'
    elif sys.version.startswith('3'):
        str_type = 'str'
        type_class = 'class'
    else:
        raise RuntimeError('This test case does only support Python 2.7 and 3.x')

    msg1 = "The value Text in cell A3 is of type <{0} '{1}'>; required by specification " \
           "is datetime".format(type_class, str_type)
    msg2 = "The 'Text' in cell E3 is empty"
    if activation_state == 'enable':
        assert msg1 in caplog.text
        assert msg2 in caplog.text
    else:
        assert msg1 not in caplog.text
        assert msg2 not in caplog.text
Beispiel #2
0
def test_matrix_row_based_positive(empty_app, path):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path(path)
    config_path = get_test_data_path('config_row_based_position_mix.json')
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
    assert len(data) == 3
    assert data[2]['Text'] == 'Text 1'
    assert data[2]['Integer'] == -2
    assert data[4]['Text'] == 'Text 3'
    assert data[4]['Integer'] == 30
Beispiel #3
0
def test_filtering(empty_app, caplog, orientation):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path(orientation + '.xlsx')
    config_path = get_test_data_path(orientation + '.json')
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
    assert 2 in data
    assert data[2]['Enum'] == 'ape'
    assert 3 not in data
    assert 4 in data
    assert data[4]['Enum'] == 'cat'
    if orientation == 'column_based':
        assert 'The row 3 was excluded due to an exclude filter on cell B3 (dog not in [ape, cat])' in caplog.text
    else:
        assert 'The column 3 was excluded due to an exclude filter on cell C2 (dog not in [ape, cat])' in caplog.text
def test_data_types(empty_app, path):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path(path)
    config_path = get_test_data_path('config.json')
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
    assert data[2]['Date'] == datetime.datetime(year=2017, month=8, day=20)
    assert data[3]['Date'] == datetime.datetime(year=2018, month=9, day=21)
    assert data[2]['Enum'] == 'ape'
    assert data[3]['Enum'] == 'dog'
    assert data[2]['Float'] == 1.1
    assert data[3]['Float'] == 22.22
    assert data[2]['Integer'] == -2
    assert data[3]['Integer'] == 0
    assert data[2]['Text'] == 'Text 1'
    assert data[3]['Text'] == 'Text 2'
def test_workbook_not_exist(empty_app):
    plugin = EmptyPlugin(empty_app)
    workbook_path = 'not_exist.xlsx'
    config_path = get_test_data_path('config.json')
    if sys.version.startswith('2.7'):
        with pytest.raises(IOError):
            plugin.excel_validation.read_excel(config_path, workbook_path)
    elif sys.version.startswith('3'):
        with pytest.raises(FileNotFoundError):
            plugin.excel_validation.read_excel(config_path, workbook_path)
    else:
        pytest.fail("Test does only support Python versions 2.7 and 3.x")
Beispiel #6
0
def test_excluded_fail_on_errors(empty_app, path, config):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path(path)
    config_path = get_test_data_path(config)
    with pytest.raises(ValueError):
        plugin.excel_validation.read_excel(config_path, workbook_path)
Beispiel #7
0
def test_sheet_last(empty_app):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path('sheets.xlsx')
    config_path = get_test_data_path('config_sheet_last.json')
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
    assert data[2]['Text'] == "sheet_last"
Beispiel #8
0
def test_sheet_name_not_exist(empty_app):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path('sheets.xlsx')
    config_path = get_test_data_path('config_sheet_name_not_exist.json')
    with pytest.raises(KeyError):
        plugin.excel_validation.read_excel(config_path, workbook_path)
Beispiel #9
0
def test_sheet_byIndex_out_of_range(empty_app):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path('sheets.xlsx')
    config_path = get_test_data_path('config_sheet_index_out_of_range.json')
    with pytest.raises(IndexError):
        plugin.excel_validation.read_excel(config_path, workbook_path)
Beispiel #10
0
def test_matrix_column_based_errors(empty_app, config_json):
    plugin = EmptyPlugin(empty_app)
    workbook_path = get_test_data_path('column_based.xlsx')
    config_path = get_test_data_path(config_json)
    with pytest.raises(ValueError):
        plugin.excel_validation.read_excel(config_path, workbook_path)