Skip to content

Commit

Permalink
Set allow_negative_balances=True on failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qwhelan committed May 16, 2024
1 parent 856adc3 commit d6086cb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
10 changes: 9 additions & 1 deletion tests/test_localized_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ def setUpClass(cls) -> None:
# To test localization plumbing, we generate Japanese taxes for test_data in Kalaallisut language. Note that the localization
# file (locales/kl/LC_MESSAGES/messages.po) doesn't contain real Kalaallisut translations, but only placeholder strings starting
# with "__test_": this is good enough to test localization plumbing (and it would work in the same way with a real translation).
cls._generate(cls.output_dir, test_name="test_data", config="test_data", method="fifo", generation_language="kl", country="jp")
cls._generate(
cls.output_dir,
test_name="test_data",
config="test_data",
method="fifo",
generation_language="kl",
country="jp",
allow_negative_balances=True,
)

def setUp(self) -> None:
self.maxDiff = None # pylint: disable=invalid-name
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ods_output_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def setUpClass(cls) -> None:
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="crypto_example", config="crypto_example", method=method, allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data", config="test_data", method=method)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data", config="test_data", method=method, allow_negative_balances=True)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data2", config="test_data", method=method, allow_negative_balances=True)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data3", config="test_data", method=method)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data3", config="test_data", method=method, allow_negative_balances=True)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data4", config="test_data4", method=method)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_hifo", config="test_data", method=method, allow_negative_balances=True)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_hifo2", config="test_data", method=method, allow_negative_balances=True)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_ods_output_diff_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ def setUpClass(cls) -> None:
generation_language="es",
allow_negative_balances=True,
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data", config="test_data", method="fifo", country="es", generation_language="es")
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_data", config="test_data", method="fifo", country="es", generation_language="es", allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_data2", config="test_data", method="fifo", country="es", generation_language="es", allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data3", config="test_data", method="fifo", country="es", generation_language="es")
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_data3", config="test_data", method="fifo", country="es", generation_language="es", allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data4", config="test_data4", method="fifo", country="es", generation_language="es")
AbstractTestODSOutputDiff._generate(
cls.output_dir,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_ods_output_diff_jp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ def setUpClass(cls) -> None:
generation_language="en",
allow_negative_balances=True,
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data", config="test_data", method="fifo", country="jp", generation_language="en")
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_data", config="test_data", method="fifo", country="jp", generation_language="en", allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_data2", config="test_data", method="fifo", country="jp", generation_language="en", allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data3", config="test_data", method="fifo", country="jp", generation_language="en")
AbstractTestODSOutputDiff._generate(
cls.output_dir, test_name="test_data3", config="test_data", method="fifo", country="jp", generation_language="en", allow_negative_balances=True
)
AbstractTestODSOutputDiff._generate(cls.output_dir, test_name="test_data4", config="test_data4", method="fifo", country="jp", generation_language="en")
AbstractTestODSOutputDiff._generate(
cls.output_dir,
Expand Down
21 changes: 14 additions & 7 deletions tests/test_tax_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@

class TestTaxEngine(unittest.TestCase):
_good_input_configuration: Configuration
_good_input_allow_negative_balance_configuration: Configuration
_bad_input_configuration: Configuration
_accounting_engine: AccountingEngine

@classmethod
def setUpClass(cls) -> None:
TestTaxEngine._good_input_configuration = Configuration("./config/test_data.ini", US())
TestTaxEngine._good_input_allow_negative_balance_configuration = Configuration("./config/test_data.ini", US(), allow_negative_balances=True)
TestTaxEngine._bad_input_configuration = Configuration("./config/test_bad_data.ini", US())
years_2_methods = AVLTree[int, AbstractAccountingMethod]()
years_2_methods.insert_node(MIN_DATE.year, AccountingMethod())
Expand All @@ -49,19 +51,24 @@ def setUp(self) -> None:

def test_good_input(self) -> None:
self._verify_good_output("B1")
self._verify_good_output("B2")
self._verify_good_output("B3")
self._verify_good_output("B4")
self._verify_good_output("B2", allow_negative_balances=True)
self._verify_good_output("B3", allow_negative_balances=True)
self._verify_good_output("B4", allow_negative_balances=True)

def _verify_good_output(self, sheet_name: str, allow_negative_balances: bool = False) -> None:
if allow_negative_balances:
config = self._good_input_allow_negative_balance_configuration
else:
config = self._good_input_configuration

def _verify_good_output(self, sheet_name: str) -> None:
asset = sheet_name

# Parser is tested separately (on same input) in test_input_parser.py
input_file_handle: object = open_ods(self._good_input_configuration, "./input/test_data.ods")
input_data: InputData = parse_ods(self._good_input_configuration, asset, input_file_handle)
input_file_handle: object = open_ods(config, "./input/test_data.ods")
input_data: InputData = parse_ods(config, asset, input_file_handle)

# In table is always present
computed_data: ComputedData = compute_tax(self._good_input_configuration, self._accounting_engine, input_data)
computed_data: ComputedData = compute_tax(config, self._accounting_engine, input_data)

if asset in RP2_TEST_OUTPUT:
self.assertEqual(str(computed_data.gain_loss_set), RP2_TEST_OUTPUT[asset])
Expand Down

0 comments on commit d6086cb

Please sign in to comment.