From 14db355f4cf75828d465c41e76053a9fc6fad63a Mon Sep 17 00:00:00 2001 From: Christopher Whelan Date: Fri, 7 Jun 2024 00:23:26 -0700 Subject: [PATCH] Minimal rename of internal_id_int to row --- src/rp2/abstract_transaction.py | 10 +-- src/rp2/in_transaction.py | 4 +- src/rp2/intra_transaction.py | 4 +- src/rp2/ods_parser.py | 6 +- src/rp2/out_transaction.py | 4 +- src/rp2/plugin/accounting_method/hifo.py | 2 +- src/rp2/plugin/accounting_method/lifo.py | 2 +- tests/test_balance.py | 12 ++-- tests/test_gain_loss.py | 14 ++-- tests/test_gain_loss_set.py | 28 ++++---- tests/test_in_transaction.py | 87 ++++++++++++------------ tests/test_input_parser.py | 30 ++++---- tests/test_intra_transaction.py | 81 +++++++++++----------- tests/test_out_transaction.py | 83 +++++++++++----------- tests/test_tax_engine.py | 2 +- tests/test_transaction_set.py | 24 ++++--- 16 files changed, 200 insertions(+), 193 deletions(-) diff --git a/src/rp2/abstract_transaction.py b/src/rp2/abstract_transaction.py index 707e50f4..0aea4fc0 100644 --- a/src/rp2/abstract_transaction.py +++ b/src/rp2/abstract_transaction.py @@ -30,7 +30,7 @@ def __init__( asset: str, transaction_type: str, spot_price: RP2Decimal, - internal_id: Optional[int] = None, + row: Optional[int] = None, unique_id: Optional[str] = None, notes: Optional[str] = None, ) -> None: @@ -39,7 +39,9 @@ def __init__( self.__timestamp: datetime = configuration.type_check_timestamp_from_string("timestamp", timestamp) self.__transaction_type: TransactionType = TransactionType.type_check_from_string("transaction_type", transaction_type) self.__spot_price: RP2Decimal = configuration.type_check_positive_decimal("spot_price", spot_price) - self.__internal_id: int = configuration.type_check_internal_id("internal_id", internal_id) if internal_id is not None else id(self) + # TODO: the fallback case does not semantically match "row", make non-optional # pylint: disable=fixme + self.__row: int = configuration.type_check_internal_id("row", row) if row is not None else id(self) + self.__internal_id: int = self.__row self.__unique_id: str = configuration.type_check_string_or_integer("unique_id", unique_id) if unique_id is not None else "" self.__notes = configuration.type_check_string("notes", notes) if notes else "" @@ -87,8 +89,8 @@ def internal_id(self) -> str: return str(self.__internal_id) @property - def internal_id_int(self) -> int: - return self.__internal_id + def row(self) -> int: + return self.__row @property def timestamp(self) -> datetime: diff --git a/src/rp2/in_transaction.py b/src/rp2/in_transaction.py index 4371f33f..0d12eb5b 100644 --- a/src/rp2/in_transaction.py +++ b/src/rp2/in_transaction.py @@ -45,11 +45,11 @@ def __init__( fiat_in_no_fee: Optional[RP2Decimal] = None, fiat_in_with_fee: Optional[RP2Decimal] = None, fiat_fee: Optional[RP2Decimal] = None, - internal_id: Optional[int] = None, + row: Optional[int] = None, unique_id: Optional[str] = None, notes: Optional[str] = None, ) -> None: - super().__init__(configuration, timestamp, asset, transaction_type, spot_price, internal_id, unique_id, notes) + super().__init__(configuration, timestamp, asset, transaction_type, spot_price, row, unique_id, notes) self.__exchange: str = configuration.type_check_exchange("exchange", exchange) self.__holder: str = configuration.type_check_holder("holder", holder) diff --git a/src/rp2/intra_transaction.py b/src/rp2/intra_transaction.py index 0bc29e55..cb356b2b 100644 --- a/src/rp2/intra_transaction.py +++ b/src/rp2/intra_transaction.py @@ -34,7 +34,7 @@ def __init__( spot_price: Optional[RP2Decimal], crypto_sent: RP2Decimal, crypto_received: RP2Decimal, - internal_id: Optional[int] = None, + row: Optional[int] = None, unique_id: Optional[str] = None, notes: Optional[str] = None, ) -> None: @@ -52,7 +52,7 @@ def __init__( raise RP2ValueError( f"crypto_fee is non-zero ({self.__crypto_fee}) but spot_price is empty or zero: {timestamp} {asset} {crypto_sent} {unique_id} " ) - super().__init__(configuration, timestamp, asset, "MOVE", spot_price, internal_id, unique_id, notes) + super().__init__(configuration, timestamp, asset, "MOVE", spot_price, row, unique_id, notes) self.__from_exchange: str = configuration.type_check_exchange("from_exchange", from_exchange) self.__from_holder: str = configuration.type_check_holder("from_holder", from_holder) diff --git a/src/rp2/ods_parser.py b/src/rp2/ods_parser.py index 82016935..deafe106 100644 --- a/src/rp2/ods_parser.py +++ b/src/rp2/ods_parser.py @@ -191,7 +191,7 @@ def _create_and_process_transaction( fiat_in_no_fee=transaction.fiat_in_no_fee, fiat_in_with_fee=transaction.fiat_in_with_fee, fiat_fee=transaction.fiat_fee, - internal_id=internal_id, + row=internal_id, unique_id=transaction.unique_id, notes=notes, ) @@ -207,7 +207,7 @@ def _create_and_process_transaction( spot_price=transaction.spot_price, crypto_out_no_fee=ZERO, crypto_fee=transaction.crypto_fee, - internal_id=artificial_internal_id, + row=artificial_internal_id, unique_id=transaction.unique_id, notes=( f"Artificial transaction modeling the crypto fee of {transaction.crypto_fee} {transaction.asset} " @@ -243,7 +243,7 @@ def _process_constructor_argument_pack( internal_id: int, class_name: str, ) -> Dict[str, Any]: - argument_pack.update({"configuration": configuration, "internal_id": internal_id}) + argument_pack.update({"configuration": configuration, "row": internal_id}) numeric_parameters: List[str] = _get_decimal_constructor_argument_names(class_name) for numeric_parameter in numeric_parameters: if numeric_parameter in argument_pack: diff --git a/src/rp2/out_transaction.py b/src/rp2/out_transaction.py index 79c46287..6ef309e6 100644 --- a/src/rp2/out_transaction.py +++ b/src/rp2/out_transaction.py @@ -38,11 +38,11 @@ def __init__( crypto_out_with_fee: Optional[RP2Decimal] = None, fiat_out_no_fee: Optional[RP2Decimal] = None, fiat_fee: Optional[RP2Decimal] = None, - internal_id: Optional[int] = None, + row: Optional[int] = None, unique_id: Optional[str] = None, notes: Optional[str] = None, ) -> None: - super().__init__(configuration, timestamp, asset, transaction_type, spot_price, internal_id, unique_id, notes) + super().__init__(configuration, timestamp, asset, transaction_type, spot_price, row, unique_id, notes) self.__exchange: str = configuration.type_check_exchange("exchange", exchange) self.__holder: str = configuration.type_check_holder("holder", holder) diff --git a/src/rp2/plugin/accounting_method/hifo.py b/src/rp2/plugin/accounting_method/hifo.py index 41969bb7..973a0282 100644 --- a/src/rp2/plugin/accounting_method/hifo.py +++ b/src/rp2/plugin/accounting_method/hifo.py @@ -68,4 +68,4 @@ def lot_candidates_order(self) -> AcquiredLotCandidatesOrder: return AcquiredLotCandidatesOrder.OLDER_TO_NEWER def heap_key(self, lot: InTransaction) -> AcquiredLotHeapSortKey: - return AcquiredLotHeapSortKey(-lot.spot_price, lot.timestamp.timestamp(), lot.internal_id_int) + return AcquiredLotHeapSortKey(-lot.spot_price, lot.timestamp.timestamp(), lot.row) diff --git a/src/rp2/plugin/accounting_method/lifo.py b/src/rp2/plugin/accounting_method/lifo.py index 76cf4fd9..cac2b8b6 100644 --- a/src/rp2/plugin/accounting_method/lifo.py +++ b/src/rp2/plugin/accounting_method/lifo.py @@ -69,4 +69,4 @@ def lot_candidates_order(self) -> AcquiredLotCandidatesOrder: return AcquiredLotCandidatesOrder.NEWER_TO_OLDER def heap_key(self, lot: InTransaction) -> AcquiredLotHeapSortKey: - return AcquiredLotHeapSortKey(ZERO, -lot.timestamp.timestamp(), -lot.internal_id_int) + return AcquiredLotHeapSortKey(ZERO, -lot.timestamp.timestamp(), -lot.row) diff --git a/tests/test_balance.py b/tests/test_balance.py index a31f186f..9c3740d2 100644 --- a/tests/test_balance.py +++ b/tests/test_balance.py @@ -58,7 +58,7 @@ def test_easy_negative_case(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("3000.2"), fiat_in_with_fee=RP2Decimal("3020.2"), - internal_id=30, + row=30, ) in_transaction_set.add_entry(transaction1) @@ -73,7 +73,7 @@ def test_easy_negative_case(self) -> None: RP2Decimal("4.0000"), crypto_fee=RP2Decimal("0.0002"), fiat_out_no_fee=RP2Decimal("4000.0"), - internal_id=31, + row=31, ) out_transaction_set.add_entry(transaction2) @@ -106,7 +106,7 @@ def test_hard_negative_case(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("3000.2"), fiat_in_with_fee=RP2Decimal("3020.2"), - internal_id=30, + row=30, ) in_transaction_set.add_entry(transaction1) @@ -121,7 +121,7 @@ def test_hard_negative_case(self) -> None: RP2Decimal("4.0000"), crypto_fee=RP2Decimal("0.0002"), fiat_out_no_fee=RP2Decimal("6000.0"), - internal_id=31, + row=31, ) out_transaction_set.add_entry(transaction2) @@ -137,7 +137,7 @@ def test_hard_negative_case(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("3000.2"), fiat_in_with_fee=RP2Decimal("3020.2"), - internal_id=32, + row=32, ) in_transaction_set.add_entry(transaction3) @@ -152,7 +152,7 @@ def test_hard_negative_case(self) -> None: RP2Decimal("2.0000"), crypto_fee=RP2Decimal("0.0002"), fiat_out_no_fee=RP2Decimal("2000.0"), - internal_id=33, + row=33, ) out_transaction_set.add_entry(transaction4) diff --git a/tests/test_gain_loss.py b/tests/test_gain_loss.py index 8568f602..ee4dd066 100644 --- a/tests/test_gain_loss.py +++ b/tests/test_gain_loss.py @@ -47,7 +47,7 @@ def setUp(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("20002"), fiat_in_with_fee=RP2Decimal("20022"), - internal_id=10, + row=10, ) self._in_buy2 = InTransaction( self._configuration, @@ -59,7 +59,7 @@ def setUp(self) -> None: RP2Decimal("10500"), RP2Decimal("0.8"), fiat_fee=RP2Decimal("10"), - internal_id=11, + row=11, ) self._in_buy3 = InTransaction( self._configuration, @@ -71,7 +71,7 @@ def setUp(self) -> None: RP2Decimal("1300"), RP2Decimal("1.5"), fiat_fee=RP2Decimal("20"), - internal_id=12, + row=12, ) self._in_interest = InTransaction( self._configuration, @@ -83,7 +83,7 @@ def setUp(self) -> None: RP2Decimal("11000"), RP2Decimal("0.1"), fiat_fee=RP2Decimal("0"), - internal_id=14, + row=14, ) self._out: OutTransaction = OutTransaction( self._configuration, @@ -95,7 +95,7 @@ def setUp(self) -> None: RP2Decimal("12000"), RP2Decimal("0.2"), RP2Decimal("0"), - internal_id=20, + row=20, ) self._intra: IntraTransaction = IntraTransaction( self._configuration, @@ -108,7 +108,7 @@ def setUp(self) -> None: RP2Decimal("12500.0"), RP2Decimal("0.4"), RP2Decimal("0.39"), - internal_id=30, + row=30, ) def test_good_interest_gain_loss(self) -> None: @@ -313,7 +313,7 @@ def test_bad_gain_loss(self) -> None: RP2Decimal("1300"), RP2Decimal("1.5"), fiat_fee=RP2Decimal("20"), - internal_id=11, + row=11, ) GainLoss(self._configuration, RP2Decimal("0.1"), self._out, in_transaction) diff --git a/tests/test_gain_loss_set.py b/tests/test_gain_loss_set.py index 8352930d..4d8da8dc 100644 --- a/tests/test_gain_loss_set.py +++ b/tests/test_gain_loss_set.py @@ -92,7 +92,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("11000"), RP2Decimal("1"), fiat_fee=RP2Decimal("100.00"), - internal_id=4, + row=4, ) cls._in2[asset] = InTransaction( cls._configuration, @@ -104,7 +104,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("12000.0"), RP2Decimal("2.0"), fiat_fee=RP2Decimal("0"), - internal_id=3, + row=3, ) cls._in6[asset] = InTransaction( cls._configuration, @@ -116,7 +116,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("13000.0"), RP2Decimal("3"), fiat_fee=RP2Decimal("0"), - internal_id=7, + row=7, ) cls._in5[asset] = InTransaction( cls._configuration, @@ -128,7 +128,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("14000.0"), RP2Decimal("4.0"), fiat_fee=RP2Decimal("400"), - internal_id=6, + row=6, ) cls._in4[asset] = InTransaction( cls._configuration, @@ -140,7 +140,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("15000.0"), RP2Decimal("5.0"), fiat_fee=RP2Decimal("500"), - internal_id=5, + row=5, ) cls._out15[asset] = OutTransaction( cls._configuration, @@ -152,7 +152,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("11200.0"), RP2Decimal("0.2"), RP2Decimal("0"), - internal_id=16, + row=16, ) cls._out14[asset] = OutTransaction( cls._configuration, @@ -164,7 +164,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("12200.0"), RP2Decimal("1.0"), RP2Decimal("0"), - internal_id=15, + row=15, ) cls._out16[asset] = OutTransaction( cls._configuration, @@ -176,7 +176,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("14200.00"), RP2Decimal("5.0"), RP2Decimal("0"), - internal_id=17, + row=17, ) cls._out12[asset] = OutTransaction( cls._configuration, @@ -188,7 +188,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("14300"), RP2Decimal("3.79"), RP2Decimal("0"), - internal_id=13, + row=13, ) cls._out13[asset] = OutTransaction( cls._configuration, @@ -200,7 +200,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("20200.00"), RP2Decimal("2"), RP2Decimal("0.01"), - internal_id=14, + row=14, ) cls._intra25[asset] = IntraTransaction( cls._configuration, @@ -213,7 +213,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("11400.0"), RP2Decimal("0.1"), RP2Decimal("0.09"), - internal_id=26, + row=26, ) cls._intra24[asset] = IntraTransaction( cls._configuration, @@ -226,7 +226,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("14400.0"), RP2Decimal("0.2"), RP2Decimal("0.18"), - internal_id=25, + row=25, ) cls._intra22[asset] = IntraTransaction( cls._configuration, @@ -239,7 +239,7 @@ def _initialize_transactions(cls, asset: str) -> None: RP2Decimal("21400.0"), RP2Decimal("0.5"), RP2Decimal("0.46"), - internal_id=23, + row=23, ) cls._gain_loss_set[asset] = GainLossSet(cls._configuration, asset) if asset == "B1": @@ -388,7 +388,7 @@ def test_bad_gain_loss_set(self) -> None: RP2Decimal("12000.0"), RP2Decimal("2.0"), fiat_fee=RP2Decimal("0"), - internal_id=3, + row=3, ) gain_loss_set.add_entry(GainLoss(self._configuration, RP2Decimal("0.2"), out15, in3)) gain_loss_set.add_entry(GainLoss(self._configuration, RP2Decimal("0.2"), out15, in_transaction_test)) diff --git a/tests/test_in_transaction.py b/tests/test_in_transaction.py index cb6a78ee..5fa1d35e 100644 --- a/tests/test_in_transaction.py +++ b/tests/test_in_transaction.py @@ -71,13 +71,14 @@ def test_taxable_in_transaction(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=19, + row=19, ) InTransaction.type_check("my_instance", in_transaction) self.assertTrue(in_transaction.is_taxable()) self.assertEqual(RP2Decimal("2000.2"), in_transaction.fiat_taxable_amount) self.assertEqual("19", in_transaction.internal_id) + self.assertEqual(19, in_transaction.row) self.assertEqual(2021, in_transaction.timestamp.year) self.assertEqual(1, in_transaction.timestamp.month) self.assertEqual(2, in_transaction.timestamp.day) @@ -170,7 +171,7 @@ def test_non_taxable_in_transaction(self) -> None: RP2Decimal("1000"), RP2Decimal("2.0002"), fiat_fee=RP2Decimal("20"), - internal_id=19, + row=19, ) self.assertFalse(in_transaction.is_taxable()) self.assertEqual(RP2Decimal("0"), in_transaction.fiat_taxable_amount) @@ -211,7 +212,7 @@ def test_in_transaction_equality_and_hashing(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=19, + row=19, ) in_transaction2: InTransaction = InTransaction( self._configuration, @@ -225,7 +226,7 @@ def test_in_transaction_equality_and_hashing(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=19, + row=19, ) in_transaction3: InTransaction = InTransaction( self._configuration, @@ -239,7 +240,7 @@ def test_in_transaction_equality_and_hashing(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=20, + row=20, ) self.assertEqual(in_transaction, in_transaction) self.assertEqual(in_transaction, in_transaction2) @@ -262,7 +263,7 @@ def test_bad_to_string(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'indent' has non-integer value"): in_transaction.to_string(None, repr_format=False, extra_data=["foobar", "qwerty"]) # type: ignore @@ -291,7 +292,7 @@ def test_bad_in_transaction(self) -> None: RP2Decimal("10000"), RP2Decimal("1"), RP2Decimal("0"), - internal_id=45, + row=45, ), ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'configuration' is not of type Configuration: .*"): @@ -308,7 +309,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'configuration' is not of type Configuration: .*"): # Bad configuration @@ -324,10 +325,10 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) - with self.assertRaisesRegex(RP2TypeError, "Parameter 'internal_id' has non-integer .*"): - # Bad internal_id + with self.assertRaisesRegex(RP2TypeError, "Parameter 'row' has non-integer .*"): + # Bad row InTransaction( self._configuration, "2021-01-02T08:42:43.882Z", @@ -340,7 +341,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id="19", # type: ignore + row="19", # type: ignore ) with self.assertRaisesRegex(RP2ValueError, "Error parsing parameter 'timestamp': Unknown string format: .*"): # Bad timestamp @@ -356,7 +357,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'timestamp' value has no timezone info: .*"): # Bad timestamp @@ -372,7 +373,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'timestamp' has non-string value .*"): # Bad timestamp @@ -388,7 +389,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'asset' value is not known: .*"): # Bad asset @@ -404,7 +405,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'asset' has non-string value .*"): # Bad asset @@ -420,7 +421,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'exchange' value is not known: .*"): # Bad exchange @@ -436,7 +437,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'exchange' has non-string value .*"): # Bad exchange @@ -452,7 +453,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'holder' value is not known: .*"): # Bad holder @@ -468,7 +469,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'holder' has non-string value .*"): # Bad holder @@ -484,7 +485,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, ".*InTransaction .*, id.*invalid transaction type.*"): # Bad transaction type @@ -500,7 +501,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'transaction_type' has invalid transaction type value: .*"): # Bad transaction type @@ -516,7 +517,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter .* has invalid transaction type value: .*"): # Bad transaction type @@ -532,7 +533,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter .* has non-string value .*"): # Bad transaction type @@ -548,7 +549,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, ".*InTransaction .*, id.*parameter 'spot_price' cannot be 0"): # Bad spot price @@ -564,7 +565,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, ".*InTransaction .*, id.*parameter 'spot_price' cannot be 0"): # Bad spot price @@ -580,7 +581,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'spot_price' has non-positive value .*"): # Bad spot price @@ -596,7 +597,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'spot_price' has non-RP2Decimal value .*"): # Bad spot price @@ -612,7 +613,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_in' has zero value"): # Bad crypto in @@ -628,7 +629,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_in' has non-positive value .*"): # Bad crypto in @@ -644,7 +645,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_in' has non-RP2Decimal value .*"): # Bad crypto in @@ -660,7 +661,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'fiat_fee' has non-positive value .*"): # Bad fiat fee @@ -676,7 +677,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("-20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'fiat_fee' has non-RP2Decimal value .*"): # Bad fiat fee @@ -692,7 +693,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee="20", # type: ignore fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'fiat_in_no_fee' has non-positive value .*"): # Bad fiat in no fee @@ -708,7 +709,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("-2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'fiat_in_no_fee' has non-RP2Decimal value .*"): # Bad fiat in no fee @@ -724,7 +725,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee="2000.2", # type: ignore fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'fiat_in_with_fee' has non-positive value .*"): # Bad fiat in with fee @@ -740,7 +741,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("-2020.2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'fiat_in_with_fee' has non-RP2Decimal value .*"): # Bad fiat in with fee @@ -756,7 +757,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=(1, 2, 3), # type: ignore - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'notes' has non-string value .*"): # Bad notes @@ -772,7 +773,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, notes=35.6, # type: ignore ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'notes' has non-string value .*"): @@ -789,7 +790,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, notes=[1, 2, 3], # type: ignore ) with self.assertRaisesRegex(RP2ValueError, "both 'crypto_fee' and 'fiat_fee' are defined: only one allowed"): @@ -807,7 +808,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) with self.assertLogs(level="WARNING") as log: @@ -824,7 +825,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("1000"), fiat_in_no_fee=RP2Decimal("1900.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=19, + row=19, ) self.assertTrue(re.search(".* InTransaction .*, id.*crypto_in.*spot_price != fiat_in_no_fee:.*", log.output[0])) @@ -842,7 +843,7 @@ def test_bad_in_transaction(self) -> None: fiat_fee=RP2Decimal("18"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2020.2"), - internal_id=19, + row=19, ) self.assertTrue(re.search(".* InTransaction .*, id.*fiat_in_with_fee != fiat_in_no_fee.*fiat_fee:.*", log.output[0])) diff --git a/tests/test_input_parser.py b/tests/test_input_parser.py index ad6e6601..5f0be162 100644 --- a/tests/test_input_parser.py +++ b/tests/test_input_parser.py @@ -73,7 +73,7 @@ def _verify_empty_table(self, transaction_set: TransactionSet) -> None: self.assertTrue(transaction_set.is_empty()) def _verify_non_empty_in_table(self, in_transaction_set: TransactionSet, asset: str) -> None: - internal_ids: List[str] = ["4", "3", "7", "6", "5"] + rows: List[str] = ["4", "3", "7", "6", "5"] timestamps: List[str] = [ "2020-01-01T08:41Z", "2020-02-01T11:18Z", @@ -95,7 +95,7 @@ def _verify_non_empty_in_table(self, in_transaction_set: TransactionSet, asset: is_taxable_values: List[bool] = [False, True, True, False, False] count: int = 0 - internal_id: str + row: str timestamp: str transaction_type: TransactionType spot_price: RP2Decimal @@ -108,7 +108,7 @@ def _verify_non_empty_in_table(self, in_transaction_set: TransactionSet, asset: previous_transaction: Optional[InTransaction] = None for ( # type: ignore transaction, - internal_id, + row, timestamp, transaction_type, spot_price, @@ -118,7 +118,7 @@ def _verify_non_empty_in_table(self, in_transaction_set: TransactionSet, asset: is_taxable, ) in zip( # type: ignore in_transaction_set, - internal_ids, + rows, timestamps, transaction_types, spot_prices, @@ -130,7 +130,7 @@ def _verify_non_empty_in_table(self, in_transaction_set: TransactionSet, asset: if not in_transaction_set or not transaction: # Unwrap the Optional types to keep mypy happy raise RP2RuntimeError("Internal error: in_transaction_set or transaction are None") self.assertEqual(in_transaction_set.get_parent(transaction), previous_transaction) - self.assertEqual(transaction.internal_id, internal_id) + self.assertEqual(transaction.row, row) self.assertEqual(transaction.timestamp, parse(timestamp)) self.assertEqual(transaction.transaction_type, transaction_type) self.assertEqual(transaction.spot_price, spot_price) @@ -144,7 +144,7 @@ def _verify_non_empty_in_table(self, in_transaction_set: TransactionSet, asset: self.assertEqual(count, 5) def _verify_non_empty_out_table(self, out_transaction_set: TransactionSet, asset: str) -> None: - internal_ids: List[str] = ["16", "15", "17", "13", "14"] + rows: List[str] = ["16", "15", "17", "13", "14"] timestamps: List[str] = [ "2020-01-11T11:15Z", "2020-02-11T19:58Z", @@ -166,7 +166,7 @@ def _verify_non_empty_out_table(self, out_transaction_set: TransactionSet, asset is_taxable_values: List[bool] = [True, True, True, True, True] count: int = 0 - internal_id: str + row: str timestamp: str transaction_type: TransactionType spot_price: RP2Decimal @@ -180,7 +180,7 @@ def _verify_non_empty_out_table(self, out_transaction_set: TransactionSet, asset for ( # type: ignore transaction, - internal_id, + row, timestamp, transaction_type, spot_price, @@ -190,7 +190,7 @@ def _verify_non_empty_out_table(self, out_transaction_set: TransactionSet, asset is_taxable, ) in zip( # type: ignore out_transaction_set, - internal_ids, + rows, timestamps, transaction_types, spot_prices, @@ -202,7 +202,7 @@ def _verify_non_empty_out_table(self, out_transaction_set: TransactionSet, asset if not out_transaction_set or not transaction: # Unwrap the Optional types to keep mypy happy raise RP2RuntimeError("Internal error: in_transaction_set or transaction are None") self.assertEqual(out_transaction_set.get_parent(transaction), previous_transaction) - self.assertEqual(transaction.internal_id, internal_id) + self.assertEqual(transaction.row, row) self.assertEqual(transaction.timestamp, parse(timestamp)) self.assertEqual(transaction.transaction_type, transaction_type) self.assertEqual(transaction.spot_price, spot_price) @@ -216,7 +216,7 @@ def _verify_non_empty_out_table(self, out_transaction_set: TransactionSet, asset self.assertEqual(count, 5) def _verify_non_empty_intra_table(self, intra_transaction_set: TransactionSet, asset: str) -> None: - internal_ids: List[str] = ["26", "24", "25", "23"] + rows: List[str] = ["26", "24", "25", "23"] timestamps: List[str] = [ "2020-01-21T18:33:14.342Z", "2020-02-21T20:23:31Z", @@ -236,7 +236,7 @@ def _verify_non_empty_intra_table(self, intra_transaction_set: TransactionSet, a is_taxable_values: List[bool] = [True, False, True, True] count: int = 0 - internal_id: str + row: str timestamp: str transaction_type: TransactionType spot_price: RP2Decimal @@ -249,7 +249,7 @@ def _verify_non_empty_intra_table(self, intra_transaction_set: TransactionSet, a previous_transaction: Optional[IntraTransaction] = None for ( # type: ignore transaction, - internal_id, + row, timestamp, transaction_type, spot_price, @@ -259,7 +259,7 @@ def _verify_non_empty_intra_table(self, intra_transaction_set: TransactionSet, a is_taxable, ) in zip( # type: ignore intra_transaction_set, - internal_ids, + rows, timestamps, transaction_types, spot_prices, @@ -271,7 +271,7 @@ def _verify_non_empty_intra_table(self, intra_transaction_set: TransactionSet, a if not intra_transaction_set or not transaction: # Unwrap the Optional types to keep mypy happy raise RP2RuntimeError("Internal error: intra_transaction_set or transaction are None") self.assertEqual(intra_transaction_set.get_parent(transaction), previous_transaction) - self.assertEqual(transaction.internal_id, internal_id) + self.assertEqual(transaction.row, row) self.assertEqual(transaction.timestamp, parse(timestamp)) self.assertEqual(transaction.transaction_type, transaction_type) self.assertEqual(transaction.spot_price, spot_price) diff --git a/tests/test_intra_transaction.py b/tests/test_intra_transaction.py index 44aee8c3..7afb06e5 100644 --- a/tests/test_intra_transaction.py +++ b/tests/test_intra_transaction.py @@ -48,12 +48,13 @@ def test_taxable_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) IntraTransaction.type_check("my_instance", intra_transaction) self.assertTrue(intra_transaction.is_taxable()) self.assertEqual(RP2Decimal("0.4"), intra_transaction.fiat_taxable_amount) + self.assertEqual(19, intra_transaction.row) self.assertEqual("19", intra_transaction.internal_id) self.assertEqual(2021, intra_transaction.timestamp.year) self.assertEqual(1, intra_transaction.timestamp.month) @@ -156,7 +157,7 @@ def test_non_taxable_intra_transaction(self) -> None: RP2Decimal("100.0"), RP2Decimal("30"), RP2Decimal("30"), - internal_id=19, + row=19, ) self.assertFalse(intra_transaction.is_taxable()) self.assertEqual(RP2Decimal("0"), intra_transaction.fiat_taxable_amount) @@ -200,7 +201,7 @@ def test_intra_transaction_equality_and_hashing(self) -> None: RP2Decimal("100.0"), RP2Decimal("30"), RP2Decimal("30"), - internal_id=19, + row=19, ) intra_transaction2: IntraTransaction = IntraTransaction( self._configuration, @@ -213,7 +214,7 @@ def test_intra_transaction_equality_and_hashing(self) -> None: RP2Decimal("100.0"), RP2Decimal("30"), RP2Decimal("30"), - internal_id=19, + row=19, ) intra_transaction3: IntraTransaction = IntraTransaction( self._configuration, @@ -226,7 +227,7 @@ def test_intra_transaction_equality_and_hashing(self) -> None: RP2Decimal("100.0"), RP2Decimal("30"), RP2Decimal("30"), - internal_id=11, + row=11, ) self.assertEqual(intra_transaction, intra_transaction) self.assertEqual(intra_transaction, intra_transaction2) @@ -248,7 +249,7 @@ def test_bad_to_string(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'indent' has non-integer value"): intra_transaction.to_string(None, repr_format=False, extra_data=["foobar", "qwerty"]) # type: ignore @@ -277,7 +278,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("10000"), RP2Decimal("1"), fiat_fee=RP2Decimal("0"), - internal_id=45, + row=45, ), ) @@ -294,7 +295,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'configuration' is not of type Configuration: .*"): # Bad configuration @@ -309,10 +310,10 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) - with self.assertRaisesRegex(RP2TypeError, "Parameter 'internal_id' has non-integer value .*"): - # Bad internal_id + with self.assertRaisesRegex(RP2TypeError, "Parameter 'row' has non-integer value .*"): + # Bad row IntraTransaction( self._configuration, "2021-01-02T08:42:43.882Z", @@ -324,7 +325,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=(1, 2, 3), # type: ignore + row=(1, 2, 3), # type: ignore ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'timestamp' has non-string value .*"): # Bad timestamp @@ -339,7 +340,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'timestamp' value has no timezone info: .*"): # Bad timestamp @@ -354,7 +355,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'asset' value is not known: .*"): # Bad asset @@ -369,7 +370,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'asset' has non-string value .*"): # Bad asset @@ -384,7 +385,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'from_exchange' value is not known: .*"): # Bad from exchange @@ -399,7 +400,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'from_exchange' has non-string value .*"): # Bad from exchange @@ -414,7 +415,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'from_holder' value is not known: .*"): # Bad from holder @@ -429,7 +430,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'from_holder' has non-string value .*"): # Bad from holder @@ -444,7 +445,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'to_exchange' value is not known: .*"): # Bad to exchange @@ -459,7 +460,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'to_exchange' has non-string value .*"): # Bad to exchange @@ -474,7 +475,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'to_holder' value is not known: .*"): # Bad to holder @@ -489,7 +490,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'to_holder' has non-string value .*"): # Bad to holder @@ -504,7 +505,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'spot_price' has non-positive value .*"): # Bad spot price @@ -519,7 +520,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("-1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'spot_price' has non-RP2Decimal value .*"): # Bad spot price @@ -534,7 +535,7 @@ def test_bad_intra_transaction(self) -> None: "1000", # type: ignore RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_sent' has zero value"): # Bad crypto sent @@ -549,7 +550,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("0"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_sent' has non-positive value .*"): # Bad crypto sent @@ -564,7 +565,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("-2"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_sent' has non-RP2Decimal value .*"): # Bad crypto sent @@ -579,7 +580,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), None, # type: ignore RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_sent' has non-RP2Decimal value .*"): # Bad crypto sent @@ -594,7 +595,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), "-2.0002", # type: ignore RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_received' has non-positive value .*"): # Bad crypto received @@ -609,7 +610,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("-2"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_received' has non-RP2Decimal value .*"): # Bad crypto received @@ -624,7 +625,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), None, # type: ignore - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_received' has non-RP2Decimal value .*"): # Bad crypto received @@ -639,7 +640,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), (1, 2, 3), # type: ignore - internal_id=19, + row=19, ) with self.assertLogs(level="WARNING") as log: @@ -655,7 +656,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) self.assertTrue(re.search(".*IntraTransaction.*: from/to exchanges/holders are the same: sending to self", log.output[0])) @@ -672,7 +673,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("-2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_sent' has zero value"): # Crypto sent == 0 @@ -687,7 +688,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("0"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_received' has non-positive value .*"): # Crypto received < 0 @@ -702,7 +703,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("-1.9998"), - internal_id=19, + row=19, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'notes' has non-string value .*"): # Bad notes @@ -717,7 +718,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, notes=1111, # type: ignore ) with self.assertLogs(level="WARNING") as log: @@ -733,7 +734,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=19, + row=19, ) self.assertTrue(re.search(".*IntraTransaction.*: from/to exchanges/holders are the same: sending to self", log.output[0])) with self.assertRaisesRegex(RP2ValueError, ".*IntraTransaction .*, id.*crypto sent < crypto received"): @@ -749,7 +750,7 @@ def test_bad_intra_transaction(self) -> None: RP2Decimal("1000.0"), RP2Decimal("1.0002"), RP2Decimal("2.9998"), - internal_id=19, + row=19, ) diff --git a/tests/test_out_transaction.py b/tests/test_out_transaction.py index d927f521..ed0bb537 100644 --- a/tests/test_out_transaction.py +++ b/tests/test_out_transaction.py @@ -47,7 +47,7 @@ def test_taxable_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0.01"), - internal_id=38, + row=38, ) OutTransaction.type_check("my_instance", out_transaction) @@ -55,6 +55,7 @@ def test_taxable_out_transaction(self) -> None: self.assertEqual(RP2Decimal("1981.98"), out_transaction.fiat_taxable_amount) self.assertEqual(RP2Decimal("2.2"), out_transaction.crypto_taxable_amount) self.assertEqual("38", out_transaction.internal_id) + self.assertEqual(38, out_transaction.row) self.assertEqual(2020, out_transaction.timestamp.year) self.assertEqual(6, out_transaction.timestamp.month) self.assertEqual(1, out_transaction.timestamp.day) @@ -137,7 +138,7 @@ def test_out_transaction_equality_and_hashing(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0.01"), - internal_id=38, + row=38, ) out_transaction2: OutTransaction = OutTransaction( self._configuration, @@ -149,7 +150,7 @@ def test_out_transaction_equality_and_hashing(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0.01"), - internal_id=38, + row=38, ) out_transaction3: OutTransaction = OutTransaction( self._configuration, @@ -161,7 +162,7 @@ def test_out_transaction_equality_and_hashing(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0.01"), - internal_id=7, + row=7, ) self.assertEqual(out_transaction, out_transaction) self.assertEqual(out_transaction, out_transaction2) @@ -182,7 +183,7 @@ def test_bad_to_string(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0.01"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'indent' has non-integer value"): out_transaction.to_string(None, repr_format=False, extra_data=["foobar", "qwerty"]) # type: ignore @@ -212,7 +213,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("10000"), RP2Decimal("1"), RP2Decimal("1"), - internal_id=45, + row=45, ), ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'configuration' is not of type Configuration: .*"): @@ -227,7 +228,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'configuration' is not of type Configuration: .*"): # Bad configuration @@ -241,10 +242,10 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) - with self.assertRaisesRegex(RP2TypeError, "Parameter 'internal_id' has non-integer value .*"): - # Bad internal_id + with self.assertRaisesRegex(RP2TypeError, "Parameter 'row' has non-integer value .*"): + # Bad row OutTransaction( self._configuration, "6/1/2020 3:59:59 -04:00", @@ -255,7 +256,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=(1, 2, 3), # type: ignore + row=(1, 2, 3), # type: ignore ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'timestamp' has non-string value .*"): # Bad timestamp @@ -269,7 +270,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'timestamp' value has no timezone info: .*"): # Bad timestamp @@ -283,7 +284,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'timestamp' has non-string value .*"): # Bad timestamp @@ -297,7 +298,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'asset' value is not known: .*"): # Bad asset @@ -311,7 +312,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'asset' has non-string value .*"): # Bad asset @@ -325,7 +326,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'exchange' value is not known: .*"): # Bad exchange @@ -339,7 +340,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'exchange' has non-string value .*"): # Bad exchange @@ -353,7 +354,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'holder' value is not known: .*"): # Bad holder @@ -367,7 +368,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'holder' has non-string value .*"): # Bad holder @@ -381,7 +382,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, ".*OutTransaction .*, id.*invalid transaction type .*"): # Bad transaction type @@ -395,7 +396,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, ".*OutTransaction .*, id.*invalid transaction type .*"): # Bad transaction type @@ -409,7 +410,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter .* has invalid transaction type value: .*"): # Bad transaction type @@ -423,7 +424,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter .* has non-string value .*"): # Bad transaction type @@ -437,7 +438,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "OutTransaction .*, id.*parameter 'spot_price' cannot be 0"): # Bad spot price @@ -451,7 +452,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("0"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'spot_price' has non-positive value .*"): # Bad spot price @@ -465,7 +466,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("-900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'spot_price' has non-RP2Decimal value ,*"): # Bad spot price @@ -479,7 +480,7 @@ def test_bad_out_transaction(self) -> None: None, # type: ignore RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_out_no_fee' has zero value"): # Bad crypto out no fee @@ -493,7 +494,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("0"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_out_no_fee' has non-positive value .*"): # Bad crypto out no fee @@ -507,7 +508,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("-2.2"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_out_no_fee' has non-RP2Decimal value .*"): # Bad crypto out no fee @@ -521,7 +522,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), None, # type: ignore RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "fee-typed transaction has non-zero 'crypto_out_no_fee'"): # Bad crypto out no fee @@ -535,7 +536,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("10"), RP2Decimal("0"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'crypto_fee' has non-positive value .*"): # Bad crypto fee @@ -549,7 +550,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("-0.1"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'crypto_fee' has non-RP2Decimal value .*"): # Bad crypto fee @@ -563,7 +564,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), "foobar", # type: ignore - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'fiat_out_no_fee' has non-positive value .*"): # Bad fiat_out_no_fee @@ -578,7 +579,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("2.2"), RP2Decimal("0"), fiat_out_no_fee=RP2Decimal("-0.1"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'fiat_out_no_fee' has non-RP2Decimal value .*"): # Bad fiat_out_no_fee @@ -593,7 +594,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("2.2"), RP2Decimal("0"), fiat_out_no_fee="foobar", # type: ignore - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2ValueError, "Parameter 'fiat_fee' has non-positive value .*"): @@ -610,7 +611,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("0"), fiat_out_no_fee=RP2Decimal("1800"), fiat_fee=RP2Decimal("-10"), - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'fiat_fee' has non-RP2Decimal value .*"): # Bad fiat fee @@ -626,7 +627,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("0"), fiat_out_no_fee=RP2Decimal("1800"), fiat_fee="foobar", # type: ignore - internal_id=38, + row=38, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'notes' has non-string value .*"): # Bad notes @@ -641,7 +642,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("2.2"), RP2Decimal("0"), notes=(1, 2, 3), # type: ignore - internal_id=38, + row=38, ) with self.assertLogs(level="WARNING") as log: @@ -656,7 +657,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("2.2"), RP2Decimal("0.1"), crypto_out_with_fee=RP2Decimal("2.2"), - internal_id=38, + row=38, ) self.assertTrue(re.search("crypto_out_with_fee != crypto_out_no_fee.*crypto_fee:.*", log.output[0])) with self.assertLogs(level="WARNING") as log: @@ -672,7 +673,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("0.1"), fiat_out_no_fee=RP2Decimal("1981.98"), fiat_fee=RP2Decimal("5.9"), - internal_id=38, + row=38, ) self.assertTrue(re.search("crypto_fee.*spot_price.*!= fiat_fee.*:.*", log.output[0])) with self.assertLogs(level="WARNING") as log: @@ -688,7 +689,7 @@ def test_bad_out_transaction(self) -> None: RP2Decimal("0.1"), fiat_out_no_fee=RP2Decimal("1081.98"), fiat_fee=RP2Decimal("90.09"), - internal_id=38, + row=38, ) self.assertTrue(re.search("crypto_out_no_fee.*spot_price.*!= fiat_out_no_fee.*:.*", log.output[0])) diff --git a/tests/test_tax_engine.py b/tests/test_tax_engine.py index 03debeb3..92c91b61 100644 --- a/tests/test_tax_engine.py +++ b/tests/test_tax_engine.py @@ -126,7 +126,7 @@ def test_bad_input(self) -> None: RP2Decimal("900.9"), RP2Decimal("20.2"), RP2Decimal("1"), - internal_id=38, + row=38, ) ) diff --git a/tests/test_transaction_set.py b/tests/test_transaction_set.py index d77f65bb..ea4eae74 100644 --- a/tests/test_transaction_set.py +++ b/tests/test_transaction_set.py @@ -64,7 +64,7 @@ def test_good_transaction_set(self) -> None: fiat_fee=RP2Decimal("20"), fiat_in_no_fee=RP2Decimal("3000.2"), fiat_in_with_fee=RP2Decimal("3020.2"), - internal_id=30, + row=30, ) transaction_set.add_entry(transaction3) @@ -80,7 +80,7 @@ def test_good_transaction_set(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_no_fee=RP2Decimal("2000.2"), fiat_in_with_fee=RP2Decimal("2000.2"), - internal_id=20, + row=20, ) transaction_set.add_entry(transaction2) @@ -106,7 +106,7 @@ def test_good_transaction_set(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=10, + row=10, ) transaction_set.add_entry(transaction1) @@ -121,7 +121,7 @@ def test_good_transaction_set(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=50, + row=50, ) transaction_set.add_entry(transaction5) @@ -136,14 +136,14 @@ def test_good_transaction_set(self) -> None: RP2Decimal("100.0"), RP2Decimal("30"), RP2Decimal("30"), - internal_id=40, + row=40, ) transaction_set.add_entry(transaction4) self.assertEqual(transaction_set.entry_set_type, EntrySetType.MIXED) self.assertEqual(transaction_set.asset, "B1") - internal_ids: List[str] = ["10", "20", "30", "40", "50"] + rows: List[str] = ["10", "20", "30", "40", "50"] transactions: List[AbstractTransaction] = [transaction1, transaction2, transaction3, transaction4, transaction5] parents: List[Optional[AbstractTransaction]] = [ None, @@ -192,15 +192,17 @@ def test_good_transaction_set(self) -> None: transaction_set, transactions, parents, - internal_ids, + rows, timestamps, transaction_types, fiat_taxable_amounts, crypto_balance_changes, fiat_balance_changes, ): + row = int(internal_id) self.assertEqual(transaction, expected_transaction) self.assertEqual(transaction_set.get_parent(transaction), parent) + self.assertEqual(transaction.row, row) self.assertEqual(transaction.internal_id, internal_id) self.assertEqual(transaction.timestamp, parse(timestamp)) self.assertEqual(transaction.transaction_type, transaction_type) @@ -226,7 +228,7 @@ def test_bad_transaction_set(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_with_fee=RP2Decimal("2000.2"), fiat_in_no_fee=RP2Decimal("2000.2"), - internal_id=20, + row=20, ) # Different instance with same contents as in_transaction in_transaction2 = InTransaction( @@ -241,7 +243,7 @@ def test_bad_transaction_set(self) -> None: fiat_fee=RP2Decimal("0"), fiat_in_with_fee=RP2Decimal("2000.2"), fiat_in_no_fee=RP2Decimal("2000.2"), - internal_id=20, + row=20, ) out_transaction = OutTransaction( self._configuration, @@ -253,7 +255,7 @@ def test_bad_transaction_set(self) -> None: RP2Decimal("900.9"), RP2Decimal("2.2"), RP2Decimal("0"), - internal_id=10, + row=10, ) intra_transaction = IntraTransaction( self._configuration, @@ -266,7 +268,7 @@ def test_bad_transaction_set(self) -> None: RP2Decimal("1000.0"), RP2Decimal("2.0002"), RP2Decimal("1.9998"), - internal_id=50, + row=50, ) with self.assertRaisesRegex(RP2TypeError, "Parameter 'configuration' is not of type Configuration: .*"):