diff --git a/src/sakia/money/quant_zerosum.py b/src/sakia/money/quant_zerosum.py index 2769a04cd63b8cfbbb3e373a16a0e398beccbc57..61ddf32eeb8052b9fad76380d9c6082552980a1b 100644 --- a/src/sakia/money/quant_zerosum.py +++ b/src/sakia/money/quant_zerosum.py @@ -7,7 +7,7 @@ from ..data.processors import BlockchainProcessor class QuantitativeZSum(BaseReferential): _NAME_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', 'Quant Z-sum') - _REF_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "{0} {1}Q0 {2}") + _REF_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "{0} {1}Q0{2}") _UNITS_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "Q0 {0}") _FORMULA_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', """Z0 = Q - ( M(t-1) / N(t) ) @@ -85,7 +85,7 @@ class QuantitativeZSum(BaseReferential): prefix = "" if international_system: - localized_value, prefix = Quantitative.to_si(value, self.app.preferences['digits_after_comma']) + localized_value, prefix = Quantitative.to_si(value, self.app.parameters.digits_after_comma) else: localized_value = QLocale().toString(float(value), 'f', 0) @@ -93,12 +93,11 @@ class QuantitativeZSum(BaseReferential): return QCoreApplication.translate("QuantitativeZSum", QuantitativeZSum._REF_STR_) \ .format(localized_value, - prefix, - shortened(self.currency) if units else "") + prefix + (" " if prefix else ""), + (" " if units else "") + (shortened(self.currency) if units else "")) else: return localized_value def diff_localized(self, units=False, international_system=False): - localized = Quantitative(self.amount, shortened(self.currency), self.app).localized(units, - international_system) + localized = Quantitative(self.amount, shortened(self.currency), self.app).localized(units, international_system) return localized diff --git a/src/sakia/money/quantitative.py b/src/sakia/money/quantitative.py index 1f016128201c9a666015acbf365c608469b183eb..5fe5fb49014ca16307b30a2cbcc365b3eb5aa670 100644 --- a/src/sakia/money/quantitative.py +++ b/src/sakia/money/quantitative.py @@ -87,10 +87,12 @@ class Quantitative(BaseReferential): if exponent > 1: localized_value = QLocale().toString(float(scientific_value * multiplier), 'f', digits) + power_of_10 = "x10" + "".join([chr(unicodes[e]) for e in str(exponent)]) else: localized_value = QLocale().toString(float(value * multiplier), 'f', 0) + power_of_10 = "" - return localized_value, "x10" + "".join([chr(unicodes[e]) for e in str(exponent)]) + return localized_value, power_of_10 def localized(self, units=False, international_system=False): value = self.value() @@ -105,7 +107,7 @@ class Quantitative(BaseReferential): Quantitative._REF_STR_) \ .format(localized_value, prefix, - " " if prefix else "" + shortened(self.currency) if units else "") + (" " if prefix and units else "") + (shortened(self.currency) if units else "")) else: return localized_value @@ -122,6 +124,6 @@ class Quantitative(BaseReferential): Quantitative._REF_STR_) \ .format(localized_value, prefix, - shortened(self.currency) if units else "") + (" " if prefix and units else "") + (shortened(self.currency) if units else "")) else: return localized_value diff --git a/src/sakia/money/relative.py b/src/sakia/money/relative.py index 45a4752aab294f9cd7609f14704668a5f272bf9c..ddb18de126a28ff60a1bbc33ee35766b03914229 100644 --- a/src/sakia/money/relative.py +++ b/src/sakia/money/relative.py @@ -8,7 +8,7 @@ from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale class Relative(BaseReferential): _NAME_STR_ = QT_TRANSLATE_NOOP('Relative', 'UD') - _REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} {1}UD {2}") + _REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} {1}UD{2}") _UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD {0}") _FORMULA_STR_ = QT_TRANSLATE_NOOP('Relative', """R = Q / UD(t) @@ -80,7 +80,7 @@ class Relative(BaseReferential): """ dividend, base = self._blockchain_processor.last_ud(self.currency) if dividend > 0: - return self.amount / float(dividend * (10**base)) + return self.amount / (float(dividend * (10**base))) else: return self.amount @@ -89,27 +89,35 @@ class Relative(BaseReferential): @staticmethod def to_si(value, digits): - prefixes = ['', 'm', 'µ', 'n', 'p', 'f', 'a', 'z', 'y'] + unicodes = { + '0': ord('\u2070'), + '1': ord('\u00B9'), + '2': ord('\u00B2'), + '3': ord('\u00B3'), + } + for n in range(4, 10): + unicodes[str(n)] = ord('\u2070') + n + if value < 0: value = -value multiplier = -1 else: multiplier = 1 scientific_value = value - prefix_index = 0 - prefix = "" + exponent = 0 - while int(scientific_value) == 0 and scientific_value > 0.0: + while scientific_value < 0.01: + exponent += 3 scientific_value *= 1000 - prefix_index += 1 - if prefix_index < len(prefixes): - prefix = prefixes[prefix_index] + if exponent > 1: localized_value = QLocale().toString(float(scientific_value * multiplier), 'f', digits) + power_of_10 = "x10â»" + "".join([chr(unicodes[e]) for e in str(exponent)]) else: localized_value = QLocale().toString(float(value * multiplier), 'f', digits) + power_of_10 = "" - return localized_value, prefix + return localized_value, power_of_10 def localized(self, units=False, international_system=False): value = self.value() @@ -122,8 +130,8 @@ class Relative(BaseReferential): if units or international_system: return QCoreApplication.translate("Relative", Relative._REF_STR_) \ .format(localized_value, - prefix, - shortened(self.currency) if units else "") + prefix + " " if prefix else "", + (" " + shortened(self.currency)) if units else "") else: return localized_value @@ -138,7 +146,7 @@ class Relative(BaseReferential): if units or international_system: return QCoreApplication.translate("Relative", Relative._REF_STR_) \ .format(localized_value, - prefix, - shortened(self.currency) if units else "") + prefix + " " if prefix else "", + (" " + shortened(self.currency)) if units else "") else: return localized_value diff --git a/src/sakia/money/relative_zerosum.py b/src/sakia/money/relative_zerosum.py index 9516f184d2bfc58a4b85458d5715c9d23015749e..94692737ae455da21c6ea9ac899ea2d4a80463dd 100644 --- a/src/sakia/money/relative_zerosum.py +++ b/src/sakia/money/relative_zerosum.py @@ -7,7 +7,7 @@ from ..data.processors import BlockchainProcessor class RelativeZSum(BaseReferential): _NAME_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', 'Relat Z-sum') - _REF_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "{0} {1}R0 {2}") + _REF_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "{0} {1}R0{2}") _UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "R0 {0}") _FORMULA_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', """R0 = (R / UD(t)) - (( M(t-1) / N(t) ) / UD(t)) @@ -66,12 +66,13 @@ class RelativeZSum(BaseReferential): :param sakia.core.community.Community community: Community instance :return: float """ - ud_block = self.community.get_ud_block() - ud_block_minus_1 = self.community.get_ud_block(x=1) - if ud_block_minus_1 and ud_block['membersCount'] > 0: - median = ud_block_minus_1['monetaryMass'] / ud_block['membersCount'] - relative_value = self.amount / float(ud_block['dividend']) - relative_median = median / ud_block['dividend'] + dividend, base = self._blockchain_processor.previous_ud(self.currency) + previous_monetary_mass = self._blockchain_processor.previous_monetary_mass(self.currency) + members_count = self._blockchain_processor.current_members_count(self.currency) + if previous_monetary_mass and members_count > 0: + median = previous_monetary_mass / members_count + relative_value = self.amount / float(dividend * 10**base) + relative_median = median / float(dividend * 10**base) else: relative_value = self.amount relative_median = 0 @@ -92,8 +93,8 @@ class RelativeZSum(BaseReferential): if units or international_system: return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\ .format(localized_value, - prefix, - shortened(self.currency) if units else "") + prefix + " " if prefix else "", + (" " + shortened(self.currency)) if units else "") else: return localized_value @@ -108,6 +109,8 @@ class RelativeZSum(BaseReferential): if units or international_system: return QCoreApplication.translate("Relative", Relative._REF_STR_)\ - .format(localized_value, prefix, shortened(self.currency) if units else "") + .format(localized_value, + prefix + " " if prefix else "", + (" " + shortened(self.currency)) if units else "") else: return localized_value diff --git a/src/sakia/tests/conftest.py b/src/sakia/tests/conftest.py index da9bd951bfc237e652f99b93141a6d6faf3c128c..9bc7e08fce96e417f5ef994cc2106bb226561faa 100644 --- a/src/sakia/tests/conftest.py +++ b/src/sakia/tests/conftest.py @@ -108,12 +108,16 @@ def simple_fake_server(fake_server, alice, bob): fake_server.forge.forge_block() fake_server.forge.set_member(alice.key.pubkey, True) fake_server.forge.set_member(bob.key.pubkey, True) - fake_server.forge.generate_dividend() - fake_server.forge.forge_block() - fake_server.forge.forge_block() - fake_server.forge.generate_dividend() - fake_server.forge.forge_block() - fake_server.forge.forge_block() + for i in range(0, 10): + new_user = mirage.User.create("test_currency", "user{0}".format(i), + "salt{0}".format(i), "password{0}".format(i), + fake_server.forge.blocks[-1].blockUID) + fake_server.forge.push(new_user.identity()) + fake_server.forge.push(new_user.join(fake_server.forge.blocks[-1].blockUID)) + fake_server.forge.forge_block() + fake_server.forge.set_member(new_user.key.pubkey, True) + fake_server.forge.generate_dividend() + fake_server.forge.forge_block() return fake_server diff --git a/src/sakia/tests/unit/core/money/test_quantitative.py b/src/sakia/tests/unit/core/money/test_quantitative.py index c9aecf8b26fb4b97009a03e852a872b97a73600e..a17318c5b995a88801a2cccdd2dc0211acf5eb61 100644 --- a/src/sakia/tests/unit/core/money/test_quantitative.py +++ b/src/sakia/tests/unit/core/money/test_quantitative.py @@ -74,4 +74,4 @@ def test_diff_localized_no_units_with_si(application_with_one_connection, bob): application_with_one_connection.parameters.digits_after_comma = 6 referential = Quantitative(101010110, bob.currency, application_with_one_connection, None) value = referential.diff_localized(units=False, international_system=True) - assert value == "101.010110 M" + assert value == "101.010110 x10â¶" diff --git a/src/sakia/tests/unit/core/money/test_quantitative_zsum.py b/src/sakia/tests/unit/core/money/test_quantitative_zsum.py index 7c530c5b111864175e56ac5bced7fa7b9c579c0a..81d2c5a535beef958c308f14629a4de9ebf714d5 100644 --- a/src/sakia/tests/unit/core/money/test_quantitative_zsum.py +++ b/src/sakia/tests/unit/core/money/test_quantitative_zsum.py @@ -1,166 +1,77 @@ -import unittest +from sakia.money import QuantitativeZSum -from PyQt5.QtCore import QLocale -from asynctest.mock import CoroutineMock, patch, PropertyMock -from sakia.money import QuantitativeZSum -from sakia.tests import QuamashTest - - -class TestQuantitativeZSum(unittest.TestCase, QuamashTest): - def setUp(self): - self.setUpQuamash() - QLocale.setDefault(QLocale("en_GB")) - - def tearDown(self): - self.tearDownQuamash() - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = QuantitativeZSum(0, community, app, None) - self.assertEqual(referential.units, "Q0 TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = QuantitativeZSum(0, community, app, None) - self.assertEqual(referential.units, "Q0 TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_value(self, app, community): - referential = QuantitativeZSum(110, community, app, None) - community.get_ud_block = CoroutineMock(return_value={'membersCount': 5}) - community.monetary_mass = CoroutineMock(return_value=500) - async def exec_test(): - value = await referential.value() - self.assertEqual(value, 10) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_differential(self, app, community): - community.get_ud_block = CoroutineMock(return_value={'membersCount': 5}) - community.monetary_mass = CoroutineMock(return_value=500) - referential = QuantitativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.value() - self.assertEqual(value, 10) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 5}) - community.monetary_mass = CoroutineMock(return_value=500) - referential = QuantitativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.localized(units=True) - self.assertEqual(value, "10 Q0 TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 1000}) - community.monetary_mass = CoroutineMock(return_value=500 * 1000) - app.preferences = { - 'digits_after_comma': 6 - } - referential = QuantitativeZSum(110 * 1000, community, app, None) - async def exec_test(): - value = await referential.localized(units=True, international_system=True) - self.assertEqual(value, "109.500000 kQ0 TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 5}) - community.monetary_mass = CoroutineMock(return_value=500) - app.preferences = { - 'digits_after_comma': 6 - } - referential = QuantitativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.localized(units=False, international_system=False) - self.assertEqual(value, "10") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 1000}) - community.monetary_mass = CoroutineMock(return_value=500 * 1000) - app.preferences = { - 'digits_after_comma': 6 - } - referential = QuantitativeZSum(110 * 1000, community, app, None) - async def exec_test(): - value = await referential.localized(units=False, international_system=True) - self.assertEqual(value, "109.500000 kQ0 ") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 1000}) - community.monetary_mass = CoroutineMock(return_value=500 * 1000 * 1000) - referential = QuantitativeZSum(110 * 1000, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=True) - self.assertEqual(value, "110,000 TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 10}) - community.monetary_mass = CoroutineMock(return_value=500 * 1000 * 1000) - app.preferences = { - 'digits_after_comma': 6 - } - referential = QuantitativeZSum(101010110, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=True, international_system=True) - self.assertEqual(value, "101.010110 MTC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 10}) - community.monetary_mass = CoroutineMock(return_value=500 * 1000 * 1000) - app.preferences = { - 'digits_after_comma': 6 - } - referential = QuantitativeZSum(101010110, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=False) - self.assertEqual(value, "101,010,110") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.get_ud_block = CoroutineMock(return_value={'membersCount': 10}) - community.monetary_mass = CoroutineMock(return_value=500 * 1000 * 1000) - app.preferences = { - 'digits_after_comma': 6 - } - referential = QuantitativeZSum(101010110, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=True) - self.assertEqual(value, "101.010110 M") - self.lp.run_until_complete(exec_test()) +def test_units(application_with_one_connection, bob): + referential = QuantitativeZSum(0, bob.currency, application_with_one_connection, None) + assert referential.units == "Q0 TC" + + +def test_diff_units(application_with_one_connection, bob): + referential = QuantitativeZSum(0, bob.currency, application_with_one_connection, None) + assert referential.units == "Q0 TC" + + +def test_value(application_with_one_connection, bob): + referential = QuantitativeZSum(110, bob.currency, application_with_one_connection, None) + value = referential.value() + assert value == -1079 + + +def test_differential(application_with_one_connection, bob): + referential = QuantitativeZSum(110, bob.currency, application_with_one_connection, None) + value = referential.value() + assert value == -1079 + + +def test_localized_no_si(application_with_one_connection, bob): + referential = QuantitativeZSum(110, bob.currency, application_with_one_connection, None) + value = referential.localized(units=True) + assert value == "-1,079 Q0 TC" + + +def test_localized_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = QuantitativeZSum(110 * 1000, bob.currency, application_with_one_connection, None) + value = referential.localized(units=True, international_system=True) + assert value == "108.811000 x10³ Q0 TC" + + +def test_localized_no_units_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = QuantitativeZSum(110, bob.currency, application_with_one_connection, None) + value = referential.localized(units=False, international_system=False) + assert value == "-1,079" + + +def test_localized_no_units_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = QuantitativeZSum(110 * 1000, bob.currency, application_with_one_connection, None) + value = referential.localized(units=False, international_system=True) + assert value == "108.811000 x10³ Q0" + + +def test_diff_localized_no_si(application_with_one_connection, bob): + referential = QuantitativeZSum(110 * 1000, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=True) + assert value == "110,000 TC" + + +def test_diff_localized_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = QuantitativeZSum(101010110, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=True, international_system=True) + assert value == "101.010110 x10â¶ TC" + + +def test_diff_localized_no_units_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = QuantitativeZSum(101010110, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=False, international_system=False) + assert value == "101,010,110" + + +def test_diff_localized_no_units_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = QuantitativeZSum(101010110, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=False, international_system=True) + assert value == "101.010110 x10â¶" diff --git a/src/sakia/tests/unit/core/money/test_relative.py b/src/sakia/tests/unit/core/money/test_relative.py index 38b8fbf0264150ebe393b82f6d0c0f4bab19aea2..c012c2e8a85f2e7b876cae072a84b8c334973f31 100644 --- a/src/sakia/tests/unit/core/money/test_relative.py +++ b/src/sakia/tests/unit/core/money/test_relative.py @@ -1,162 +1,80 @@ -import unittest +import pytest +from sakia.money import Relative -from PyQt5.QtCore import QLocale -from asynctest.mock import CoroutineMock, patch, PropertyMock -from sakia.money import Relative -from sakia.tests import QuamashTest - - -class TestRelative(unittest.TestCase, QuamashTest): - def setUp(self): - self.setUpQuamash() - QLocale.setDefault(QLocale("en_GB")) - - def tearDown(self): - self.tearDownQuamash() - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = Relative(0, community, app, None) - self.assertEqual(referential.units, "UD TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = Relative(0, community, app, None) - self.assertEqual(referential.units, "UD TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_value(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - referential = Relative(10101011, community, app, None) - async def exec_test(): - value = await referential.value() - self.assertAlmostEqual(value, 1010.10110) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_differential(self, app, community): - community.dividend = CoroutineMock(return_value=1000) - referential = Relative(110, community, app, None) - async def exec_test(): - value = await referential.value() - self.assertAlmostEqual(value, 0.11) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(101, community, app, None) - async def exec_test(): - value = await referential.localized(units=True) - self.assertEqual(value, "0.101000 UD TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.localized(units=True, international_system=True) - self.assertEqual(value, "1.011000 mUD TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.localized(units=False, international_system=False) - self.assertEqual(value, "0.101100") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.localized(units=False, international_system=True) - self.assertEqual(value, "1.011000 mUD ") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=True) - self.assertEqual(value, "0.101100 UD TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=True, international_system=True) - self.assertEqual(value, "1.011000 mUD TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=False) - self.assertEqual(value, "0.001011") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = Relative(1011, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=True) - self.assertEqual(value, "1.011000 mUD ") - self.lp.run_until_complete(exec_test()) \ No newline at end of file +def test_units(application_with_one_connection, bob): + referential = Relative(0, bob.currency, application_with_one_connection, None) + assert referential.units == "UD TC" + + +def test_diff_units(application_with_one_connection, bob): + referential = Relative(0, bob.currency, application_with_one_connection, None) + assert referential.units == "UD TC" + + +def test_value(application_with_one_connection, bob): + referential = Relative(13555300, bob.currency, application_with_one_connection, None) + value = referential.value() + assert value == pytest.approx(58177.253218) + + +def test_differential(application_with_one_connection, bob): + referential = Relative(11, bob.currency, application_with_one_connection, None) + value = referential.value() + assert value == pytest.approx(0.0472103) + + +def test_localized_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(11, bob.currency, application_with_one_connection, None) + value = referential.localized(units=True) + assert value == "0.047210 UD TC" + + +def test_localized_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(1, bob.currency, application_with_one_connection, None) + value = referential.localized(units=True, international_system=True) + assert value == "4.291845 x10â»Â³ UD TC" + + +def test_localized_no_units_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(11, bob.currency, application_with_one_connection, None) + value = referential.localized(units=False, international_system=False) + assert value == "0.047210" + + +def test_localized_no_units_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(1, bob.currency, application_with_one_connection, None) + value = referential.localized(units=False, international_system=True) + assert value == "4.291845 x10â»Â³ UD" + + +def test_diff_localized_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(11, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=True) + assert value == "0.047210 UD TC" + + +def test_diff_localized_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(1, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=True, international_system=True) + assert value, "9.090909 x10â» UD TC" + + +def test_diff_localized_no_units_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(1, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=False, international_system=False) + assert value == "0.004292" + + +def test_diff_localized_no_units_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = Relative(1, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=False, international_system=True) + assert value == "4.291845 x10â»Â³ UD" diff --git a/src/sakia/tests/unit/core/money/test_relative_to_past.py b/src/sakia/tests/unit/core/money/test_relative_to_past.py deleted file mode 100644 index 2d52d700e8cccafbed6c523d2ea7f1040b09a032..0000000000000000000000000000000000000000 --- a/src/sakia/tests/unit/core/money/test_relative_to_past.py +++ /dev/null @@ -1,194 +0,0 @@ -import unittest - -from PyQt5.QtCore import QLocale, QDateTime -from asynctest.mock import CoroutineMock, patch, PropertyMock - -from sakia.money import RelativeToPast -from sakia.tests import QuamashTest - - -class TestRelativeToPast(unittest.TestCase, QuamashTest): - def setUp(self): - self.setUpQuamash() - QLocale.setDefault(QLocale("en_GB")) - - def tearDown(self): - self.tearDownQuamash() - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = RelativeToPast(0, community, app, 100) - self.assertEqual(referential.units, "UD(t) TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = RelativeToPast(0, community, app, 100) - self.assertEqual(referential.units, "UD(t) TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_value(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - referential = RelativeToPast(10101011, community, app, 100) - async def exec_test(): - value = await referential.value() - self.assertAlmostEqual(value, 1010.10110) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_differential(self, app, community): - community.dividend = CoroutineMock(return_value=1000) - referential = RelativeToPast(110, community, app, 100) - async def exec_test(): - value = await referential.value() - self.assertAlmostEqual(value, 0.11) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(101, community, app, 100) - async def exec_test(): - value = await referential.localized(units=True) - self.assertEqual(value, "0.101000 UD({0}) TC".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(1452663088792).date(), - QLocale.dateFormat(QLocale(), QLocale.ShortFormat) - ))) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.localized(units=True, international_system=True) - self.assertEqual(value, "1.011000 mUD({0}) TC".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(1452663088792).date(), - QLocale.dateFormat(QLocale(), QLocale.ShortFormat) - ))) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.localized(units=False, international_system=False) - self.assertEqual(value, "0.101100") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.localized(units=False, international_system=True) - self.assertEqual(value, "1.011000 mUD({0}) ".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(1452663088792).date(), - QLocale.dateFormat(QLocale(), QLocale.ShortFormat) - ))) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.diff_localized(units=True) - self.assertEqual(value, "0.101100 UD({0}) TC".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(1452663088792).date(), - QLocale.dateFormat(QLocale(), QLocale.ShortFormat) - ))) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.diff_localized(units=True, international_system=True) - self.assertEqual(value, "1.011000 mUD({0}) TC".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(1452663088792).date(), - QLocale.dateFormat(QLocale(), QLocale.ShortFormat) - ))) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_no_si(self, app, community): - community.dividend = CoroutineMock(return_value=10000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=False) - self.assertEqual(value, "0.101100") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_with_si(self, app, community): - community.dividend = CoroutineMock(return_value=1000000) - community.get_ud_block = CoroutineMock(return_value={'medianTime': 1452663088792}) - type(community).short_currency = PropertyMock(return_value="TC") - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeToPast(1011, community, app, 100) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=True) - self.assertEqual(value, "1.011000 mUD({0}) ".format(QLocale.toString( - QLocale(), - QDateTime.fromTime_t(1452663088792).date(), - QLocale.dateFormat(QLocale(), QLocale.ShortFormat) - ))) - self.lp.run_until_complete(exec_test()) diff --git a/src/sakia/tests/unit/core/money/test_relative_zsum.py b/src/sakia/tests/unit/core/money/test_relative_zsum.py index 7c32b99d59daa6b990499cfdb4dba9c929fa5c23..245b679c341de913b31806910106a20d6a28d9b5 100644 --- a/src/sakia/tests/unit/core/money/test_relative_zsum.py +++ b/src/sakia/tests/unit/core/money/test_relative_zsum.py @@ -1,186 +1,82 @@ -import unittest +from pytest import approx +from sakia.money import RelativeZSum -from PyQt5.QtCore import QLocale -from asynctest.mock import CoroutineMock, patch, PropertyMock -from sakia.money import RelativeZSum -from sakia.tests import QuamashTest - - -class TestRelativeZSum(unittest.TestCase, QuamashTest): - def setUp(self): - self.setUpQuamash() - QLocale.setDefault(QLocale("en_GB")) - - def tearDown(self): - self.tearDownQuamash() - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = RelativeZSum(0, community, app, None) - self.assertEqual(referential.units, "R0 TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_units(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - referential = RelativeZSum(0, community, app, None) - self.assertEqual(referential.units, "R0 TC") - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_value(self, app, community): - referential = RelativeZSum(110, community, app, None) - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - async def exec_test(): - value = await referential.value() - self.assertAlmostEqual(value, 0.10) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_differential(self, app, community): - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - referential = RelativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.value() - self.assertAlmostEqual(value, 0.10) - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - referential = RelativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.localized(units=True) - self.assertEqual(value, "0.1 R0 TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.localized(units=True, international_system=True) - self.assertEqual(value, "100.000000 mR0 TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.localized(units=False, international_system=False) - self.assertEqual(value, "0.100000") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_localized_no_units_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeZSum(110, community, app, None) - async def exec_test(): - value = await referential.localized(units=False, international_system=True) - self.assertEqual(value, "100.000000 mR0 ") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - referential = RelativeZSum(90, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=True) - self.assertEqual(value, "0.9 UD TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeZSum(90, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=True, international_system=True) - self.assertEqual(value, "900.000000 mUD TC") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_no_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeZSum(90, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=False) - self.assertEqual(value, "0.900000") - self.lp.run_until_complete(exec_test()) - - @patch('sakia.core.Community') - @patch('sakia.core.Application') - def test_diff_localized_no_units_with_si(self, app, community): - type(community).short_currency = PropertyMock(return_value="TC") - community.dividend = CoroutineMock(return_value=100) - community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \ - {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \ - else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} ) - app.preferences = { - 'digits_after_comma': 6 - } - referential = RelativeZSum(90, community, app, None) - async def exec_test(): - value = await referential.diff_localized(units=False, international_system=True) - self.assertEqual(value, "900.000000 mUD ") - self.lp.run_until_complete(exec_test()) +def test_units(application_with_one_connection, bob): + referential = RelativeZSum(0, bob.currency, application_with_one_connection, None) + assert referential.units == "R0 TC" + + +def test_diff_units(application_with_one_connection, bob): + referential = RelativeZSum(0, bob.currency, application_with_one_connection, None) + assert referential.units == "R0 TC" + + +def test_value(application_with_one_connection, bob): + referential = RelativeZSum(2702, bob.currency, application_with_one_connection, None) + value = referential.value() + assert value == approx(8.70007) + + +def test_differential(application_with_one_connection, bob): + referential = RelativeZSum(111, bob.currency, application_with_one_connection, None) + value = referential.value() + assert value == approx(-3.521619496) + + +def test_localized_no_si(application_with_one_connection, fake_server, bob): + referential = RelativeZSum(110, bob.currency, application_with_one_connection, None) + value = referential.localized(units=True) + assert value == "-3.53 R0 TC" + + +def test_localized_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + + referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) + value = referential.localized(units=True, international_system=True) + assert value == "-4.040487 R0 TC" + + +def test_localized_no_units_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + + referential = RelativeZSum(110, bob.currency, application_with_one_connection, None) + value = referential.localized(units=False, international_system=False) + assert value == "-3.526336" + + +def test_localized_no_units_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + + referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) + value = referential.localized(units=False, international_system=True) + assert value == "-4.040487 R0" + + +def test_diff_localized_no_si(application_with_one_connection, bob): + referential = RelativeZSum(11, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=True) + assert value == "0.05 UD TC" + + +def test_diff_localized_with_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + + referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=True, international_system=True) + assert value == "4.291845 x10â»Â³ UD TC" + + +def test_diff_localized_no_units_no_si(application_with_one_connection, bob): + application_with_one_connection.parameters.digits_after_comma = 6 + referential = RelativeZSum(90, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=False, international_system=False) + assert value == "0.386266" + + +def test_diff_localized_no_units_with_si(application_with_one_connection, bob): + + referential = RelativeZSum(90, bob.currency, application_with_one_connection, None) + value = referential.diff_localized(units=False, international_system=True) + assert value == "0.39 UD"