Пример #1
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)
Пример #2
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()
Пример #3
0
def test_run_does_nothing_if_no_data():
    tt = TableTransformer('file.txt')
    tt.extractors = [Mock(), Mock()]
    tt.read_data = Mock(return_value=None)
    tt.write_table = Mock()
    tt.run()

    tt.read_data.assert_called()
    tt.write_table.assert_not_called()
    for e in tt.extractors:
        e.extract.assert_not_called()
        e.create_table.assert_not_called()
Пример #4
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))