Ejemplo n.º 1
0
 def __init__(self, output_folder=None):
     self.outputFolder = output_folder
     self.csvProcessor = CSVProcessor()
     self.timeStr = time.strftime("%Y-%m_%d-%H_%M_%S")
def test_indexing_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    assert processor[0::2] == [[0, "'str3'", 13.1], [2, "'str1'", 7.9]]
Ejemplo n.º 3
0
def test_drop_column(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    processor.drop_column(2)
    assert processor.csv == [[1, 8], [4, 5], [0, 5]]
def test_drop_columns_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])
    processor.drop_columns((0, 2))

    assert processor.csv == [["'str3'"], ["'str2'"], ["'str1'"]]
    assert processor.header == ['col2']
def test_sort_without_key(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=[int, int, int])
    processor.sort()

    assert processor.csv == [[0, 5, 7], [1, 8, 3], [4, 5, 6]]
    assert processor.header == ['col1', 'col2', 'col3']
def test_tail_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    assert processor.tail(2) == [[1, "'str2'", 6.2], [2, "'str1'", 7.9]]
def test_get_columns_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    assert processor.get_columns((0, 1)) == [[0, "'str3'"], [1, "'str2'"],
                                             [2, "'str1'"]]
Ejemplo n.º 8
0
def test_indexing(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert processor[0::2] == [[1, 8, 3], [0, 5, 7]]
Ejemplo n.º 9
0
def test_should_throw_when_column_out_of_bound(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    with pytest.raises(CSVColumnException):
        processor.get_column(6)
        processor.get_column(-1)
Ejemplo n.º 10
0
def test_get_rows_by_column_value(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert processor.get_rows_by_column_value(1, 5) == [[4, 5, 6], [0, 5, 7]]
    assert processor.get_rows_by_column_value(1, 100) == []
Ejemplo n.º 11
0
def test_casting_to_str_and_back(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert CSVProcessor(str(processor), types=(int, int, int)) == processor
Ejemplo n.º 12
0
def test_drop_columns_multiple_types(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=(int, str, float))
    processor.drop_columns((0, 1))

    assert processor.csv == [[13.1], [6.2], [7.9]]
    assert processor.header == ['col3']
Ejemplo n.º 13
0
def test_drop_columns(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))
    processor.drop_columns((0, 2))

    assert processor.csv == [[8], [5], [5]]
    assert processor.header == ['col2']
Ejemplo n.º 14
0
def test_drop_column_multiple_types(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=(int, str, float))

    processor.drop_column(2)
    assert processor.csv == [[0, "'str3'"], [1, "'str2'"], [2, "'str1'"]]
Ejemplo n.º 15
0
from csv_processor import CSVProcessor

if __name__ == '__main__':
    csv = CSVProcessor.from_file('sample.csv', types=(int, str, str, int))
    print(csv.csv)
    print(csv.get_column(1))
Ejemplo n.º 16
0
def test_instances_with_same_headers_and_data_should_be_equal(simple_int_csv):
    processor1 = CSVProcessor(simple_int_csv)
    processor2 = CSVProcessor(simple_int_csv)

    assert processor1 == processor2
def test_top_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    assert processor.top(2) == [[0, "'str3'", 13.1], [1, "'str2'", 6.2]]
Ejemplo n.º 18
0
def test_instances_with_different_data_should_not_be_equal(multiple_types_csv, simple_int_csv):
    processor1 = CSVProcessor(simple_int_csv)
    processor2 = CSVProcessor(multiple_types_csv)

    assert processor1 != processor2
def test_get_column_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    assert processor.get_column(2) == [13.1, 6.2, 7.9]
Ejemplo n.º 20
0
def test_top(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert processor.top(2) == [[1, 8, 3], [4, 5, 6]]
def test_drop_column_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])
    processor.drop_column(2)

    assert processor.csv == [[0, "'str3'"], [1, "'str2'"], [2, "'str1'"]]
    assert processor.header == ['col1', 'col2']
Ejemplo n.º 22
0
def test_tail(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert processor.tail(2) == [[4, 5, 6], [0, 5, 7]]
def test_get_rows_by_column_value_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    assert processor.get_rows_by_column_value(0, 0) == [[0, "'str3'", 13.1]]
Ejemplo n.º 24
0
def test_get_column(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert processor.get_column(2) == [3, 6, 7]
def test_casting_to_str_and_back_multi(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=[int, str, float])

    s = str(processor)
    csv_processor = CSVProcessor(s, types=(int, str, float))
    assert csv_processor == processor
Ejemplo n.º 26
0
def test_get_columns(simple_int_csv):
    processor = CSVProcessor(simple_int_csv, types=(int, int, int))

    assert processor.get_columns((1, 2)) == [[8, 3], [5, 6], [5, 7]]
def test_from_file_multi(mock_file, multiple_types_csv):
    path = 'path/to/file'
    processor_from_file = CSVProcessor.from_file(path)

    assert processor_from_file == CSVProcessor(multiple_types_csv)
Ejemplo n.º 28
0
def test_get_columns_multiple_types(multiple_types_csv):
    processor = CSVProcessor(multiple_types_csv, types=(int, str, float))

    assert processor.get_columns((1, 2)) == [["'str3'", 13.1], ["'str2'", 6.2], ["'str1'", 7.9]]