Beispiel #1
0
def test_read_data_path_is_dir(mock_open):
    mock_open.side_effect = IsADirectoryError()
    tt = TableTransformer('file.txt')
    tt.logger = Mock()
    output = tt.read_data()

    mock_open.assert_called()
    tt.logger.error.assert_called()
    assert output is None
Beispiel #2
0
def test_read_data_file_not_found(mock_open):
    mock_open.side_effect = FileNotFoundError()
    tt = TableTransformer('file.txt')
    tt.logger = Mock()
    output = tt.read_data()

    mock_open.assert_called()
    tt.logger.error.assert_called()
    assert output is None
Beispiel #3
0
def test_run_catches_FileExistsError():
    tt = TableTransformer('file.txt')
    tt.extractors = [Mock(), Mock()]
    tt.logger = Mock()
    tt.read_data = Mock()
    tt.write_table = Mock(side_effect=FileExistsError('error'))
    tt.run()

    assert len(tt.logger.error.call_args_list) == len(tt.extractors)
Beispiel #4
0
def test_run_does_nothing_if_no_extractor():
    tt = TableTransformer('file.txt')
    tt.extractors = []
    tt.logger = Mock()
    tt.read_data = Mock()
    tt.write_table = Mock()
    tt.run()

    tt.read_data.assert_not_called()
    tt.write_table.assert_not_called()
    tt.logger.error.assert_called()
Beispiel #5
0
def test_run():
    tt = TableTransformer('file.txt')
    tt.extractors = [Mock(), Mock()]
    tt.logger = Mock()
    tt.read_data = Mock()
    tt.write_table = Mock()
    tt.output_template = Mock()
    tt.run()

    for e in tt.extractors:
        e.extract.assert_called_once()
        e.create_table.assert_called_once()
    tt.read_data.assert_called_once()
    assert len(tt.write_table.call_args_list) == len(tt.extractors)
    assert (len(tt.output_template.substitute.call_args_list) == len(
        tt.extractors))