Skip to content

Commit 0e41a43

Browse files
Address lint and type issues
1 parent 9ed8d7b commit 0e41a43

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/dali/plugin/input/csv/crypto_com_app.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __init__(
136136
self.transaction_hash = transaction_hash
137137
self.notes = notes
138138

139-
def __str__(self):
139+
def __str__(self) -> str:
140140
return (
141141
f"CryptoComAppTransaction(timestamp={self.timestamp}, "
142142
f"description={self.description}, currency={self.currency}, "
@@ -171,10 +171,15 @@ def __init__(
171171
super().__init__(account_holder=account_holder, native_fiat=native_fiat)
172172
self.__in_csv_file: Optional[str] = in_csv_file
173173
self.__logger: logging.Logger = create_logger(self.__CRYPTO_COM_APP)
174-
self.__remove_reverted: bool = remove_reverted_transactions
174+
self.__remove_reverted: bool = False if remove_reverted_transactions is None else remove_reverted_transactions
175175

176176
def load(self, country: AbstractCountry) -> List[AbstractTransaction]:
177177
csv_transactions: List[CryptoComAppTransaction] = []
178+
179+
if not self.__in_csv_file:
180+
self.__logger.error("No input CSV file specified.")
181+
raise ValueError("Input CSV file is not specified.")
182+
178183
with open(self.__in_csv_file, encoding="utf-8") as transaction_csv_file:
179184
lines = reader(transaction_csv_file)
180185

@@ -247,6 +252,9 @@ def handle_exchange_transaction(self, transaction: CryptoComAppTransaction) -> L
247252
"""
248253
self.__logger.debug("Processing exchange transaction %s", transaction)
249254

255+
if not transaction.to_currency or not transaction.to_amount or not transaction.abs_float_to_amount:
256+
self.__logger.warning("Exchange transaction missing 'to_currency' or 'to_amount', skipping: %s", transaction)
257+
return []
250258
exchange_transactions_out: List[AbstractTransaction] = []
251259

252260
try:
@@ -361,7 +369,7 @@ def handle_in_type_transaction(self, transaction: CryptoComAppTransaction) -> In
361369
"""
362370

363371
self.__logger.debug("Processing in transaction %s", transaction)
364-
if transaction.to_currency:
372+
if transaction.to_currency and transaction.to_amount:
365373
# If there is a to_currency, we assume is a purchase from usd to the currency
366374
in_currency = transaction.to_currency
367375
crypto_in = transaction.to_amount
@@ -398,7 +406,7 @@ def handle_in_type_transaction(self, transaction: CryptoComAppTransaction) -> In
398406
notes=transaction.notes,
399407
)
400408

401-
def format_time(self, time: str):
409+
def format_time(self, time: str) -> str:
402410
"""
403411
Convert time from "MM/DD/YYYY HH:MM" format to ISO 8601 format with UTC timezone.
404412
"""

tests/test_crypto_com_app.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_load_transactions_remove_reverted(self) -> None:
2323
result = plugin.load(US())
2424
assert len(result) == 35
2525

26-
def test_handle_exchange_transaction(self):
26+
def test_handle_exchange_transaction(self) -> None:
2727
plugin = InputPlugin(
2828
account_holder="tester",
2929
in_csv_file="input/test_crypto_com_app.csv",
@@ -56,6 +56,8 @@ def test_handle_exchange_transaction(self):
5656
assert out_transaction.timestamp == "2022-06-15 21:58:00+0000"
5757
assert out_transaction.transaction_type.lower() == Keyword.SELL.value.lower()
5858
assert out_transaction.spot_price == "0.11888081892640755"
59+
assert out_transaction.crypto_out_no_fee is not None
60+
assert out_transaction.crypto_out_with_fee is not None
5961
assert RP2Decimal(out_transaction.crypto_out_no_fee) == RP2Decimal("259.8504164")
6062
assert RP2Decimal(out_transaction.crypto_out_with_fee) == RP2Decimal("259.8504164")
6163
assert out_transaction.crypto_fee == "0"
@@ -71,15 +73,16 @@ def test_handle_exchange_transaction(self):
7173
assert in_transaction.fiat_in_no_fee == "30.8912303"
7274
assert in_transaction.crypto_fee == "0"
7375

74-
def test_handle_intra_transaction(self):
76+
def test_handle_intra_transaction(self) -> None:
7577
plugin = InputPlugin(
7678
account_holder="tester",
7779
in_csv_file="input/test_crypto_com_app.csv",
7880
native_fiat="USD",
7981
)
8082

8183
transaction = CryptoComAppTransaction(
82-
raw_data="11/21/2022 22:08,Withdraw ETH (ERC20),ETH,-0.3877,USD,421.5213882,USD,421.5213882,crypto_withdrawal,0x1646a7c9f57f5f543c498f5ebff14dab16f9c9b09dbfb50405622564b8c62762",
84+
raw_data="11/21/2022 22:08,Withdraw ETH (ERC20),ETH,-0.3877,USD,421.5213882,USD,421.5213882,"
85+
"crypto_withdrawal,0x1646a7c9f57f5f543c498f5ebff14dab16f9c9b09dbfb50405622564b8c62762",
8386
time=plugin.format_time("11/21/2022 22:08"),
8487
description="Withdraw ETH (ERC20)",
8588
currency="ETH",
@@ -103,7 +106,7 @@ def test_handle_intra_transaction(self):
103106
assert RP2Decimal(result.crypto_sent) == RP2Decimal("0.3877")
104107
assert RP2Decimal(result.crypto_received) == RP2Decimal("0.3877")
105108

106-
def test_handle_in_transaction(self):
109+
def test_handle_in_transaction(self) -> None:
107110
plugin = InputPlugin(
108111
account_holder="tester",
109112
in_csv_file="input/test_crypto_com_app.csv",
@@ -134,7 +137,7 @@ def test_handle_in_transaction(self):
134137
assert result.fiat_in_no_fee == "25.0"
135138
assert result.crypto_fee == "0"
136139

137-
def test_handle_out_transaction(self):
140+
def test_handle_out_transaction(self) -> None:
138141
plugin = InputPlugin(
139142
account_holder="tester",
140143
in_csv_file="input/test_crypto_com_app.csv",
@@ -165,7 +168,7 @@ def test_handle_out_transaction(self):
165168
assert result.crypto_fee == "0"
166169
assert result.crypto_out_with_fee == "0.0259378"
167170

168-
def test_remove_ignored_transactions(self):
171+
def test_remove_ignored_transactions(self) -> None:
169172
plugin = InputPlugin(
170173
account_holder="tester",
171174
in_csv_file="input/test_crypto_com_app.csv",
@@ -201,7 +204,7 @@ def test_remove_ignored_transactions(self):
201204
assert len(result) == 1
202205
assert result[0].transaction_kind == "referral_gift"
203206

204-
def test_revert_reverted_transactions(self):
207+
def test_revert_reverted_transactions(self) -> None:
205208
plugin = InputPlugin(
206209
account_holder="tester",
207210
in_csv_file="input/test_crypto_com_app.csv",
@@ -236,7 +239,7 @@ def test_revert_reverted_transactions(self):
236239
result = plugin.remove_reverted_csv_transactions(transactions)
237240
assert len(result) == 0
238241

239-
def test_date_conversion(self):
242+
def test_date_conversion(self) -> None:
240243
# Test the date conversion from string to datetime
241244
in_date_str = "2/29/2024 6:42"
242245
expected_date = "2024-02-29T06:42:00+00:00"

0 commit comments

Comments
 (0)