aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-01-12 19:32:00 +0100
committerFlorian Dold <florian.dold@gmail.com>2020-01-12 19:32:00 +0100
commit7d15041f8a1aad859ed26fc7d6b5c7d882cfbc8c (patch)
treefdc1afcb72ec261afa7759bc2ebb3fce214483f9 /tests
parent1dcfbcbeae7fed4a9dec575cdd0275ee2727d670 (diff)
downloadtaler-util-7d15041f8a1aad859ed26fc7d6b5c7d882cfbc8c.tar.gz
taler-util-7d15041f8a1aad859ed26fc7d6b5c7d882cfbc8c.tar.bz2
taler-util-7d15041f8a1aad859ed26fc7d6b5c7d882cfbc8c.zip
formatting, throw correct exception, version bump, more tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_amount.py44
-rwxr-xr-xtests/test_log.py21
2 files changed, 45 insertions, 20 deletions
diff --git a/tests/test_amount.py b/tests/test_amount.py
index 3dd386a..559dd2c 100755
--- a/tests/test_amount.py
+++ b/tests/test_amount.py
@@ -19,32 +19,51 @@
# @version 0.0
# @repository https://git.taler.net/taler-util.git/
-from taler.util.amount import Amount, SignedAmount, AmountOverflowError, MAX_AMOUNT_VALUE
+from taler.util.amount import (
+ Amount,
+ SignedAmount,
+ AmountFormatError,
+ AmountOverflowError,
+ MAX_AMOUNT_VALUE,
+)
from unittest import TestCase
import json
+
class TestAmount(TestCase):
def test_very_big_number(self):
with self.assertRaises(AmountOverflowError):
- self.Amount = Amount('TESTKUDOS',
- value=99999999999999999999999999999999999999999999,
- fraction=0)
+ self.Amount = Amount(
+ "TESTKUDOS",
+ value=99999999999999999999999999999999999999999999,
+ fraction=0,
+ )
def test_add_overflow(self):
- a1 = Amount('TESTKUDOS',
- value=MAX_AMOUNT_VALUE,
- fraction=0)
+ a1 = Amount("TESTKUDOS", value=MAX_AMOUNT_VALUE, fraction=0)
with self.assertRaises(AmountOverflowError):
a2 = a1 + Amount.parse("TESTKUDOS:1")
def test_sub_overflow(self):
- a1 = Amount('TESTKUDOS',
- value=MAX_AMOUNT_VALUE,
- fraction=0)
+ a1 = Amount("TESTKUDOS", value=MAX_AMOUNT_VALUE, fraction=0)
s1 = SignedAmount(False, a1)
with self.assertRaises(AmountOverflowError):
s2 = s1 - SignedAmount.parse("TESTKUDOS:1")
+ def test_parse_error(self):
+ with self.assertRaises(AmountFormatError):
+ Amount.parse("TESTKUDOS:0,5")
+ with self.assertRaises(AmountFormatError):
+ Amount.parse("+TESTKUDOS:0.5")
+ with self.assertRaises(AmountFormatError):
+ Amount.parse("0.5")
+ with self.assertRaises(AmountFormatError):
+ Amount.parse(":0.5")
+ with self.assertRaises(AmountFormatError):
+ Amount.parse("EUR::0.5")
+ with self.assertRaises(AmountFormatError):
+ Amount.parse("EUR:.5")
+
def test_parse_and_cmp(self):
self.assertTrue(Amount.parse("EUR:0.0") < Amount.parse("EUR:0.5"))
@@ -52,7 +71,9 @@ class TestAmount(TestCase):
self.assertEqual(Amount.parse("TESTKUDOS:0").stringify(3), "TESTKUDOS:0.000")
def test_signed_amount(self):
- self.assertEqual(SignedAmount.parse("TESTKUDOS:1.5").stringify(3), "+TESTKUDOS:1.500")
+ self.assertEqual(
+ SignedAmount.parse("TESTKUDOS:1.5").stringify(3), "+TESTKUDOS:1.500"
+ )
def test_zero_crossing(self):
p1 = SignedAmount.parse("EUR:1")
@@ -66,4 +87,3 @@ class TestAmount(TestCase):
self.assertEqual(p2 - p3, -p1)
self.assertEqual((-p2) + p3, p1)
-
diff --git a/tests/test_log.py b/tests/test_log.py
index 6409529..5d982d5 100755
--- a/tests/test_log.py
+++ b/tests/test_log.py
@@ -48,8 +48,6 @@ def clean_env():
del os.environ["GNUNET_FORCE_LOGFILE"]
-
-
##
# "mother" class of all the tests. NOTE: no logs will appear
# on screen, as the setLevel function is mocked (therefore the
@@ -82,7 +80,10 @@ class TestGnunetLog(TestCase):
gl.log("msg", gl.DEBUG)
today = datetime.now()
- expected_filename = "/tmp/gnunet-pylog-%s-%s.log" % (str(os.getpid()), today.strftime("%Y_%m_%d"))
+ expected_filename = "/tmp/gnunet-pylog-%s-%s.log" % (
+ str(os.getpid()),
+ today.strftime("%Y_%m_%d"),
+ )
mocked_FileHandler.assert_called_with(expected_filename)
mocked_addHandler.assert_called_with(unused_mock)
@@ -107,7 +108,6 @@ class TestGnunetLog(TestCase):
gl.log("msg", gl.DEBUG)
mocked_setLevel.assert_called_with(level=logging.INFO)
-
##
# This function tests the case where *only* the GNUNET_LOG
# env variable is set -- not even the manual setup of the
@@ -122,7 +122,9 @@ class TestGnunetLog(TestCase):
@patch("logging.basicConfig")
def test_non_forced_env(self, mocked_basicConfig, mocked_setLevel):
self.assertIsNone(os.environ.get("GNUNET_FORCE_LOG"))
- os.environ["GNUNET_LOG"] = "gnunet-pylog;log_test.py;test_non_forced_env;99;ERROR" # lineno is not 100% accurate.
+ os.environ[
+ "GNUNET_LOG"
+ ] = "gnunet-pylog;log_test.py;test_non_forced_env;99;ERROR" # lineno is not 100% accurate.
gl = GL("gnunet-pylog")
gl.log("msg", gl.DEBUG)
mocked_setLevel.assert_called_with(level=logging.INFO)
@@ -141,7 +143,9 @@ class TestGnunetLog(TestCase):
@patch("logging.basicConfig")
def test_only_forced_env(self, mocked_basicConfig, mocked_setLevel):
self.assertIsNone(os.environ.get("GNUNET_LOG"))
- os.environ["GNUNET_FORCE_LOG"] = "gnunet-pylog;log_test.py;test_only_forced_env;90-200;ERROR"
+ 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.INFO)
@@ -165,7 +169,6 @@ class TestGnunetLog(TestCase):
gl.log("msg", gl.DEBUG)
mocked_setLevel.assert_called_with(level=logging.ERROR)
-
##
# This function tests the case where *both* the manual loglevel
# and the forced env variable are setup; the expected result is
@@ -204,7 +207,9 @@ class TestGnunetLog(TestCase):
# the real setLevel.
@patch("logging.Logger.setLevel")
@patch("logging.basicConfig")
- def test_manual_loglevel_AND_nonforced_env(self, mocked_basicConfig, mocked_setLevel):
+ def test_manual_loglevel_AND_nonforced_env(
+ self, mocked_basicConfig, mocked_setLevel
+ ):
self.assertIsNone(os.environ.get("GNUNET_LOG"))
self.assertIsNone(os.environ.get("GNUNET_FORCE_LOG"))
os.environ["GNUNET_LOG"] = ";;;;DEBUG"