diff options
| author | Max Nanis | 2026-08-24 17:12:54 -0700 |
|---|---|---|
| committer | Max Nanis | 2026-08-24 17:12:54 -0700 |
| commit | 5682f48a96b0713929a4bb52e72eec5907d5dd32 (patch) | |
| tree | 3e5ba728145cf69f4ea0fde48e630b341c164cd0 /tests/models/test_currency.py | |
| parent | 979efd01b0c61d493d1fef3dff9885f5d38a8975 (diff) | |
| download | generalresearch-5682f48a96b0713929a4bb52e72eec5907d5dd32.tar.gz generalresearch-5682f48a96b0713929a4bb52e72eec5907d5dd32.zip | |
pytest fixture annotations, ruf manual edits
Diffstat (limited to 'tests/models/test_currency.py')
| -rw-r--r-- | tests/models/test_currency.py | 114 |
1 files changed, 29 insertions, 85 deletions
diff --git a/tests/models/test_currency.py b/tests/models/test_currency.py index 1102717..9bc2216 100644 --- a/tests/models/test_currency.py +++ b/tests/models/test_currency.py @@ -8,11 +8,12 @@ from random import randint import pytest +from generalresearch.currency import USDCent, USDMill, format_usd_cent + class TestUSDCentModel: def test_construct_int(self): - from generalresearch.currency import USDCent for _ in range(100): int_val = randint(0, 999_999) @@ -20,10 +21,9 @@ class TestUSDCentModel: assert int_val == instance def test_construct_float(self): - from generalresearch.currency import USDCent + float_val: float = 10.6789 with pytest.warns(expected_warning=Warning) as record: - float_val: float = 10.6789 instance = USDCent(float_val) assert len(record) == 1 @@ -34,10 +34,9 @@ class TestUSDCentModel: assert instance == 10 def test_construct_decimal(self): - from generalresearch.currency import USDCent + decimal_val: Decimal = Decimal("10.0") with pytest.warns(expected_warning=Warning) as record: - decimal_val: Decimal = Decimal("10.0") instance = USDCent(decimal_val) assert len(record) == 1 @@ -50,8 +49,8 @@ class TestUSDCentModel: assert instance == 10 # Now with rounding + decimal_val: Decimal = Decimal("10.6789") with pytest.warns(Warning) as record: - decimal_val: Decimal = Decimal("10.6789") instance = USDCent(decimal_val) assert len(record) == 1 @@ -64,16 +63,12 @@ class TestUSDCentModel: assert instance == 10 def test_construct_negative(self): - from generalresearch.currency import USDCent - with pytest.raises(expected_exception=ValueError) as cm: USDCent(-1) assert "USDCent not be less than zero" in str(cm.value) def test_operation_add(self): - from generalresearch.currency import USDCent - - for i in range(100): + for _ in range(100): int_val1 = randint(0, 999_999) int_val2 = randint(0, 999_999) @@ -83,9 +78,7 @@ class TestUSDCentModel: assert int_val1 + int_val2 == instance1 + instance2 def test_operation_subtract(self): - from generalresearch.currency import USDCent - - for i in range(100): + for _ in range(100): int_val1 = randint(500_000, 999_999) int_val2 = randint(0, 499_999) @@ -95,9 +88,7 @@ class TestUSDCentModel: assert int_val1 - int_val2 == instance1 - instance2 def test_operation_subtract_to_neg(self): - from generalresearch.currency import USDCent - - for i in range(100): + for _ in range(100): int_val = randint(0, 999_999) instance = USDCent(int_val) @@ -107,9 +98,7 @@ class TestUSDCentModel: assert "USDCent not be less than zero" in str(cm.value) def test_operation_multiply(self): - from generalresearch.currency import USDCent - - for i in range(100): + for _ in range(100): int_val1 = randint(0, 999_999) int_val2 = randint(0, 999_999) @@ -119,15 +108,11 @@ class TestUSDCentModel: assert int_val1 * int_val2 == instance1 * instance2 def test_operation_div(self): - from generalresearch.currency import USDCent - with pytest.raises(ValueError) as cm: - USDCent(10) / 2 + _ = USDCent(10) / 2 assert "Division not allowed for USDCent" in str(cm.value) def test_operation_result_type(self): - from generalresearch.currency import USDCent - int_val = randint(1, 999_999) instance = USDCent(int_val) @@ -141,8 +126,6 @@ class TestUSDCentModel: assert isinstance(res_multipy, USDCent) def test_operation_partner_add(self): - from generalresearch.currency import USDCent - int_val = randint(1, 999_999) instance = USDCent(int_val) @@ -159,18 +142,14 @@ class TestUSDCentModel: _ = instance + True def test_abs(self): - from generalresearch.currency import USDCent - - for i in range(100): + for _ in range(100): int_val = abs(randint(0, 999_999)) instance = abs(USDCent(int_val)) assert int_val == instance def test_str(self): - from generalresearch.currency import USDCent - - for i in range(100): + for _ in range(100): int_val = randint(0, 999_999) instance = USDCent(int_val) @@ -180,8 +159,6 @@ class TestUSDCentModel: """There is no correct answer here, but we at least want to make sure that a USDCent is returned """ - from generalresearch.currency import USDCent - res = USDCent(10) // 1.2 assert not isinstance(res, USDCent) assert isinstance(res, float) @@ -206,18 +183,14 @@ class TestUSDCentModel: class TestUSDMillModel: def test_construct_int(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val = randint(0, 999_999) instance = USDMill(int_val) assert int_val == instance def test_construct_float(self): - from generalresearch.currency import USDMill - + float_val: float = 10.6789 with pytest.warns(expected_warning=Warning) as record: - float_val: float = 10.6789 instance = USDMill(float_val) assert len(record) == 1 @@ -228,10 +201,8 @@ class TestUSDMillModel: assert instance == 10 def test_construct_decimal(self): - from generalresearch.currency import USDMill - + decimal_val: Decimal = Decimal("10.0") with pytest.warns(expected_warning=Warning) as record: - decimal_val: Decimal = Decimal("10.0") instance = USDMill(decimal_val) assert len(record) == 1 @@ -244,12 +215,11 @@ class TestUSDMillModel: assert instance == 10 # Now with rounding + decimal_val: Decimal = Decimal("10.6789") with pytest.warns(expected_warning=Warning) as record: - decimal_val: Decimal = Decimal("10.6789") instance = USDMill(decimal_val) - assert isinstance(instance, USDMill) - + assert isinstance(instance, USDMill) assert len(record) == 1 assert ( "USDMill init with a Decimal. Rounding behavior may be unexpected" @@ -260,16 +230,12 @@ class TestUSDMillModel: assert instance == 10 def test_construct_negative(self): - from generalresearch.currency import USDMill - with pytest.raises(expected_exception=ValueError) as cm: USDMill(-1) assert "USDMill not be less than zero" in str(cm.value) def test_operation_add(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val1 = randint(0, 999_999) int_val2 = randint(0, 999_999) @@ -279,9 +245,7 @@ class TestUSDMillModel: assert int_val1 + int_val2 == instance1 + instance2 def test_operation_subtract(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val1 = randint(500_000, 999_999) int_val2 = randint(0, 499_999) @@ -291,21 +255,17 @@ class TestUSDMillModel: assert int_val1 - int_val2 == instance1 - instance2 def test_operation_subtract_to_neg(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val = randint(0, 999_999) instance = USDMill(int_val) with pytest.raises(expected_exception=ValueError) as cm: - instance - USDMill(1_000_000) + _ = instance - USDMill(1_000_000) assert "USDMill not be less than zero" in str(cm.value) def test_operation_multiply(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val1 = randint(0, 999_999) int_val2 = randint(0, 999_999) @@ -315,15 +275,11 @@ class TestUSDMillModel: assert int_val1 * int_val2 == instance1 * instance2 def test_operation_div(self): - from generalresearch.currency import USDMill - with pytest.raises(ValueError) as cm: - USDMill(10) / 2 + _ = USDMill(10) / 2 assert "Division not allowed for USDMill" in str(cm.value) def test_operation_result_type(self): - from generalresearch.currency import USDMill - int_val = randint(1, 999_999) instance = USDMill(int_val) @@ -337,36 +293,30 @@ class TestUSDMillModel: assert isinstance(res_multipy, USDMill) def test_operation_partner_add(self): - from generalresearch.currency import USDMill - int_val = randint(1, 999_999) instance = USDMill(int_val) with pytest.raises(expected_exception=AssertionError): - instance + 0.10 + _ = instance + 0.10 with pytest.raises(expected_exception=AssertionError): - instance + Decimal(".10") + _ = instance + Decimal(".10") with pytest.raises(expected_exception=AssertionError): - instance + "9.9" + _ = instance + "9.9" with pytest.raises(expected_exception=AssertionError): - instance + True + _ = instance + True def test_abs(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val = abs(randint(0, 999_999)) instance = abs(USDMill(int_val)) assert int_val == instance def test_str(self): - from generalresearch.currency import USDMill - - for i in range(100): + for _ in range(100): int_val = randint(0, 999_999) instance = USDMill(int_val) @@ -376,8 +326,6 @@ class TestUSDMillModel: """There is no correct answer here, but we at least want to make sure that a USDMill is returned """ - from generalresearch.currency import USDCent, USDMill - res = USDMill(10) // 1.2 assert not isinstance(res, USDMill) assert isinstance(res, float) @@ -402,11 +350,7 @@ class TestUSDMillModel: class TestNegativeFormatting: def test_pos(self): - from generalresearch.currency import format_usd_cent - assert "-$987.65" == format_usd_cent(-98765) def test_neg(self): - from generalresearch.currency import format_usd_cent - assert "-$123.45" == format_usd_cent(-12345) |
