-
Notifications
You must be signed in to change notification settings - Fork 44
/
test_large_input.py
164 lines (140 loc) · 5.52 KB
/
test_large_input.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Copyright 2021 eprbell
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import shutil
import unittest
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, List
import ezodf
from abstract_test_ods_output_diff import AbstractTestODSOutputDiff, OutputPlugins
from dateutil.tz import gettz
from rp2.rp2_error import RP2RuntimeError
ROOT_PATH: Path = Path(os.path.dirname(__file__)).parent.absolute()
class TestLargeInput(AbstractTestODSOutputDiff):
output_dir: Path
@classmethod
def setUpClass(cls) -> None:
cls.output_dir = ROOT_PATH / Path("output") / Path(cls.__module__)
shutil.rmtree(cls.output_dir, ignore_errors=True)
cls._generate_large_input(cls.output_dir)
for method in AbstractTestODSOutputDiff.METHODS:
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_large_input", config="test_large_input", method=method, input_path=cls.output_dir
)
def setUp(self) -> None:
self.maxDiff = None # pylint: disable=invalid-name
@staticmethod
def _fill_row(sheet: Any, row_index: int, row: List[Any]) -> int:
for col_index, element in enumerate(row):
sheet[row_index, col_index].set_value(element)
return row_index + 1
@classmethod
def _generate_large_input(cls, output_dir: Path) -> None:
output_file_path: Path = output_dir / Path("test_large_input.ods")
if not output_dir.exists():
output_dir.mkdir(parents=True)
if not output_dir.is_dir():
raise RP2RuntimeError(f"output_dir '{str(output_dir)}' exists but it's not a directory")
output_file: Any = ezodf.newdoc("ods", str(output_file_path), template=None)
row_index: int = 0
timestamp: datetime = datetime(2015, 1, 1, 1, 1, 1, 0, tzinfo=gettz("UTC"))
asset: str = "B1"
exchanges: List[str] = ["Coinbase", "Kraken"]
holders: List[str] = ["Alice", "Bob"]
in_type: List[str] = ["buy", "interest"]
out_type: List[str] = ["sell", "donate"]
column_total: int = 30
table_row_total: int = 200 if "RP2_TEST_TABLE_SIZE" not in os.environ else int(str(os.environ.get("RP2_TEST_TABLE_SIZE")))
sheet: Any = ezodf.Table("B1")
output_file.sheets += sheet
sheet.reset(size=(table_row_total * 2 + 100, column_total))
row_index = cls._fill_row(sheet, row_index, ["IN"])
row_index = cls._fill_row(
sheet,
row_index,
[
"timestamp",
"asset",
"exchange",
"holder",
"type",
"spot",
"crypto in",
"fiat fee",
"notes",
],
)
for i in range(0, table_row_total):
row_index = cls._fill_row(
sheet,
row_index,
[
timestamp,
asset,
exchanges[int(i / 5) % 2],
holders[int(i / 10) % 2],
in_type[int(i / 10) % 2],
float(1 + i % 10) / 10,
1 + i % 5,
0,
],
)
if i < table_row_total * 0.93:
timestamp += timedelta(minutes=1)
row_index = cls._fill_row(sheet, row_index, ["TABLE END"])
row_index = cls._fill_row(sheet, row_index, [""])
row_index = cls._fill_row(sheet, row_index, ["OUT"])
row_index = cls._fill_row(
sheet,
row_index,
[
"timestamp",
"asset",
"exchange",
"holder",
"type",
"spot",
"crypto out",
"crypto fee",
"notes",
],
)
for i in range(0, table_row_total):
row_index = cls._fill_row(
sheet,
row_index,
[
timestamp,
asset,
exchanges[int(i / 5) % 2],
holders[int(i / 10) % 2],
out_type[int(i / 10) % 2],
float(1 + i % 10) / 10,
float(1 + i % 10) / 20,
0,
],
)
if i < table_row_total * 0.80:
timestamp += timedelta(minutes=1)
row_index = cls._fill_row(sheet, row_index, ["TABLE END"])
output_file.save()
def test_large_input_rp2_full_report(self) -> None:
for method in self.METHODS:
self._compare(output_dir=self.output_dir, test_name="test_large_input", method=method, output_plugin=OutputPlugins.RP2_FULL_REPORT)
def test_large_input_tax_report_us(self) -> None:
for method in self.METHODS:
self._compare(output_dir=self.output_dir, test_name="test_large_input", method=method, output_plugin=OutputPlugins.TAX_REPORT_US)
if __name__ == "__main__":
unittest.main()