Skip to content
Snippets Groups Projects
Commit 0bad720a authored by inso's avatar inso
Browse files

Merge branch 'feature/past_dividend' into dev

parents 3aaa5de1 2846e905
No related branches found
No related tags found
No related merge requests found
Showing
with 1056 additions and 74 deletions
...@@ -116,13 +116,16 @@ class Community(QObject): ...@@ -116,13 +116,16 @@ class Community(QObject):
u = ord('\u24B6') + ord(letter) - ord('A') u = ord('\u24B6') + ord(letter) - ord('A')
return chr(u) return chr(u)
async def dividend(self): async def dividend(self, block_number=None):
""" """
Get the last generated community universal dividend. Get the last generated community universal dividend before block_number.
If block_number is None, returns the last block_number.
:param int block_number: The block at which we get the latest dividend
:return: The last UD or 1 if no UD was generated. :return: The last UD or 1 if no UD was generated.
""" """
block = await self.get_ud_block() block = await self.get_ud_block(block_number=block_number)
if block: if block:
return block['dividend'] return block['dividend']
else: else:
...@@ -152,18 +155,24 @@ class Community(QObject): ...@@ -152,18 +155,24 @@ class Community(QObject):
else: else:
return 1 return 1
async def get_ud_block(self, x=0): async def get_ud_block(self, x=0, block_number=None):
""" """
Get a block with universal dividend Get a block with universal dividend
If x and block_number are passed to the result,
it returns the 'x' older block with UD in it BEFORE block_number
:param int x: Get the 'x' older block with UD in it :param int x: Get the 'x' older block with UD in it
:param int block_number: Get the latest dividend before this block number
:return: The last block with universal dividend. :return: The last block with universal dividend.
:rtype: dict
""" """
try: try:
udblocks = await self.bma_access.future_request(bma.blockchain.UD) udblocks = await self.bma_access.future_request(bma.blockchain.UD)
blocks = udblocks['result']['blocks'] blocks = udblocks['result']['blocks']
if block_number:
blocks = [b for b in blocks if b <= block_number]
if len(blocks) > 0: if len(blocks) > 0:
index = len(blocks)-(1+x) index = len(blocks) - (1+x)
if index < 0: if index < 0:
index = 0 index = 0
block_number = blocks[index] block_number = blocks[index]
......
...@@ -2,5 +2,6 @@ from .quantitative import Quantitative ...@@ -2,5 +2,6 @@ from .quantitative import Quantitative
from .relative import Relative from .relative import Relative
from .quant_zerosum import QuantitativeZSum from .quant_zerosum import QuantitativeZSum
from .relative_zerosum import RelativeZSum from .relative_zerosum import RelativeZSum
from .relative_to_past import RelativeToPast
Referentials = (Quantitative, Relative, QuantitativeZSum, RelativeZSum) Referentials = (Quantitative, Relative, QuantitativeZSum, RelativeZSum, RelativeToPast)
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QObject, QLocale
import asyncio
class BaseReferential:
"""
Interface to all referentials
"""
def __init__(self, amount, community, app, block_number=None):
self.amount = amount
self.community = community
self.app = app
self._block_number = block_number
@classmethod
def translated_name(self):
pass
@property
def units(self):
pass
@property
def diff_units(self):
pass
async def value(self):
pass
async def differential(self):
pass
@staticmethod
def to_si(value, digits):
pass
async def localized(self, units=False, international_system=False):
pass
async def diff_localized(self, units=False, international_system=False):
pass
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
from . import Quantitative from . import Quantitative
import asyncio from .base_referential import BaseReferential
class QuantitativeZSum: class QuantitativeZSum(BaseReferential):
_NAME_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', 'Quant Z-sum') _NAME_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', 'Quant Z-sum')
_REF_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "{0} Q0 {1}") _REF_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "{0} {1}Q0 {2}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "Q0 {0}") _UNITS_STR_ = QT_TRANSLATE_NOOP('QuantitativeZSum', "Q0 {0}")
def __init__(self, amount, community, app): def __init__(self, amount, community, app, block_number=None):
self.amount = amount super().__init__(amount, community, app, block_number)
self.community = community
self.app = app
@classmethod @classmethod
def translated_name(cls): def translated_name(cls):
return QCoreApplication.translate('QuantitativeZSum', QuantitativeZSum._NAME_STR_) return QCoreApplication.translate('QuantitativeZSum', QuantitativeZSum._NAME_STR_)
@classmethod @property
def units(cls, currency): def units(self):
return QCoreApplication.translate("QuantitativeZSum", QuantitativeZSum._UNITS_STR_).format(currency) return QCoreApplication.translate("QuantitativeZSum", QuantitativeZSum._UNITS_STR_).format(self.community.short_currency)
@classmethod @property
def diff_units(cls, currency): def diff_units(self):
return Quantitative.units(currency) return self.units
async def value(self): async def value(self):
""" """
...@@ -43,7 +41,7 @@ class QuantitativeZSum: ...@@ -43,7 +41,7 @@ class QuantitativeZSum:
ud_block = await self.community.get_ud_block() ud_block = await self.community.get_ud_block()
if ud_block and ud_block['membersCount'] > 0: if ud_block and ud_block['membersCount'] > 0:
monetary_mass = await self.community.monetary_mass() monetary_mass = await self.community.monetary_mass()
average = monetary_mass / ud_block['membersCount'] average = int(monetary_mass / ud_block['membersCount'])
else: else:
average = 0 average = 0
return self.amount - average return self.amount - average
...@@ -60,10 +58,11 @@ class QuantitativeZSum: ...@@ -60,10 +58,11 @@ class QuantitativeZSum:
else: else:
localized_value = QLocale().toString(float(value), 'f', 0) localized_value = QLocale().toString(float(value), 'f', 0)
if units: if units or international_system:
return QCoreApplication.translate("QuantitativeZSum", return QCoreApplication.translate("QuantitativeZSum",
QuantitativeZSum._REF_STR_) \ QuantitativeZSum._REF_STR_) \
.format(localized_value, .format(localized_value,
prefix,
self.community.short_currency if units else "") self.community.short_currency if units else "")
else: else:
return localized_value return localized_value
......
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QObject, QLocale from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
import asyncio from .base_referential import BaseReferential
class Quantitative(): class Quantitative(BaseReferential):
_NAME_STR_ = QT_TRANSLATE_NOOP('Quantitative', 'Units') _NAME_STR_ = QT_TRANSLATE_NOOP('Quantitative', 'Units')
_REF_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0} {1}{2}") _REF_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0} {1}{2}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0}") _UNITS_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0}")
def __init__(self, amount, community, app): def __init__(self, amount, community, app, block_number=None):
self.amount = amount super().__init__(amount, community, app, block_number)
self.community = community
self.app = app
@classmethod @classmethod
def translated_name(cls): def translated_name(cls):
return QCoreApplication.translate('Quantitative', Quantitative._NAME_STR_) return QCoreApplication.translate('Quantitative', Quantitative._NAME_STR_)
@classmethod @property
def units(cls, currency): def units(self):
return QCoreApplication.translate("Quantitative", Quantitative._UNITS_STR_).format(currency) return QCoreApplication.translate("Quantitative", Quantitative._UNITS_STR_).format(self.community.short_currency)
@classmethod @property
def diff_units(cls, currency): def diff_units(self):
return Quantitative.units(currency) return self.units
async def value(self): async def value(self):
""" """
......
from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale
import asyncio from .base_referential import BaseReferential
class Relative: class Relative(BaseReferential):
_NAME_STR_ = QT_TRANSLATE_NOOP('Relative', 'UD') _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}") _UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD {0}")
def __init__(self, amount, community, app): def __init__(self, amount, community, app, block_number=None):
self.amount = amount super().__init__(amount, community, app, block_number)
self.community = community
self.app = app
@classmethod @classmethod
def translated_name(cls): def translated_name(cls):
return QCoreApplication.translate('Relative', Relative._NAME_STR_) return QCoreApplication.translate('Relative', Relative._NAME_STR_)
@classmethod @property
def units(self, currency): def units(self):
return QCoreApplication.translate("Relative", Relative._UNITS_STR_).format(currency) return QCoreApplication.translate("Relative", Relative._UNITS_STR_).format(self.community.short_currency)
@classmethod @property
def diff_units(self, currency): def diff_units(self):
return self.units(currency) return self.units
async def value(self): async def value(self):
""" """
......
from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale, QDateTime
from .base_referential import BaseReferential
from . import Relative
class RelativeToPast(BaseReferential):
_NAME_STR_ = QT_TRANSLATE_NOOP('RelativeToPast', 'Past UD')
_REF_STR_ = QT_TRANSLATE_NOOP('RelativeToPast', "{0} {1}UD({2}) {3}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeToPast', "UD({0}) {1}")
def __init__(self, amount, community, app, block_number=None):
super().__init__(amount, community, app, block_number)
@classmethod
def translated_name(cls):
return QCoreApplication.translate('RelativeToPast', RelativeToPast._NAME_STR_)
@property
def units(self):
return QCoreApplication.translate("RelativeToPast", RelativeToPast._UNITS_STR_).format('t',
self.community.short_currency)
@property
def diff_units(self):
return self.units
async def value(self):
"""
Return relative to past value of amount
:return: float
"""
dividend = await self.community.dividend()
if dividend > 0:
return self.amount / float(dividend)
else:
return self.amount
async def differential(self):
"""
Return relative to past differential value of amount
:return: float
"""
dividend = await self.community.dividend(self._block_number)
if dividend > 0:
return self.amount / float(dividend)
else:
return self.amount
async def localized(self, units=False, international_system=False):
value = await self.value()
block = await self.community.get_block()
prefix = ""
if international_system:
localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units or international_system:
return QCoreApplication.translate("RelativeToPast", RelativeToPast._REF_STR_) \
.format(localized_value,
prefix,
QLocale.toString(
QLocale(),
QDateTime.fromTime_t(block['medianTime']).date(),
QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
),
self.community.short_currency if units else "")
else:
return localized_value
async def diff_localized(self, units=False, international_system=False):
value = await self.differential()
block = await self.community.get_block(self._block_number)
prefix = ""
if international_system and value != 0:
localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units or international_system:
return QCoreApplication.translate("RelativeToPast", RelativeToPast._REF_STR_)\
.format(localized_value,
prefix,
QLocale.toString(
QLocale(),
QDateTime.fromTime_t(block['medianTime']).date(),
QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
),
self.community.short_currency if units else "")
else:
return localized_value
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
from .relative import Relative from .relative import Relative
import asyncio from .base_referential import BaseReferential
class RelativeZSum: class RelativeZSum(BaseReferential):
_NAME_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', 'Relat Z-sum') _NAME_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', 'Relat Z-sum')
_REF_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "{0} R0 {1}") _REF_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "{0} {1}R0 {2}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "R0 {0}") _UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "R0 {0}")
def __init__(self, amount, community, app): def __init__(self, amount, community, app, block_number=None):
self.amount = amount super().__init__(amount, community, app, block_number)
self.community = community
self.app = app
@classmethod @classmethod
def translated_name(cls): def translated_name(cls):
return QCoreApplication.translate('RelativeZSum', RelativeZSum._NAME_STR_) return QCoreApplication.translate('RelativeZSum', RelativeZSum._NAME_STR_)
@classmethod @property
def units(cls, currency): def units(self):
return QCoreApplication.translate("RelativeZSum", RelativeZSum._UNITS_STR_).format(currency) return QCoreApplication.translate("RelativeZSum", RelativeZSum._UNITS_STR_).format(self.community.short_currency)
@classmethod @property
def diff_units(cls, currency): def diff_units(self):
return Relative.units(currency) return self.units
async def value(self): async def value(self):
""" """
...@@ -41,7 +39,7 @@ class RelativeZSum: ...@@ -41,7 +39,7 @@ class RelativeZSum:
:return: float :return: float
""" """
ud_block = await self.community.get_ud_block() ud_block = await self.community.get_ud_block()
ud_block_minus_1 = await self.community.get_ud_block(1) ud_block_minus_1 = await self.community.get_ud_block(x=1)
if ud_block_minus_1 and ud_block['membersCount'] > 0: if ud_block_minus_1 and ud_block['membersCount'] > 0:
median = ud_block_minus_1['monetaryMass'] / ud_block['membersCount'] median = ud_block_minus_1['monetaryMass'] / ud_block['membersCount']
relative_value = self.amount / float(ud_block['dividend']) relative_value = self.amount / float(ud_block['dividend'])
...@@ -63,9 +61,10 @@ class RelativeZSum: ...@@ -63,9 +61,10 @@ class RelativeZSum:
else: else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma']) localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units: if units or international_system:
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\ return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\
.format(localized_value, .format(localized_value,
prefix,
self.community.short_currency if units else "") self.community.short_currency if units else "")
else: else:
return localized_value return localized_value
...@@ -79,8 +78,8 @@ class RelativeZSum: ...@@ -79,8 +78,8 @@ class RelativeZSum:
else: else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma']) localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units: if units or international_system:
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\ return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\
.format(localized_value, self.community.short_currency if units else "") .format(localized_value, prefix, self.community.short_currency if units else "")
else: else:
return localized_value return localized_value
...@@ -70,7 +70,7 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -70,7 +70,7 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
logging.debug('community get_ud_block error : ' + str(e)) logging.debug('community get_ud_block error : ' + str(e))
return False return False
try: try:
block_ud_minus_1 = await self.community.get_ud_block(1) block_ud_minus_1 = await self.community.get_ud_block(x=1)
except NoPeerAvailable as e: except NoPeerAvailable as e:
logging.debug('community get_ud_block error : ' + str(e)) logging.debug('community get_ud_block error : ' + str(e))
return False return False
...@@ -125,15 +125,15 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -125,15 +125,15 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
""").format( """).format(
localized_ud, localized_ud,
self.tr('Universal Dividend UD(t) in'), self.tr('Universal Dividend UD(t) in'),
self.account.current_ref.diff_units(self.community.currency), self.account.current_ref(0, self.community, self.app, None).diff_units,
localized_mass_minus_1, localized_mass_minus_1,
self.tr('Monetary Mass M(t-1) in'), self.tr('Monetary Mass M(t-1) in'),
self.account.current_ref.diff_units(self.community.currency), self.account.current_ref(0, self.community, self.app, None).units,
block_ud['membersCount'], block_ud['membersCount'],
self.tr('Members N(t)'), self.tr('Members N(t)'),
localized_mass_minus_1_per_member, localized_mass_minus_1_per_member,
self.tr('Monetary Mass per member M(t-1)/N(t) in'), self.tr('Monetary Mass per member M(t-1)/N(t) in'),
self.account.current_ref.diff_units(self.community.currency), self.account.current_ref(0, self.community, self.app, None).diff_units,
float(0) if block_ud['membersCount'] == 0 or block_ud_minus_1['monetaryMass'] == 0 else float(0) if block_ud['membersCount'] == 0 or block_ud_minus_1['monetaryMass'] == 0 else
block_ud['dividend'] / (block_ud_minus_1['monetaryMass'] / block_ud['membersCount']), block_ud['dividend'] / (block_ud_minus_1['monetaryMass'] / block_ud['membersCount']),
...@@ -179,10 +179,10 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -179,10 +179,10 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
self.tr('{:} = MAX {{ {:} {:} ; {:2.0%} &#215; {:} {:} / {:} }}').format( self.tr('{:} = MAX {{ {:} {:} ; {:2.0%} &#215; {:} {:} / {:} }}').format(
localized_ud_plus_1, localized_ud_plus_1,
localized_ud, localized_ud,
self.account.current_ref.diff_units(self.community.currency), self.account.current_ref(0, self.community, self.app, None).diff_units,
params['c'], params['c'],
localized_mass, localized_mass,
self.account.current_ref.diff_units(self.community.currency), self.account.current_ref(0, self.community, self.app, None).diff_units,
block_ud['membersCount'] block_ud['membersCount']
), ),
self.tr('Universal Dividend (computed)') self.tr('Universal Dividend (computed)')
......
...@@ -231,7 +231,8 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -231,7 +231,8 @@ class HistoryTableModel(QAbstractTableModel):
async def data_received(self, transfer): async def data_received(self, transfer):
amount = transfer.metadata['amount'] amount = transfer.metadata['amount']
deposit = await self.account.current_ref(transfer.metadata['amount'], self.community, self.app)\ deposit = await self.account.current_ref(transfer.metadata['amount'], self.community,
self.app, transfer.blockid.number)\
.diff_localized(international_system=self.app.preferences['international_system_of_units']) .diff_localized(international_system=self.app.preferences['international_system_of_units'])
comment = "" comment = ""
if transfer.metadata['comment'] != "": if transfer.metadata['comment'] != "":
...@@ -254,7 +255,8 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -254,7 +255,8 @@ class HistoryTableModel(QAbstractTableModel):
async def data_sent(self, transfer): async def data_sent(self, transfer):
amount = transfer.metadata['amount'] amount = transfer.metadata['amount']
paiment = await self.account.current_ref(transfer.metadata['amount'], self.community, self.app)\ paiment = await self.account.current_ref(transfer.metadata['amount'], self.community,
self.app, transfer.blockid.number)\
.diff_localized(international_system=self.app.preferences['international_system_of_units']) .diff_localized(international_system=self.app.preferences['international_system_of_units'])
comment = "" comment = ""
if transfer.metadata['comment'] != "": if transfer.metadata['comment'] != "":
...@@ -277,7 +279,7 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -277,7 +279,7 @@ class HistoryTableModel(QAbstractTableModel):
async def data_dividend(self, dividend): async def data_dividend(self, dividend):
amount = dividend['amount'] amount = dividend['amount']
deposit = await self.account.current_ref(dividend['amount'], self.community, self.app)\ deposit = await self.account.current_ref(dividend['amount'], self.community, self.app, dividend['block_number'])\
.diff_localized(international_system=self.app.preferences['international_system_of_units']) .diff_localized(international_system=self.app.preferences['international_system_of_units'])
comment = "" comment = ""
receiver = self.account.name receiver = self.account.name
...@@ -334,7 +336,7 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -334,7 +336,7 @@ class HistoryTableModel(QAbstractTableModel):
if self.columns_types[section] == 'payment' or self.columns_types[section] == 'deposit': if self.columns_types[section] == 'payment' or self.columns_types[section] == 'deposit':
return '{:}\n({:})'.format( return '{:}\n({:})'.format(
self.column_headers[section](), self.column_headers[section](),
self.account.current_ref.diff_units(self.community.short_currency) self.account.current_ref(0, self.community, self.app, None).diff_units
) )
return self.column_headers[section]() return self.column_headers[section]()
......
...@@ -112,7 +112,7 @@ class WalletsTableModel(QAbstractTableModel): ...@@ -112,7 +112,7 @@ class WalletsTableModel(QAbstractTableModel):
if self.columns_types[section] == 'amount': if self.columns_types[section] == 'amount':
return '{:}\n({:})'.format( return '{:}\n({:})'.format(
self.columns_headers[section], self.columns_headers[section],
self.account.current_ref.units(self.community.short_currency) self.account.current_ref(0, self.community, self.app, None).units
) )
return self.columns_headers[section] return self.columns_headers[section]
......
import unittest
from asynctest.mock import Mock, CoroutineMock, patch, PropertyMock
from PyQt5.QtCore import QLocale
from sakia.tests import QuamashTest
from sakia.core.money import Quantitative
class TestQuantitative(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 = Quantitative(0, community, app, None)
self.assertEqual(referential.units, "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 = Quantitative(0, community, app, None)
self.assertEqual(referential.units, "TC")
@patch('sakia.core.Community')
@patch('sakia.core.Application')
def test_value(self, app, community):
referential = Quantitative(101010110, community, app, None)
async def exec_test():
value = await referential.value()
self.assertEqual(value, 101010110)
self.lp.run_until_complete(exec_test())
@patch('sakia.core.Community')
@patch('sakia.core.Application')
def test_differential(self, app, community):
referential = Quantitative(110, community, app, None)
async def exec_test():
value = await referential.value()
self.assertEqual(value, 110)
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")
referential = Quantitative(101010110, community, app, None)
async def exec_test():
value = await referential.localized(units=True)
self.assertEqual(value, "101,010,110 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")
app.preferences = {
'digits_after_comma': 6
}
referential = Quantitative(101010110, community, app, None)
async def exec_test():
value = await referential.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_localized_no_units_no_si(self, app, community):
type(community).short_currency = PropertyMock(return_value="TC")
app.preferences = {
'digits_after_comma': 6
}
referential = Quantitative(101010110, community, app, None)
async def exec_test():
value = await referential.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_localized_no_units_with_si(self, app, community):
type(community).short_currency = PropertyMock(return_value="TC")
app.preferences = {
'digits_after_comma': 6
}
referential = Quantitative(101010110, community, app, None)
async def exec_test():
value = await referential.localized(units=False, international_system=True)
self.assertEqual(value, "101.010110 M")
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")
referential = Quantitative(101010110, community, app, None)
async def exec_test():
value = await referential.diff_localized(units=True)
self.assertEqual(value, "101,010,110 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")
app.preferences = {
'digits_after_comma': 6
}
referential = Quantitative(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")
app.preferences = {
'digits_after_comma': 6
}
referential = Quantitative(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")
app.preferences = {
'digits_after_comma': 6
}
referential = Quantitative(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())
import unittest
from asynctest.mock import Mock, CoroutineMock, patch, PropertyMock
from PyQt5.QtCore import QLocale
from sakia.tests import QuamashTest
from sakia.core.money import QuantitativeZSum
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())
import unittest
from asynctest.mock import Mock, CoroutineMock, patch, PropertyMock
from PyQt5.QtCore import QLocale
from sakia.tests import QuamashTest
from sakia.core.money import Relative
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=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=True, international_system=True)
self.assertEqual(value, "1.011000 dUD 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=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=True)
self.assertEqual(value, "1.011000 dUD ")
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=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, international_system=True)
self.assertEqual(value, "1.011000 dUD 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=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=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=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=False, international_system=True)
self.assertEqual(value, "1.011000 dUD ")
self.lp.run_until_complete(exec_test())
\ No newline at end of file
import unittest
from asynctest.mock import Mock, CoroutineMock, patch, PropertyMock
from PyQt5.QtCore import QLocale, QDateTime
from sakia.tests import QuamashTest
from sakia.core.money import RelativeToPast
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_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=10000)
community.get_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 dUD({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_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=10000)
community.get_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 dUD({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_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=10000)
community.get_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 dUD({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_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=10000)
community.get_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 dUD({0}) ".format(QLocale.toString(
QLocale(),
QDateTime.fromTime_t(1452663088792).date(),
QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
)))
self.lp.run_until_complete(exec_test())
import unittest
from asynctest.mock import Mock, CoroutineMock, patch, PropertyMock
from PyQt5.QtCore import QLocale
from sakia.tests import QuamashTest
from sakia.core.money import RelativeZSum
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, "1.000000 dR0 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, "1.000000 dR0 ")
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 R0 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, "9.000000 dR0 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, "9.000000 dR0 ")
self.lp.run_until_complete(exec_test())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment