gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-python] branch master updated (bda184f -> a3707a2)


From: gnunet
Subject: [gnunet-python] branch master updated (bda184f -> a3707a2)
Date: Sun, 12 Apr 2020 23:22:18 +0200

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

htgoebel pushed a change to branch master
in repository gnunet-python.

    from bda184f  fixes
     new 4309d80  Add a small test-suite.
     new a49b946  Extend .gitignore.
     new 41724f1  Simplify initiation of `_Key` and subclasses.
     new 602cde1  Avoid "During handling of the above exception" when 
re-raising.
     new cc1e04b  Add '_Key.__repr__()' to eliminate redundant code in 
subclasses.
     new 87ecb65  Use relative imports.
     new a755de6  Add test-cases for strings.string_to_absolute_time.
     new 5759c1f  Replace spaghetti code by loops.
     new 7bff538  Add test-cases for strings.data_to_string and string_to_data.
     new 4b41816  Mark strings.encTable as private.
     new 8028efd  Use upper-case names for global constant values.
     new a3707a2  Break some very long lines and some other minor code-cleanup.

The 12 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:
 .gitignore                  | 18 ++++++++++++-
 gnunet/__init__.py          | 29 +++++++++++---------
 gnunet/_dbus_utils.py       | 30 +++++++++++++--------
 gnunet/block.py             |  2 +-
 gnunet/crypto.py            | 10 ++-----
 gnunet/dht.py               | 34 ++++++++++++++----------
 gnunet/gns.py               | 21 ++++++++-------
 gnunet/gnsrecord.py         | 21 +++++++++------
 gnunet/strings.py           | 64 ++++++++++++++-------------------------------
 setup.py                    |  8 +++++-
 tests/unit/test_crypto.py   | 31 ++++++++++++++++++++++
 tests/unit/test_hashcode.py | 32 +++++++++++++++++++++++
 tests/unit/test_strings.py  | 50 +++++++++++++++++++++++++++++++++++
 13 files changed, 240 insertions(+), 110 deletions(-)
 create mode 100644 tests/unit/test_crypto.py
 create mode 100644 tests/unit/test_hashcode.py
 create mode 100644 tests/unit/test_strings.py

diff --git a/.gitignore b/.gitignore
index 7e6f516..221635c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,20 @@
 *.swp
 *.swo
-/gnunet/__pycache__
 
