Passed
Push — mpeta ( 1841cb...62640f )
by Konstantinos
03:46
created

tests.test_datapoints   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_table_dimensions() 0 40 1
A test_data() 0 11 1
1
import pytest
2
from collections import Counter
3
4
5
@pytest.fixture(params=[
6
    ['data_1'],
7
    ['data_2'],
8
])
9
def test_data(request, somagic, datapoint_files_to_test, read_observations):
10
    test_datapoints_json_file = datapoint_files_to_test[request.param[0]]['data_path']
11
    read_observations(somagic, test_datapoints_json_file)
12
    return type('T', (object,), {
13
        'dataset': somagic.dataset,
14
        'expected_data': datapoint_files_to_test[request.param[0]],
15
        'expected_dataset_name': test_datapoints_json_file,
16
    })
17
18
19
def test_table_dimensions(test_data):
20
    assert test_data.dataset.name == test_data.expected_dataset_name
21
    assert len(test_data.dataset.datapoints) == test_data.dataset.datapoints.nb_rows == test_data.expected_data['nb_rows']
22
    assert test_data.dataset.datapoints.nb_columns == test_data.expected_data['nb_columns']
23
    assert tuple(test_data.dataset.datapoints.attributes) == test_data.expected_data['column_names']
24
    
25
    assert all([Counter([type(x) for x in test_data.dataset.datapoints.column(k)]) ==
26
                Counter(v) for k, v in test_data.expected_data['type_distros'].items()])
27
28
    assert all([Counter([x for x in test_data.dataset.datapoints.column(k)]) ==
29
                Counter(v) for k, v in test_data.expected_data['value_distros'].items()])
30
31
    # Uncomment below to debug the complex assert statement with triple all, below
32
    # print()
33
    # for row, v in test_data.expected_data['row'].items():
34
    #     print('ROW', row)
35
    #     for j, (column, value) in enumerate(v.items()):
36
    #         print(j, 'Column:', column, 'Value:', value)
37
    #         for k, condition in enumerate(value):
38
    #             print('Condition index:', k)
39
    #             assert condition(test_data.dataset.datapoints.row(row)[column])
40
    
41
42
    # for i, v in enumerate(test_data.dataset.datapoints.column('flavors')):
43
    #     print('I:', i)
44
    #     if i < 76:
45
    #         assert type(v) == list
46
    #     if i == 76:
47
    #         # assert type(v) == list
48
    #         assert type(v) == type(None)
49
    #     if i > 76 and i < 87:
50
    #         assert type(v) == list
51
    #     if i == 87:
52
    #         # assert type(v) == list
53
    #         assert type(v) == type(None)
54
    #     if i > 87:
55
    #         assert type(v) == list
56
57
    assert all([all([all([condition(test_data.dataset.datapoints.row(row)[column]) for condition in value])
58
                     for column, value in v.items()]) for row, v in test_data.expected_data['row'].items()])
59