[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated (2
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated (2030c9e -> 0b5a237) |
Date: |
Tue, 21 Feb 2017 11:11:59 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a change to branch master
in repository merchant-frontend-examples.
from 2030c9e Going on with Python tutorial..
new 7c068c6 Half-baking string_to_amount
new 0b5a237 string_to_amount
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc | Bin 1272 -> 1712 bytes
Python/lib/pytaler/amounts.py | 15 ++++++++++++++-
Python/lib/pytaler/tests.py | 14 ++++++++++----
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc
b/Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc
index 24b724e..5f665fb 100644
Binary files a/Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc and
b/Python/lib/pytaler/__pycache__/amounts.cpython-35.pyc differ
diff --git a/Python/lib/pytaler/amounts.py b/Python/lib/pytaler/amounts.py
index ee7b0d1..00f9ae4 100644
--- a/Python/lib/pytaler/amounts.py
+++ b/Python/lib/pytaler/amounts.py
@@ -14,10 +14,23 @@
#
# @author Marcello Stanisci
+import re
+
FRACTION = 100000000
def amount_get_zero(currency):
- return {"value": 0, "fraction": 0, "currency": currency}
+ return dict(value=0, fraction=0, currency=currency)
+
+def string_to_amount(fmt):
+ pattern = re.compile("^[0-9]+\.[0-9]+:[A-Z]+$")
+ assert(pattern.match(fmt))
+ split = fmt.split(":")
+ num = split[0]
+ currency = split[1]
+ split = num.split(".")
+ value = int(split[0])
+ fraction = int(split[1]) * FRACTION
+ return dict(value=value, fraction=fraction, currency=currency)
def amount_sum(a1, a2):
diff --git a/Python/lib/pytaler/tests.py b/Python/lib/pytaler/tests.py
index 120e968..ffc8cba 100644
--- a/Python/lib/pytaler/tests.py
+++ b/Python/lib/pytaler/tests.py
@@ -2,13 +2,13 @@ import unittest
import amounts
from random import randint
-currency = "KUDOS"
+CURRENCY = "KUDOS"
class AmountsTest(unittest.TestCase):
- def test(self):
- a1 = amounts.amount_get_zero(currency)
- a2 = amounts.amount_get_zero(currency)
+ def test_sum_sub(self):
+ a1 = amounts.amount_get_zero(CURRENCY)
+ a2 = amounts.amount_get_zero(CURRENCY)
v1 = randint(1, 200)
v2 = randint(1, 200)
f1 = randint(10000000, 100000000)
@@ -22,5 +22,11 @@ class AmountsTest(unittest.TestCase):
self.assertTrue(amounts.same_amount(res2, a2))
+ def test_string_to_amount(self):
+ model = dict(value=1, fraction=0, currency=CURRENCY)
+ amount = amounts.string_to_amount("1.0:%s" % CURRENCY)
+ self.assertTrue(amounts.same_amount(model, amount))
+
+
if __name__ == '__main__':
unittest.main()
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated (2030c9e -> 0b5a237),
gnunet <=