Skip to content
Snippets Groups Projects
Commit fde33e6f authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Fix unittest for python 3

parent 3c4d42a4
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ from builtins import object
from builtins import chr
from future.utils import python_2_unicode_compatible
from binascii import hexlify, unhexlify
from .py23 import py23_bytes, bytes_types, integer_types, string_types, text_type
from .py23 import py23_bytes, py23_chr, bytes_types, integer_types, string_types, text_type
import hashlib
import sys
import string
......@@ -124,7 +124,7 @@ def base58decode(base58_str):
leading_zeroes_count = 0
for b in base58_text:
if isinstance(b, integer_types):
n = n * 58 + BASE58_ALPHABET.find(chr(b))
n = n * 58 + BASE58_ALPHABET.find(py23_chr(b))
else:
n = n * 58 + BASE58_ALPHABET.find(b)
if n == 0:
......
......@@ -2,7 +2,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import bytes, int, str
from builtins import bytes, int, str, chr
import sys
PY2 = sys.version_info[0] == 2
......@@ -31,3 +31,10 @@ def py23_bytes(item, encoding=None):
return bytes(item, encoding)
else:
return bytes(item)
def py23_chr(item):
if PY2:
return chr(item)
else:
return bytes([item])
......@@ -7,6 +7,7 @@ import pytest
import unittest
from beemgraphenebase.py23 import (
py23_bytes,
py23_chr,
bytes_types,
integer_types,
string_types,
......@@ -105,10 +106,14 @@ class Testcases(unittest.TestCase):
def test_string_types(self):
a = 'abc'
b = u'abc'
c = b'abc'
self.assertTrue(isinstance(a, string_types))
self.assertTrue(isinstance(b, string_types))
self.assertTrue(isinstance(c, string_types))
def test_chr(self):
BASE58_ALPHABET = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
self.assertEqual(BASE58_ALPHABET.find(py23_chr(4)), -1)
self.assertEqual(BASE58_ALPHABET.find(b"Z"), 32)
self.assertEqual(BASE58_ALPHABET.find(py23_bytes("Z", "ascii")), 32)
if __name__ == '__main__':
......
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