|
| 1 | +from collections import Iterable |
| 2 | + |
| 3 | +from exasol_udf_mock_python.group import Group, IterableWithSize |
| 4 | + |
| 5 | + |
| 6 | +def test_groups_are_equal(): |
| 7 | + group1 = Group([(1,), (2,), (3,)]) |
| 8 | + group2 = Group([(1,), (2,), (3,)]) |
| 9 | + assert group1 == group2 |
| 10 | + |
| 11 | + |
| 12 | +def test_group_prefix_equal_but_first_group_is_longer(): |
| 13 | + group1 = Group([(1,), (2,), (3,), (4,)]) |
| 14 | + group2 = Group([(1,), (2,), (3,)]) |
| 15 | + assert group1 != group2 |
| 16 | + |
| 17 | + |
| 18 | +def test_group_prefix_equal_but_second_group_is_longer(): |
| 19 | + group1 = Group([(1,), (2,), (3,)]) |
| 20 | + group2 = Group([(1,), (2,), (3,), (4,)]) |
| 21 | + assert group1 != group2 |
| 22 | + |
| 23 | + |
| 24 | +def test_group_same_length_difference_in_the_middle(): |
| 25 | + group1 = Group([(1,), (2,), (5,), (4,)]) |
| 26 | + group2 = Group([(1,), (2,), (3,), (4,)]) |
| 27 | + assert group1 != group2 |
| 28 | + |
| 29 | + |
| 30 | +def test_group_has_tuple_as_iterable_but_rows_is_list(): |
| 31 | + group = Group(((1,), (2,), (5,), (4,))) |
| 32 | + assert group.rows == [(1,), (2,), (5,), (4,)] |
| 33 | + |
| 34 | + |
| 35 | +def test_group_len(): |
| 36 | + group = Group(((1,), (2,), (5,), (4,))) |
| 37 | + assert len(group) == 4 |
| 38 | + |
| 39 | + |
| 40 | +def test_group_iter(): |
| 41 | + group = Group(((1,), (2,), (5,), (4,))) |
| 42 | + assert list(iter(group)) == [(1,), (2,), (5,), (4,)] |
| 43 | + |
| 44 | + |
| 45 | +class MyIterable(Iterable): |
| 46 | + def __iter__(self): |
| 47 | + return iter([(1,), (2,), (3,)]) |
| 48 | + |
| 49 | + |
| 50 | +def test_group_with_custom_iterable_rows(): |
| 51 | + group = Group(MyIterable()) |
| 52 | + assert group.rows == [(1,), (2,), (3,)] |
| 53 | + |
| 54 | + |
| 55 | +def test_group_with_custom_iterable_len(): |
| 56 | + group = Group(MyIterable()) |
| 57 | + assert len(group) == 3 |
| 58 | + |
| 59 | + |
| 60 | +def test_group_with_iterable_with_size_len(): |
| 61 | + class MyIterableWithSize(IterableWithSize): |
| 62 | + def __iter__(self): |
| 63 | + raise Exception("The group should use __len__ instead of __iter__ to determine the length") |
| 64 | + |
| 65 | + def __len__(self): |
| 66 | + return 3 |
| 67 | + |
| 68 | + group = Group(MyIterableWithSize()) |
| 69 | + assert len(group) == 3 |
0 commit comments