+*~
+.\#*
+\#*#
+
+*.py[co]
+__pycache__/
+/build/
+/dist/
+/*.egg
+/*.egg-info/
+/*.egg-link
+/MANIFEST
+/.eggs/
+/.pytest_cache/
+
+# py.test cache folder
+.cache
diff --git a/gnunet/__init__.py b/gnunet/__init__.py
index dc4e701..eb43c56 100644
--- a/gnunet/__init__.py
+++ b/gnunet/__init__.py
@@ -1,4 +1,4 @@
-import gnunet.strings as strings
+from . import strings
 
 
 class GNUNetDaemonError(Exception):
@@ -6,27 +6,32 @@ class GNUNetDaemonError(Exception):
 
 
 class _Key:
-    def __init__(self, arg, subtype, bits):
-        if isinstance(arg, subtype):
+    def __init__(self, arg):
+        if isinstance(arg, type(self)):
             self._data = arg._data
         elif isinstance(arg, str):
             self._data = strings.string_to_data(arg)
         else:
             try:
                 self._data = bytearray(arg)
-            except:
-                raise TypeError("'arg' must be a " + type(subtype).__name__ + 
", a string or an array of bytes. Not a '" + type(arg).__name__ + "'.")
+            except TypeError as e:
+                # HACK: replace the exception message
+                e.args = ("'arg' must be a %s, a string or an array "
+                          "of bytes. Not a '%s'." %
+                          (type(self).__name__, type(arg).__name__),)
+                raise
 
-        if len(self._data) * 8 != bits:
-            raise ValueError("'arg' must be a " + bits + " bit hash. Got " + 
len(self._data) + " bits.")
+        if len(self._data) * 8 != self.__bits__:
+            raise ValueError("'arg' must be a %s bit hash. Got %s bits."
+                             % (self.__bits__, len(self._data) * 8))
 
     def __str__(self):
         return strings.data_to_string(self._data)
 
+    def __repr__(self):
+        cls = self.__class__
+        return "%s.%s(%r)" % (cls.__module__, cls.__name__, str(self))
 
-class HashCode(_Key):
-    def __init__(self, arg):
-        _Key.__init__(self, arg, HashCode, 512)
 
-    def __repr__(self):
-        return "gnunet.HashCode('" + str(self) + "')"
+class HashCode(_Key):
+    __bits__ = 512
diff --git a/gnunet/_dbus_utils.py b/gnunet/_dbus_utils.py
index 803f8bb..26cdadd 100644
--- a/gnunet/_dbus_utils.py
+++ b/gnunet/_dbus_utils.py
@@ -1,8 +1,10 @@
-from gnunet import _Key, GNUNetDaemonError
-import gnunet.strings as strings
+from . import _Key, GNUNetDaemonError
+from . import strings
+
 import dbus
 import threading
 import datetime
+
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
@@ -30,7 +32,8 @@ def pythonize(arg, argtype):
         if isinstance(arg, str):
             return strings.string_to_absolute_time(arg)
         if isinstance(arg. dbus.UInt64):
-            return datetime.datetime(1970, 1, 1) + 
datetime.timedelta(microseconds=arg)
+            return (datetime.datetime(1970, 1, 1)
+                    + datetime.timedelta(microseconds=arg))
         return datetime.datetime(arg)
 
 
@@ -46,7 +49,8 @@ def dbusize(arg, pretty):
 
     if isinstance(arg, datetime.datetime):
         if pretty:
-            return dbus.String(strings.absolute_time_to_string(arg), 
variant_level=1)
+            return dbus.String(strings.absolute_time_to_string(arg),
+                               variant_level=1)
         else:
             return dbus.UInt64((arg - datetime.datetime(1970, 1, 
1)).total_seconds() * 1000000, variant_level=1)
 
@@ -58,12 +62,16 @@ def handle_exception(e, daemon, daemon_address):
         raise e
     name = name[len("org.freedesktop.DBus.Error."):]
 
-    if name == "Failed" or name == "InvalidArgs":
+    if name in ("Failed", "InvalidArgs"):
         raise GNUNetDaemonError(message)
-    if name == "NoMemory":
+    elif name == "NoMemory":
         raise MemoryError(message)
-    if name == "ServiceUnknown" or name == "NameHasNoOwner":
-        raise GNUNetDaemonError("Failed to contact " + daemon + " daemon at " 
+ daemon_address)
-    if name == "NoReply" or name == "Timeout":
-        raise GNUNetDaemonError("Did not receive reply from " + daemon + " 
daemon at " + daemon_address + ". Daemon might of crashed")
-    raise e
+    elif name in ("ServiceUnknown", "NameHasNoOwner"):
+        raise GNUNetDaemonError("Failed to contact %s daemon at %s" %
+                                (daemon, daemon_address))
+    elif name in ("NoReply", "Timeout"):
+        raise GNUNetDaemonError("Did not receive reply from %s daemon at %s. "
+                                "Daemon might of crashed."
+                                % (daemon, daemon_address))
+    else:
+        raise e
diff --git a/gnunet/block.py b/gnunet/block.py
index ec363e0..2c9fbd0 100644
--- a/gnunet/block.py
+++ b/gnunet/block.py
@@ -1,4 +1,4 @@
-types = set([
+TYPES = set([
     "any",
     "fs_dblock",
     "fs_iblock",
diff --git a/gnunet/crypto.py b/gnunet/crypto.py
index 461b0cc..c4841d5 100644
--- a/gnunet/crypto.py
+++ b/gnunet/crypto.py
@@ -1,10 +1,4 @@
-from gnunet import _Key
-import gnunet.strings as strings
-
+from . import _Key
 
 class EcdsaPublicKey(_Key):
-    def __init__(self, arg):
-        _Key.__init__(self, arg, EcdsaPublicKey, 256)
-
-    def __repr__(self):
-        return "gnunet.crypto.EcdsaPublicKey('" + str(self) + "')"
+    __bits__ = 256
diff --git a/gnunet/dht.py b/gnunet/dht.py
index fc86e22..e9aa525 100644
--- a/gnunet/dht.py
+++ b/gnunet/dht.py
@@ -2,10 +2,9 @@ import dbus
 
 import datetime
 
-from gnunet import *
-from gnunet._dbus_utils import *
-
-import gnunet.block as block
+from . import *
+from . import block
+from ._dbus_utils import *
 
 get_requests = {}
 requests_lock = threading.Lock()
@@ -31,9 +30,12 @@ class GetResult(threading.Thread):
 
         if request:
             if request.record_route:
-                request.callback(self.block_type, self.key, self.data, 
self.expiry, get_path=self.get_path, put_path=self.put_path)
+                request.callback(self.block_type, self.key, self.data,
+                                 self.expiry, get_path=self.get_path,
+                                 put_path=self.put_path)
             else:
-                request.callback(self.block_type, self.key, self.data, 
self.expiry)
+                request.callback(self.block_type, self.key, self.data,
+                                 self.expiry)
 
 
 def _result(expiry, key, get_path, put_path, block_type, data, path):
@@ -45,7 +47,8 @@ def _result(expiry, key, get_path, put_path, block_type, 
data, path):
     data = bytearray(data)
     GetResult(expiry, key, get_path, put_path, block_type, data, path)
 
-sysbus.add_signal_receiver(_result, "result", "gnu.gnunet.dht.get", 
"gnu.gnunet.dht", path_keyword="path")
+sysbus.add_signal_receiver(_result, "result", "gnu.gnunet.dht.get",
+                           "gnu.gnunet.dht", path_keyword="path")
 
 
 class GetRequest:
@@ -55,7 +58,8 @@ class GetRequest:
         self.record_route = record_route
 
     def filter_known_results(self, keys):
-        keys = dbus.Array([dbusize(HashCode(key)) for key in list(keys)], 
signature="v")
+        keys = dbus.Array([dbusize(HashCode(key))
+                           for key in list(keys)], signature="v")
         try:
             sysbus.get_object("gnu.gnunet.dht", 
self._path).filter_known_results(keys, dbus_interface="gnu.gnunet.dht.get")
         except dbus.DBusException as e:
@@ -68,11 +72,12 @@ class GetRequest:
             handle_exception(e, "dht", "gnu.gnunet.dht")
 
 
-def put(key, desired_replication_level, block_type, data, expiry=None, 
demultiplex_everywhere=False, record_route=False, bart=False):
+def put(key, desired_replication_level, block_type, data, expiry=None,
+        demultiplex_everywhere=False, record_route=False, bart=False):
     key = dbusize(HashCode(key), True)
     desired_replication_level = dbus.UInt32(desired_replication_level)
-    if block_type not in block.types:
-        raise ValueError("'block_type' must be one of %s" % block.types)
+    if block_type not in block.TYPES:
+        raise ValueError("'block_type' must be one of %s" % block.TYPES)
     block_type = dbus.String(block_type, variant_level=1)
     if expiry is not None:
         if not isinstance(expiry, datetime.datetime):
@@ -95,9 +100,10 @@ def put(key, desired_replication_level, block_type, data, 
expiry=None, demultipl
         handle_exception(e, "dht", "gnu.gnunet.dht")
 
 
-def get_start(callback, block_type, key, desired_replication_level, 
demultiplex_everywhere=False, record_route=False, bart=False):
-    if block_type not in block.types:
-        raise ValueError("'block_type' must be one of %s" % block.types)
+def get_start(callback, block_type, key, desired_replication_level,
+              demultiplex_everywhere=False, record_route=False, bart=False):
+    if block_type not in block.TYPES:
+        raise ValueError("'block_type' must be one of %s" % block.TYPES)
     block_type = dbus.String(block_type, variant_level=1)
     key = dbusize(HashCode(key), True)
     desired_replication_level = dbus.UInt32(desired_replication_level)
diff --git a/gnunet/gns.py b/gnunet/gns.py
index b2d5e64..b46b681 100644
--- a/gnunet/gns.py
+++ b/gnunet/gns.py
@@ -1,23 +1,25 @@
 import dbus
 
-from gnunet._dbus_utils import *
+from . import *
+from . import crypto
+from . import gnsrecord
 
-from gnunet import *
-import gnunet.crypto as crypto
-import gnunet.gnsrecord as gnsrecord
+from ._dbus_utils import *
 
 
 def lookup(name, zone, record_type, only_cached):
     name = str(name)
     zone = dbusize(crypto.EcdsaPublicKey(zone), True)
-    if record_type not in gnsrecord.types:
-        raise ValueError("'record_type' must be one of %s" % gnsrecord.types)
-    # record_type = dbus.UInt32(gnsrecord.types[record_type], variant_level=1)
+    if record_type not in gnsrecord.TYPES:
+        raise ValueError("'record_type' must be one of %s" % gnsrecord.TYPES)
+    # record_type = dbus.UInt32(gnsrecord.TYPES[record_type], variant_level=1)
     record_type = dbus.String(record_type, variant_level=1)
     only_cached = dbus.Boolean(only_cached)
 
     try:
-        results = sysbus.get_object("gnu.gnunet.gns", "/").lookup(name, zone, 
record_type, only_cached)
+        results = sysbus.get_object("gnu.gnunet.gns", "/").lookup(name, zone,
+                                                                  record_type,
+                                                                  only_cached)
     except dbus.DBusException as e:
         handle_exception(e, "gns", "gnu.gnunet.gns")
 
@@ -43,6 +45,7 @@ def lookup(name, zone, record_type, only_cached):
             expiration_time = pythonize(r[3], datetime.timedelta)
         else:
             expiration_time = pythonize(r[3], datetime.datetime)
-        ret.append(gnsrecord.Data(record_type, data, expiration_time, private, 
pending, shadow))
+        ret.append(gnsrecord.Data(record_type, data, expiration_time,
+                                  private, pending, shadow))
 
     return ret
diff --git a/gnunet/gnsrecord.py b/gnunet/gnsrecord.py
index 1cb0d72..d869d05 100644
--- a/gnunet/gnsrecord.py
+++ b/gnunet/gnsrecord.py
@@ -1,7 +1,7 @@
 import datetime
 
 
-dns_types = {
+DNS_TYPES = {
     "A":      1,
     "NS":     2,
     "CNAME":  5,
@@ -13,7 +13,7 @@ dns_types = {
     "TLSA":   52}
 
 
-gns_types = {
+GNS_TYPES = {
     "PKEY":     65536,
     "NICK":     65537,
     "LEHO":     65538,
@@ -21,18 +21,23 @@ gns_types = {
     "GNS2DNS":  65540}
 
 
-types = dict(list(dns_types.items()) + list(gns_types.items()))
+TYPES = dict(DNS_TYPES.items())
+TYPES.update(GNS_TYPES.items())
 
 
 class Data:
-    def __init__(self, record_type, data, expiration_time=None, private=None, 
pending=None, shadow=None):
+    def __init__(self, record_type, data, expiration_time=None, private=None,
+                 pending=None, shadow=None):
         self.record_type = str(record_type)
-        if record_type not in types:
-            raise ValueError("'record_type' must be one of %s" % types)
+        if record_type not in TYPES:
+            raise ValueError("'record_type' must be one of %s" % TYPES)
         # self.data = bytearray(data)
         self.data = str(data)
-        if expiration_time is not None and not isinstance(expiration_time, 
datetime.datetime) or isinstance(expiration_time, datetime.timedelta):
-            raise TypeError("'expiration_time' must be a datetime.datetime or 
a datetime.timedelta")
+        if (expiration_time is not None and
+            not isinstance(expiration_time,
+                           (datetime.datetime, datetime.timedelta))):
+            raise TypeError("'expiration_time' must be a datetime.datetime "
+                            "or a datetime.timedelta")
         self.expiration_time = expiration_time
         self.private = private
         self.pending = pending
diff --git a/gnunet/strings.py b/gnunet/strings.py
index 595c450..5bf2c9e 100644
--- a/gnunet/strings.py
+++ b/gnunet/strings.py
@@ -1,9 +1,9 @@
 import datetime
 
-from gnunet import *
+from . import *
 
 
-encTable = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
+__encTable = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
 
 
 def data_to_string(data):
@@ -20,9 +20,9 @@ def data_to_string(data):
             vbit += 8
         while vbit >= 5:
             vbit -= 5
-            ret += encTable[(bits >> vbit) & 31]
+            ret += __encTable[(bits >> vbit) & 31]
     if vbit > 0:
-        ret += encTable[(bits << (5 - vbit)) & 31]
+        ret += __encTable[(bits << (5 - vbit)) & 31]
     return ret
 
 
@@ -53,48 +53,22 @@ def string_to_data(s):
 def absolute_time_to_string(t):
     return t.strftime("%a %b %d %H:%M:%S %Y")
 
-
 def string_to_absolute_time(s):
     if s == "end of time":
         return None
-    try:
-        return datetime.datetime.strptime(s, "%a %b %d %H:%M:%S %Y")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%c")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Ec")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%x")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Ex")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Y-%m-%d")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Y-%m")
-    except ValueError:
-        pass
-    try:
-        return datetime.datetime.strptime(s, "%Y")
-    except ValueError:
-        pass
+    for fmt in (
+            "%a %b %d %H:%M:%S %Y",
+            "%c",
+            "%Ec",
+            "%Y-%m-%d %H:%M:%S",
+            "%Y-%m-%d %H:%M",
+            "%x",
+            "%Ex",
+            "%Y-%m-%d",
+            "%Y-%m",
+            "%Y"):
+        try:
+            return datetime.datetime.strptime(s, fmt)
+        except ValueError:
+            pass
     raise ValueError("%s is not a properly formatted time string" % s)
diff --git a/setup.py b/setup.py
index 2d7b91e..f0a6dfd 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,13 @@ setup(
     license="GNU GPLv3+",
     keywords="GNUnet binding p2p",
     url="https://gnunet.org";,
-    long_description="""GNUnet is an alternative network stack for building 
secure, decentralized and privacy-preserving distributed applications. Our goal 
is to replace the old insecure Internet protocol stack. Starting from an 
application for secure publication of files, it has grown to include all kinds 
of basic protocol components and applications towards the creation of a GNU 
internet.
+    long_description="""
+    GNUnet is an alternative network stack for building secure,
+    decentralized and privacy-preserving distributed applications. Our
+    goal is to replace the old insecure Internet protocol stack.
+    Starting from an application for secure publication of files, it
+    has grown to include all kinds of basic protocol components and
+    applications towards the creation of a GNU internet.
 
 GNUnet is an official GNU package.
 
diff --git a/tests/unit/test_crypto.py b/tests/unit/test_crypto.py
new file mode 100644
index 0000000..ab3db79
--- /dev/null
+++ b/tests/unit/test_crypto.py
@@ -0,0 +1,31 @@
+import pytest
+
+from gnunet.crypto import EcdsaPublicKey
+
+def test___repr__():
+    k = EcdsaPublicKey(b"abcd"*(256//8//4))
+    assert repr(k).startswith('gnunet.crypto.EcdsaPublicKey(')
+
+def test___init__string():
+    s = "C5H66P31C9HM8OB2CDI62OJ3CHGM4OR4C5H66P31C9HM8OB2CDI0"
+    k = EcdsaPublicKey(s)
+
+def test___init__bytes():
+    k = EcdsaPublicKey(b"abcd"*(256//8//4))
+
+def test___init_EcdsaPublicKey():
+    k1 = EcdsaPublicKey(b"abcd"*(256//8//4))
+    k2 = EcdsaPublicKey(k1)
+    assert k1._data == k2._data
+
+def test___init__string_wrong_size():
+    with pytest.raises(ValueError):
+        k = EcdsaPublicKey("abcd")
+    with pytest.raises(ValueError):
+        k = EcdsaPublicKey("abcd"*256)
+
+def test___init__bytes_wrong_size():
+    with pytest.raises(ValueError):
+        k = EcdsaPublicKey(b"abcd")
+    with pytest.raises(ValueError):
+        k = EcdsaPublicKey(b"abcd"*256)
diff --git a/tests/unit/test_hashcode.py b/tests/unit/test_hashcode.py
new file mode 100644
index 0000000..d40cdd9
--- /dev/null
+++ b/tests/unit/test_hashcode.py
@@ -0,0 +1,32 @@
+import pytest
+
+from gnunet import HashCode
+
+def test___repr__():
+    k = HashCode(b"abcd"*(512//8//4))
+    assert repr(k).startswith('gnunet.HashCode(')
+
+def test___init__string():
+    s = ("C5H66P31C9HM8OB2CDI62OJ3CHGM4OR4C5H66P31C9HM8OB2CDI6"
+         "2OJ3CHGM4OR4C5H66P31C9HM8OB2CDI62OJ3CHGM4OR4C5H66P0")
+    k = HashCode(s)
+
+def test___init__bytes():
+    k = HashCode(b"abcd"*(512//8//4))
+
+def test___init_HashCode():
+    k1 = HashCode(b"abcd"*(512//8//4))
+    k2 = HashCode(k1)
+    assert k1._data == k2._data
+
+def test___init__string_wrong_size():
+    with pytest.raises(ValueError):
+        k = HashCode("abcd")
+    with pytest.raises(ValueError):
+        k = HashCode("abcd"*512)
+
+def test___init__bytes_wrong_size():
+    with pytest.raises(ValueError):
+        k = HashCode(b"abcd")
+    with pytest.raises(ValueError):
+        k = HashCode(b"abcd"*512)
diff --git a/tests/unit/test_strings.py b/tests/unit/test_strings.py
new file mode 100644
index 0000000..835a508
--- /dev/null
+++ b/tests/unit/test_strings.py
@@ -0,0 +1,50 @@
+import pytest
+
+from gnunet import strings
+
+import locale
+locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
+
+test_dates = (
+    ("Sat Jan 07 19:54:12 2008", (2008, 1, 7, 19, 54, 12)),
+    ("Thu 27 Mar 2005 11:05:25 PM CET", (2005, 3, 27, 23, 5, 25)),
+    # FIXME: need test-case for %Ec
+    ("2019-02-23 16:07:22", (2019, 2, 23, 16, 7, 22)),
+    ("1998-08-17 14:33", (1998, 8, 17, 14, 33, 0)),
+    ("12/15/2007", (2007, 12, 15, 0, 0, 0)),
+    # FIXME: need test-case for %Ex
+    ("2019-02-26", (2019, 2, 26, 0, 0, 0)),
+    ("2014-03-23", (2014, 3, 23, 0, 0, 0)),
+    ("2020", (2020, 1, 1, 0, 0, 0))
+    )
+
+@pytest.mark.parametrize("datestr,expected", test_dates)
+def test_string_to_absolute_time(datestr, expected):
+    dt = strings.string_to_absolute_time(datestr)
+    assert dt.timetuple()[:6] == expected
+
+
+def test_string_to_absolute_time_end_of_time():
+    assert strings.string_to_absolute_time("end of time") is None
+
+
+def test_string_to_absolute_invalid():
+    with pytest.raises(ValueError) as excinfo:
+        strings.string_to_absolute_time("asdfgh")
+    assert str(excinfo.value).startswith("asdfgh is not a properly formatted")
+
+
+def test_data_to_string():
+    assert strings.data_to_string(b"") == ""
+    assert strings.data_to_string(b"dfgzu") == "CHJ6EUJL"
+
+
+def test_string_to_data():
+    assert strings.string_to_data("") == b""
+    assert strings.string_to_data("CHJ6EUJL") == b"dfgzu"
+    with pytest.raises(ValueError) as excinfo:
+        strings.string_to_data("asdfgh")
+    assert "is not a valid data-encoding string" in str(excinfo.value)
+    with pytest.raises(ValueError) as excinfo:
+        strings.string_to_data(["asdfgh"])
+    assert "is not a valid data-encoding string" in str(excinfo.value)

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



reply via email to

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