diff --git a/src/sakia/money/quant_zerosum.py b/src/sakia/money/quant_zerosum.py index 23e781b88eb6a4f322b2e3bf8ffd63c92fff3ef3..3f4cb1703dfe05911772525910e7d90fec9d056e 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}{2}") _UNITS_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "Q0 {0}") _FORMULA_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', """Z0 = Q - ( M(t-1) / N(t) ) @@ -102,9 +102,8 @@ class QuantitativeZSum(BaseReferential): if units or show_base: return QCoreApplication.translate("QuantitativeZSum", QuantitativeZSum._REF_STR_) \ - .format(localized_value, - prefix + (" " if prefix else ""), - (" " if units else "") + (shortened(self.currency) if units else "")) + .format(localized_value, "", + (" " + self.units if units else "")) else: return localized_value diff --git a/src/sakia/money/quantitative.py b/src/sakia/money/quantitative.py index b20793dcd1f1ca6ac316a7bdf2c4684e23f5b23e..1628854a6f0240a3007b26fd06753f97646ba066 100644 --- a/src/sakia/money/quantitative.py +++ b/src/sakia/money/quantitative.py @@ -100,7 +100,7 @@ class Quantitative(BaseReferential): Quantitative._REF_STR_) \ .format(localized_value, prefix, - (" " if prefix and units else "") + (shortened(self.currency) if units else "")) + (" " if prefix and units else "") + (self.units if units else "")) else: return localized_value @@ -115,6 +115,6 @@ class Quantitative(BaseReferential): Quantitative._REF_STR_) \ .format(localized_value, prefix, - (" " if prefix and units else "") + (shortened(self.currency) if units else "")) + (" " if prefix and units else "") + (self.diff_units if units else "")) else: return localized_value diff --git a/src/sakia/money/relative.py b/src/sakia/money/relative.py index 2443a5bf7eb88433b2f9e81a27cfafa3b534b46f..21776aa5806ee1a7b83ad5045978303fb5f3a841 100644 --- a/src/sakia/money/relative.py +++ b/src/sakia/money/relative.py @@ -7,8 +7,8 @@ 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}") - _UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD {0}") + _REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} {1}{2}") + _UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD") _FORMULA_STR_ = QT_TRANSLATE_NOOP('Relative', """R = Q / UD(t) <br > @@ -50,7 +50,7 @@ class Relative(BaseReferential): @property def units(self): - return QCoreApplication.translate("Relative", Relative._UNITS_STR_).format("") + return QCoreApplication.translate("Relative", Relative._UNITS_STR_) @property def formula(self): @@ -89,26 +89,22 @@ class Relative(BaseReferential): def localized(self, units=False, show_base=False): value = self.value() - prefix = "" localized_value = QLocale().toString(float(value), 'f', self.app.parameters.digits_after_comma) if units: return QCoreApplication.translate("Relative", Relative._REF_STR_) \ - .format(localized_value, - prefix + " " if prefix else "", - (" " + shortened(self.currency)) if units else "") + .format(localized_value, "", + (self.units if units else "")) else: return localized_value def diff_localized(self, units=False, show_base=False): value = self.differential() - prefix = "" localized_value = QLocale().toString(float(value), 'f', self.app.parameters.digits_after_comma) if units: return QCoreApplication.translate("Relative", Relative._REF_STR_) \ - .format(localized_value, - prefix + " " if prefix else "", - (" " + shortened(self.currency)) if units else "") + .format(localized_value, "", + (self.diff_units if units else "")) else: return localized_value diff --git a/src/sakia/money/relative_zerosum.py b/src/sakia/money/relative_zerosum.py index 67fb55df30622c93328640a505624497450bdf53..414acc60b7f69535b699ceea8a6193beb6e77f57 100644 --- a/src/sakia/money/relative_zerosum.py +++ b/src/sakia/money/relative_zerosum.py @@ -7,8 +7,8 @@ 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}") - _UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "R0 {0}") + _REF_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "{0} {1}{2}") + _UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "R0 UD") _FORMULA_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', """R0 = (Q / UD(t)) - (( M(t-1) / N(t) ) / UD(t)) <br > @@ -37,7 +37,7 @@ class RelativeZSum(BaseReferential): @property def units(self): - return QCoreApplication.translate("RelativeZSum", RelativeZSum._UNITS_STR_).format("") + return QCoreApplication.translate("RelativeZSum", RelativeZSum._UNITS_STR_) @property def formula(self): @@ -49,7 +49,7 @@ class RelativeZSum(BaseReferential): @property def diff_units(self): - return QCoreApplication.translate("Relative", Relative._UNITS_STR_).format(shortened("")) + return QCoreApplication.translate("Relative", Relative._UNITS_STR_) @staticmethod def base_str(base): @@ -93,7 +93,7 @@ class RelativeZSum(BaseReferential): if units: return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\ .format(localized_value, "", - (" " + shortened(self.currency)) if units else "") + self.units if units else "") else: return localized_value @@ -105,6 +105,6 @@ class RelativeZSum(BaseReferential): if units: return QCoreApplication.translate("Relative", Relative._REF_STR_)\ .format(localized_value, "", - (" " + shortened(self.currency)) if units else "") + (self.diff_units if units else "")) else: return localized_value diff --git a/tests/conftest.py b/tests/conftest.py index e2b6b6b4587a41a5522ba5cd3c84bf68b34cb925..74c50c095016f81e0eeee846c647566445998937 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))) +from sakia.constants import ROOT_SERVERS from duniterpy.documents import BlockUID from sakia.app import Application from sakia.options import SakiaOptions @@ -147,6 +148,8 @@ def simple_fake_server(fake_server, alice, bob): @pytest.fixture def application_with_one_connection(application, simple_fake_server, bob): + ROOT_SERVERS[simple_fake_server.forge.currency] = {'display': "Fake Currency", + 'nodes': []} current_block = simple_fake_server.forge.blocks[-1] last_ud_block = [b for b in simple_fake_server.forge.blocks if b.ud][-1] previous_ud_block = [b for b in simple_fake_server.forge.blocks if b.ud][-2] diff --git a/tests/unit/money/test_quantitative.py b/tests/unit/money/test_quantitative.py index 950dbe0ad87651b3f7f86de292074b7ab30ec1ac..38085d0d4fa82565bd8cce3e2cf5346e864f9b32 100644 --- a/tests/unit/money/test_quantitative.py +++ b/tests/unit/money/test_quantitative.py @@ -1,16 +1,6 @@ from sakia.money import Quantitative -def test_units(application_with_one_connection, bob): - referential = Quantitative(0, bob.currency, application_with_one_connection, None) - assert referential.units == "TC" - - -def test_diff_units(application_with_one_connection, bob): - referential = Quantitative(0, bob.currency, application_with_one_connection, None) - assert referential.units == "TC" - - def test_value(application_with_one_connection, bob): referential = Quantitative(101010110, bob.currency, application_with_one_connection, None) value = referential.value() @@ -26,7 +16,7 @@ def test_differential(application_with_one_connection, bob): def test_localized_no_si(application_with_one_connection, bob): referential = Quantitative(101010110, bob.currency, application_with_one_connection, None) value = referential.localized(units=True) - assert value == "1,010,101.10 TC" + assert value == "1,010,101.10 units" def test_localized_with_si(application_with_one_connection, bob): @@ -36,7 +26,7 @@ def test_localized_with_si(application_with_one_connection, bob): blockchain.last_ud_base = 3 application_with_one_connection.db.blockchains_repo.update(blockchain) value = referential.localized(units=True, show_base=True) - assert value == "1,010.10 .10³ TC" + assert value == "1,010.10 .10³ units" def test_localized_no_units_no_si(application_with_one_connection, bob): @@ -59,7 +49,7 @@ def test_localized_no_units_with_si(application_with_one_connection, bob): def test_diff_localized_no_si(application_with_one_connection, bob): referential = Quantitative(101010110, bob.currency, application_with_one_connection, None) value = referential.diff_localized(units=True) - assert value == "1,010,101.10 TC" + assert value == "1,010,101.10 units" def test_diff_localized_with_si(application_with_one_connection, bob): @@ -70,7 +60,7 @@ def test_diff_localized_with_si(application_with_one_connection, bob): application_with_one_connection.db.blockchains_repo.update(blockchain) value = referential.diff_localized(units=True, show_base=True) - assert value == "1,010.10 .10³ TC" + assert value == "1,010.10 .10³ units" def test_diff_localized_no_units_no_si(application_with_one_connection, bob): diff --git a/tests/unit/money/test_quantitative_zsum.py b/tests/unit/money/test_quantitative_zsum.py index cc2f0f9eef5a0705566fcfc1d6fe8de1b83784a7..2ef09e7cf4775a067908cc86f2059c4a1076d141 100644 --- a/tests/unit/money/test_quantitative_zsum.py +++ b/tests/unit/money/test_quantitative_zsum.py @@ -1,16 +1,6 @@ from sakia.money import QuantitativeZSum -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() @@ -26,14 +16,14 @@ def test_differential(application_with_one_connection, bob): 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 == "-10.79 Q0 TC" + assert value == "-10.79 Q0 units" 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, show_base=True) - assert value == "1,088.11 Q0 TC" + assert value == "1,088.11 Q0 units" def test_localized_no_units_no_si(application_with_one_connection, bob): @@ -47,13 +37,13 @@ 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, show_base=True) - assert value == "1,088.11 Q0" + assert value == "1,088.11" 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 == "1,100.00 TC" + assert value == "1,100.00 units" def test_diff_localized_with_si(application_with_one_connection, bob): @@ -63,7 +53,7 @@ def test_diff_localized_with_si(application_with_one_connection, bob): blockchain.last_ud_base = 3 application_with_one_connection.db.blockchains_repo.update(blockchain) value = referential.diff_localized(units=True, show_base=True) - assert value == "1,010.00 .10³ TC" + assert value == "1,010.00 .10³ units" def test_diff_localized_no_units_no_si(application_with_one_connection, bob): diff --git a/tests/unit/money/test_relative.py b/tests/unit/money/test_relative.py index 0bb50bf24fdefbb07b782489eb1a8231c1335c7e..d66053593871d5548394aebf4f131e8a59326875 100644 --- a/tests/unit/money/test_relative.py +++ b/tests/unit/money/test_relative.py @@ -2,16 +2,6 @@ import pytest from sakia.money import Relative -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() @@ -28,14 +18,14 @@ 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" + assert value == "0.047210 UD" 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, show_base=True) - assert value == "0.004292 UD TC" + assert value == "0.004292 UD" def test_localized_no_units_no_si(application_with_one_connection, bob): @@ -56,14 +46,14 @@ 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" + assert value == "0.047210 UD" 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, show_base=True) - assert value, "9.090909 x10⻠UD TC" + assert value, "9.090909 x10⻠UD" def test_diff_localized_no_units_no_si(application_with_one_connection, bob): diff --git a/tests/unit/money/test_relative_zsum.py b/tests/unit/money/test_relative_zsum.py index e25b410d6bbba7ddb59c4e63507cb3f50ff816cc..7aad08cf085e0549b70ba2dd5becbb14206133db 100644 --- a/tests/unit/money/test_relative_zsum.py +++ b/tests/unit/money/test_relative_zsum.py @@ -2,16 +2,6 @@ from pytest import approx from sakia.money import RelativeZSum -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() @@ -27,7 +17,7 @@ def test_differential(application_with_one_connection, bob): 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" + assert value == "-3.53 R0 UD" def test_localized_with_si(application_with_one_connection, bob): @@ -35,7 +25,7 @@ def test_localized_with_si(application_with_one_connection, bob): referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) value = referential.localized(units=True, show_base=True) - assert value == "-4.040487 R0 TC" + assert value == "-4.040487 R0 UD" def test_localized_no_units_no_si(application_with_one_connection, bob): @@ -57,7 +47,7 @@ def test_localized_no_units_with_si(application_with_one_connection, bob): 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" + assert value == "0.05 UD" def test_diff_localized_with_si(application_with_one_connection, bob): @@ -65,7 +55,7 @@ def test_diff_localized_with_si(application_with_one_connection, bob): referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) value = referential.diff_localized(units=True, show_base=True) - assert value == "0.004292 UD TC" + assert value == "0.004292 UD" def test_diff_localized_no_units_no_si(application_with_one_connection, bob):