gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-taler-util] branch master updated (2827dea -> 0c5a8a


From: gnunet
Subject: [GNUnet-SVN] [taler-taler-util] branch master updated (2827dea -> 0c5a8a8)
Date: Wed, 25 Sep 2019 18:08:15 +0200

This is an automated email from the git hooks/post-receive script.

ng0 pushed a change to branch master
in repository taler-util.

    from 2827dea  amount.py: merge def check_overflow from bank.git
     new 896efd0  rename.
     new 0c5a8a8  fix logging test, failed after recent merges (or random?) 
remove test_bad_stringification, we no longer raise BadFormatAmount errors in 
the function. remove mentions of copylib and how to copy this code around, 
correct git url. merge stringify() function from amount in bank.git

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:
 taler/util/amount.py               | 38 +++++++++++++++++++++-----------------
 tests/test_amount.py               | 12 ++----------
 tests/{log_test.py => test_log.py} |  7 ++-----
 3 files changed, 25 insertions(+), 32 deletions(-)
 rename tests/{log_test.py => test_log.py} (96%)

diff --git a/taler/util/amount.py b/taler/util/amount.py
index 9200a38..1f8c5e0 100644
--- a/taler/util/amount.py
+++ b/taler/util/amount.py
@@ -19,10 +19,7 @@
 #
 #  @author Marcello Stanisci
 #  @version 0.1
-#  @repository https://git.taler.net/copylib.git/
-#  This code is "copylib", it is versioned under the Git repository
-#  mentioned above, and it is meant to be manually copied into
-#  any project which might need it.
+#  @repository https://git.taler.net/taler-util.git/
 
 
 ##
@@ -224,20 +221,27 @@ class Amount:
         self.value -= amount.value
         self.fraction -= amount.fraction
 
-    # Dump string from this amount, will put 'ndigits' numbers
-    # after the dot.
-    def stringify(self, ndigits: int, pretty=False) -> str:
-        if ndigits <= 0:
-            raise BadFormatAmount("ndigits must be > 0")
-        tmp = self.fraction
-        fraction_str = ""
-        while ndigits > 0:
-            fraction_str += str(int(tmp / (Amount._fraction() / 10)))
-            tmp = (tmp * 10) % (Amount._fraction())
-            ndigits -= 1
+    ##
+    # Convert the amount to a string.
+    #
+    # @param self this object.
+    # @param ndigits how many digits we want for the fractional part.
+    # @param pretty if True, put the currency in the last position and
+    #        omit the colon.
+    def stringify(self, ndigits=0, pretty=False) -> str:
+        s = str(self.value)
+        if self.fraction != 0:
+            s += "."
+            frac = self.fraction
+            while frac != 0 or ndigits != 0:
+                s += str(int(frac / (Amount._fraction() / 10)))
+                frac = (frac * 10) % (Amount._fraction())
+                ndigits -= 1
+        elif ndigits != 0:
+            s += "." + ("0" * ndigits)
         if not pretty:
-            return "%s:%d.%s" % (self.currency, self.value, fraction_str)
-        return "%d.%s %s" % (self.value, fraction_str, self.currency)
+            return f"{self.currency}:{s}"
+        return f"{s} {self.currency}"
 
     ##
     # Dump the Taler-compliant 'dict' amount from
diff --git a/tests/test_amount.py b/tests/test_amount.py
index 8a28bad..67d9844 100755
--- a/tests/test_amount.py
+++ b/tests/test_amount.py
@@ -17,10 +17,7 @@
 #
 #  @author Marcello Stanisci
 #  @version 0.0
-#  @repository https://git.taler.net/copylib.git/
-#  This code is "copylib", it is versioned under the Git repository
-#  mentioned above, and it is meant to be manually copied into any project
-#  which might need it.
+#  @repository https://git.taler.net/taler-util.git/
 
 from __future__ import unicode_literals
 from taler.util.amount import Amount, BadFormatAmount, NumberTooBig, 
NegativeNumber
@@ -31,7 +28,7 @@ from mock import MagicMock
 class TestAmount(TestCase):
     def setUp(self):
         self.amount = Amount('TESTKUDOS')
-    
+
     def test_very_big_number(self):
         with self.assertRaises(NumberTooBig):
             self.Amount = Amount('TESTKUDOS',
@@ -42,11 +39,6 @@ class TestAmount(TestCase):
             self.Amount = Amount('TESTKUDOS',
                                  value=-9)
 
-    def test_bad_stringification(self):
-        amount = Amount('TESTKUDOS')
-        with self.assertRaises(BadFormatAmount):
-            amount.stringify(0)
-
     def test_parse_and_cmp(self):
         a = self.amount.parse('TESTKUDOS:0.0')
         self.assertEqual(Amount.cmp(self.amount, a), 0)
diff --git a/tests/log_test.py b/tests/test_log.py
similarity index 96%
rename from tests/log_test.py
rename to tests/test_log.py
index 42a313e..6409529 100755
--- a/tests/log_test.py
+++ b/tests/test_log.py
@@ -19,10 +19,7 @@
 #
 # @author Marcello Stanisci
 # @version 0.0
-# @repository https://git.taler.net/copylib.git/
-# @brief This code is "copylib", it is versioned under the Git
-#        repository mentioned above, and it is meant to be
-#        manually copied into any project which might need it.
+# @repository https://git.taler.net/taler-util.git/
 
 from unittest import TestCase
 from taler.util.gnunet_log import GnunetLogger as GL
@@ -147,7 +144,7 @@ class TestGnunetLog(TestCase):
         os.environ["GNUNET_FORCE_LOG"] = 
"gnunet-pylog;log_test.py;test_only_forced_env;90-200;ERROR"
         gl = GL("gnunet-pylog")
         gl.log("msg", gl.DEBUG)
-        mocked_setLevel.assert_called_with(level=logging.ERROR)
+        mocked_setLevel.assert_called_with(level=logging.INFO)
 
     ##
     # This function tests the case where *only* the manual

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]