Skip to content
Snippets Groups Projects
Commit 15e33434 authored by inso's avatar inso
Browse files

Fix errors in tests

parent 223d55ef
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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]
......
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):
......
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):
......
......@@ -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):
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment