forked from apache/iceberg-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_count.py
More file actions
58 lines (44 loc) · 1.96 KB
/
Copy pathtest_count.py
File metadata and controls
58 lines (44 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest
from unittest.mock import MagicMock, Mock, patch
from pyiceberg.table import DataScan
from pyiceberg.expressions import AlwaysTrue
class DummyFile:
def __init__(self, record_count):
self.record_count = record_count
class DummyTask:
def __init__(self, record_count, residual=None, delete_files=None):
self.file = DummyFile(record_count)
self.residual = residual if residual is not None else AlwaysTrue()
self.delete_files = delete_files or []
def test_count_basic():
# Create a mock table with the necessary attributes
table = Mock(spec=DataScan)
# Mock the plan_files method to return our dummy task
task = DummyTask(42, residual=AlwaysTrue(), delete_files=[])
table.plan_files = MagicMock(return_value=[task])
# Import and call the actual count method
from pyiceberg.table import DataScan as ActualDataScan
table.count = ActualDataScan.count.__get__(table, ActualDataScan)
assert table.count() == 42
def test_count_empty():
# Create a mock table with the necessary attributes
table = Mock(spec=DataScan)
# Mock the plan_files method to return no tasks
table.plan_files = MagicMock(return_value=[])
# Import and call the actual count method
from pyiceberg.table import DataScan as ActualDataScan
table.count = ActualDataScan.count.__get__(table, ActualDataScan)
assert table.count() == 0
def test_count_large():
# Create a mock table with the necessary attributes
table = Mock(spec=DataScan)
# Mock the plan_files method to return multiple tasks
tasks = [
DummyTask(500000, residual=AlwaysTrue(), delete_files=[]),
DummyTask(500000, residual=AlwaysTrue(), delete_files=[]),
]
table.plan_files = MagicMock(return_value=tasks)
# Import and call the actual count method
from pyiceberg.table import DataScan as ActualDataScan
table.count = ActualDataScan.count.__get__(table, ActualDataScan)
assert table.count() == 1000000