From 19f65420018b600ba190dc67dea6b2d8947c1ca3 Mon Sep 17 00:00:00 2001 From: Eduard Carreras Date: Mon, 9 Dec 2019 17:58:11 +0100 Subject: [PATCH 1/9] Inital support for py3 --- bankbarcode/__init__.py | 2 +- bankbarcode/bankbarcode.py | 3 ++- bankbarcode/cuaderno57.py | 3 ++- setup.py | 7 ++----- spec/cuaderno57_Recibo507_due_date_spec.py | 6 +++--- spec/cuaderno57_Recibo507_input_spec.py | 2 +- spec/cuaderno57_Recibo_input_spec.py | 2 +- spec/input_spec.py | 2 +- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bankbarcode/__init__.py b/bankbarcode/__init__.py index b74a6cb..410a8aa 100644 --- a/bankbarcode/__init__.py +++ b/bankbarcode/__init__.py @@ -1,5 +1,5 @@ try: __version__ = __import__('pkg_resources') \ .get_distribution(__name__).version -except Exception, e: +except Exception as e: __version__ = 'unknown' diff --git a/bankbarcode/bankbarcode.py b/bankbarcode/bankbarcode.py index ca8e004..51c08a8 100644 --- a/bankbarcode/bankbarcode.py +++ b/bankbarcode/bankbarcode.py @@ -1,5 +1,6 @@ from barcode import generate -from StringIO import StringIO +import six +from six.moves import StringIO class BankBarcode(object): diff --git a/bankbarcode/cuaderno57.py b/bankbarcode/cuaderno57.py index e6b6594..3b28b42 100644 --- a/bankbarcode/cuaderno57.py +++ b/bankbarcode/cuaderno57.py @@ -1,7 +1,8 @@ # coding=utf-8 +from __future__ import absolute_import from datetime import datetime -from bankbarcode import BankBarcode +from .bankbarcode import BankBarcode from decimal import Decimal diff --git a/setup.py b/setup.py index b072e82..c1257c3 100644 --- a/setup.py +++ b/setup.py @@ -13,12 +13,9 @@ author_email='devel@gisce.net', # We need python-barcode v0.8, to have Code128 (EAN128), not released yet # https://bitbucket.org/whitie/python-barcode/issues/16/pypi-08-release-request - dependency_links=[ - "https://bitbucket.org/whitie/python-barcode/get/6c22b96.zip" - "#egg=pybarcode-0.8b1" - ], install_requires=[ - 'pybarcode>=0.8b1' + 'python-barcode', + 'six' ], description='barcodes for financial documents' ) diff --git a/spec/cuaderno57_Recibo507_due_date_spec.py b/spec/cuaderno57_Recibo507_due_date_spec.py index 9fcf148..c4889f3 100644 --- a/spec/cuaderno57_Recibo507_due_date_spec.py +++ b/spec/cuaderno57_Recibo507_due_date_spec.py @@ -11,7 +11,7 @@ def callback(): ref = '12345678901' notice = '123456' amount = '6543.21' - due_date = datetime(2015, 11, 01) + due_date = datetime(2015, 11, 0o1) recibo = Recibo507(entity, suffix, ref, notice, amount, due_date) expect(callback).to( raise_error(ValueError, @@ -23,7 +23,7 @@ def callback(): ref = '00000000015' notice = '300815' amount = '53.98' - due_date = datetime(2015, 11, 01) + due_date = datetime(2015, 11, 0o1) recibo = Recibo507(entity, suffix, ref, notice, amount, due_date) expect(recibo.notice).not_to(equal(notice)) expect(recibo.notice).to(equal(due_date.strftime('%d%m%y'))) @@ -35,7 +35,7 @@ def callback(): notice = '300815' amount = '53.98' checksum = '27' - due_date = datetime(2015, 11, 01) + due_date = datetime(2015, 11, 0o1) recibo = Recibo507(entity, suffix, ref, notice, amount, due_date) expect(recibo.notice).to(equal(due_date.strftime('%d%m%y'))) expect(recibo.checksum()).to(equal(checksum)) diff --git a/spec/cuaderno57_Recibo507_input_spec.py b/spec/cuaderno57_Recibo507_input_spec.py index 071068a..55b5122 100644 --- a/spec/cuaderno57_Recibo507_input_spec.py +++ b/spec/cuaderno57_Recibo507_input_spec.py @@ -1,4 +1,4 @@ -from sys import maxint +from sys import maxsize from expects import expect, be_true, raise_error from random import randint, uniform, random from bankbarcode.cuaderno57 import Recibo507 diff --git a/spec/cuaderno57_Recibo_input_spec.py b/spec/cuaderno57_Recibo_input_spec.py index 400b0cd..46aff5a 100644 --- a/spec/cuaderno57_Recibo_input_spec.py +++ b/spec/cuaderno57_Recibo_input_spec.py @@ -1,4 +1,4 @@ -from sys import maxint +from sys import maxsize from datetime import datetime from expects import expect, be_true, raise_error from random import randint, uniform, random diff --git a/spec/input_spec.py b/spec/input_spec.py index 9aa9244..972a709 100644 --- a/spec/input_spec.py +++ b/spec/input_spec.py @@ -1,4 +1,4 @@ -from sys import maxint +from sys import maxsize from expects import expect, be_true, raise_error from random import randint from bankbarcode.bankbarcode import BankBarcode From c16e97462c03fecc8df6b335434b606457d6782e Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 11:21:52 +0000 Subject: [PATCH 2/9] Compat code unicode and instances --- bankbarcode/bankbarcode.py | 3 ++- bankbarcode/cuaderno57.py | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bankbarcode/bankbarcode.py b/bankbarcode/bankbarcode.py index 51c08a8..1f11115 100644 --- a/bankbarcode/bankbarcode.py +++ b/bankbarcode/bankbarcode.py @@ -1,6 +1,7 @@ from barcode import generate import six from six.moves import StringIO +from six import string_types class BankBarcode(object): @@ -31,7 +32,7 @@ def _check_length(self, name, value, expected_length, description): return True def _strip_dotsvg(self, path): - if isinstance(path, basestring) and path[-4:] == '.svg': + if isinstance(path, string_types) and path[-4:] == '.svg': new_path = path[:-4] else: new_path = path diff --git a/bankbarcode/cuaderno57.py b/bankbarcode/cuaderno57.py index 3b28b42..d60b70f 100644 --- a/bankbarcode/cuaderno57.py +++ b/bankbarcode/cuaderno57.py @@ -1,9 +1,10 @@ # coding=utf-8 -from __future__ import absolute_import +from __future__ import absolute_import, unicode_literals from datetime import datetime from .bankbarcode import BankBarcode from decimal import Decimal +from six import text_type, string_types class Recibo(BankBarcode): @@ -73,7 +74,7 @@ def _check_amount(self, amount): raise ValueError('{} have more than 2 decimals'.format(name)) if decimal > 99999999.99: raise ValueError('{} is too big'.format(name)) - value = unicode(int(decimal * 100)).zfill(10) + value = text_type(int(decimal * 100)).zfill(10) expected_length = 10 description = 'amount lenth should be 10' return self._check_length(name, value, expected_length, description) @@ -89,7 +90,7 @@ def _check_due_date(self, due_date, suffix): name = 'due_date' if due_date is None: return True - if isinstance(due_date, basestring): + if isinstance(due_date, string_types): try: date = datetime.strptime(due_date, '%Y-%m-%d') except: @@ -226,7 +227,7 @@ def amount(self, value): :param value: the amount (Importe) """ - unicode_value = unicode(value) + unicode_value = text_type(value) if self._check_amount(unicode_value): self._amount = unicode_value @@ -245,7 +246,7 @@ def due_date(self, due_date): self._due_date = None else: if self._check_due_date(due_date, self.suffix): - if isinstance(due_date, basestring): + if isinstance(due_date, string_types): due_date = datetime.strptime(due_date, '%Y-%m-%d') self._due_date = due_date self._notice = self._due_date.strftime('%d%m%y') @@ -276,7 +277,7 @@ def checksum(self): decimals = int(Decimal(sum) / 97 % 1 * 100) if not decimals: return '00' - return unicode(100 - decimals).zfill(2) + return text_type(100 - decimals).zfill(2) def code(self): """ @@ -284,11 +285,11 @@ def code(self): :return: an unicode string with the code for the barcode """ - id_application = u'90' - format_type = u'507' - parity = u'0' + id_application = '90' + format_type = '507' + parity = '0' - amount100 = unicode(self.amount100()).zfill(10) + amount100 = text_type(self.amount100()).zfill(10) code = ( '{id_application}' From 930e896c4fae878c2b13033baf2e96b5a2bd3223 Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 13:31:09 +0000 Subject: [PATCH 3/9] Add github actions --- .github/workflows/python-app.yml | 36 ++++++++++++++++++++++++++++++++ .travis.yml | 12 ----------- 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/python-app.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..d3ecccd --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,36 @@ + +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: BANKBARCODE_CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + # You can use PyPy versions in python-version. + # For example, pypy2 and pypy3 + matrix: + python-version: ["2.7", "3.6"] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + pip install -e . + - name: Run test + run: | + mamba --enable-coverage \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9461a9e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: python -python: - - "2.7" -install: - - "pip install -r requirements-dev.txt" - - "pip install coveralls" - - "pip install --process-dependency-links -e ." -script: - - mamba --enable-coverage -after_success: - - coveralls - - coverage report From 71008be8cf93521b6141a23b82136fd3d2168e7b Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 15:05:25 +0000 Subject: [PATCH 4/9] change req --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index aad2981..38c66e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ # python-barcode # We need python-barcode v0.8, to have Code128 (EAN128), not released yet # https://bitbucket.org/whitie/python-barcode/issues/16/pypi-08-release-request -https://bitbucket.org/whitie/python-barcode/get/6c22b96a2ca2.zip +# https://bitbucket.org/whitie/python-barcode/get/6c22b96a2ca2.zip 0.8.0 fro py2 compat check +python-barcode From 703c0ad9fdd45dc093aef1610386490075020008 Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 15:14:24 +0000 Subject: [PATCH 5/9] Fix version --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 38c66e7..bb31aeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ # We need python-barcode v0.8, to have Code128 (EAN128), not released yet # https://bitbucket.org/whitie/python-barcode/issues/16/pypi-08-release-request # https://bitbucket.org/whitie/python-barcode/get/6c22b96a2ca2.zip 0.8.0 fro py2 compat check -python-barcode +python-barcode==0.8.0 diff --git a/setup.py b/setup.py index c1257c3..702aef8 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ # We need python-barcode v0.8, to have Code128 (EAN128), not released yet # https://bitbucket.org/whitie/python-barcode/issues/16/pypi-08-release-request install_requires=[ - 'python-barcode', + 'python-barcode==0.8.0', 'six' ], description='barcodes for financial documents' From f34b994b593fe124fe080c3ac43a89f29de5477e Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 15:28:19 +0000 Subject: [PATCH 6/9] update mamba reqs --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6a121d8..01b9fbf 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,2 @@ -mamba +mamba<=0.10.0 expects \ No newline at end of file From 22e455c192ed2b26ba76c1f2b8b38efa0b518e65 Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 15:43:22 +0000 Subject: [PATCH 7/9] unicode and max ints --- spec/cuaderno57_Recibo507_input_spec.py | 39 +++++++++++++------------ spec/cuaderno57_Recibo_input_spec.py | 33 +++++++++++---------- spec/input_spec.py | 5 +++- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/spec/cuaderno57_Recibo507_input_spec.py b/spec/cuaderno57_Recibo507_input_spec.py index 55b5122..5e8cc90 100644 --- a/spec/cuaderno57_Recibo507_input_spec.py +++ b/spec/cuaderno57_Recibo507_input_spec.py @@ -2,6 +2,9 @@ from expects import expect, be_true, raise_error from random import randint, uniform, random from bankbarcode.cuaderno57 import Recibo507 +from six import text_type +import sys +maxint = sys.maxsize with description('Check input values for Recibo507'): @@ -17,11 +20,11 @@ with context('Check entity'): with it('return True if length of value is 8, a NIF/CIF, without the letter'): - value = unicode(randint(0, 99999999)).zfill(8) + value = text_type(randint(0, 99999999)).zfill(8) expect(self.recibo507._check_entity(value)).to(be_true) with it('raise a value error if length of value is less than 8'): - short_value = unicode(randint(0, 9999999)) + short_value = text_type(randint(0, 9999999)) short_error = 'entity is too short, entity should be a NIF/CIF, without the letter' def callback(): @@ -30,7 +33,7 @@ def callback(): expect(callback).to(raise_error(ValueError, short_error)) with it('raise a value error if length of value is greater than 8'): - long_value = unicode(randint(100000000, maxint)) + long_value = text_type(randint(100000000, maxint)) long_error = 'entity is too long, entity should be a NIF/CIF, without the letter' def callback(): @@ -41,11 +44,11 @@ def callback(): with context('Check suffix'): with it('return True if the length of value is 3'): - value = unicode(randint(0, 999)).zfill(3) + value = text_type(randint(0, 999)).zfill(3) expect(self.recibo507._check_suffix(value)).to(be_true) with it('raise a value error if length of value is less than 3'): - short_value = unicode(randint(0, 99)) + short_value = text_type(randint(0, 99)) def callback(): self.recibo507._check_suffix(short_value) @@ -53,7 +56,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'suffix is too short, suffix lenth should be 3')) with it('raise a value error if length of value is greater than 3'): - long_value = unicode(randint(1000, maxint)) + long_value = text_type(randint(1000, maxint)) def callback(): self.recibo507._check_suffix(long_value) @@ -63,11 +66,11 @@ def callback(): with context('Check reference'): with it('return True if the length of value is 11'): - value = unicode(randint(0, 9999999999)).zfill(11) + value = text_type(randint(0, 9999999999)).zfill(11) expect(self.recibo507._check_ref(value)).to(be_true) with it('raise a value error if length of value is less than 11'): - short_value = unicode(randint(0, 9999999999)) + short_value = text_type(randint(0, 9999999999)) def callback(): self.recibo507._check_ref(short_value) @@ -75,7 +78,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'ref is too short, ref lenth should be 11')) with it('raise a value error if length of value is greater than 11'): - long_value = unicode(randint(100000000000, maxint)) + long_value = text_type(randint(100000000000, maxint)) def callback(): self.recibo507._check_ref(long_value) @@ -85,11 +88,11 @@ def callback(): with context('Check identification'): with it('return True if the length of value is 6'): - value = unicode(randint(0, 999999)).zfill(6) + value = text_type(randint(0, 999999)).zfill(6) expect(self.recibo507._check_notice(value)).to(be_true) with it('raise a value error if length of value is less than 6'): - short_value = unicode(randint(0, 99999)) + short_value = text_type(randint(0, 99999)) def callback(): self.recibo507._check_notice(short_value) @@ -97,7 +100,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'notice is too short, notice lenth should be 6')) with it('raise a value error if length of value is greater than 6'): - long_value = unicode(randint(1000000, maxint)) + long_value = text_type(randint(1000000, maxint)) def callback(): self.recibo507._check_notice(long_value) @@ -107,7 +110,7 @@ def callback(): with context('Check amount'): with it('return True if amount is a unicode with less than 100000000 with 2 decimals'): - value = unicode(round(uniform(0, 99999999.99), 2)) + value = text_type(round(uniform(0, 99999999.99), 2)) expect(self.recibo507._check_amount(value)).to(be_true) with it('return True is amount is a int less than 100000000'): @@ -115,7 +118,7 @@ def callback(): expect(self.recibo507._check_amount(value)).to(be_true) with it('raise a value error if amount isn\'t less than 100000000'): - big_value = unicode(round(uniform(100000000, maxint), 2)) + big_value = text_type(round(uniform(100000000, maxint), 2)) def callback(): self.recibo507._check_amount(big_value) @@ -123,7 +126,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'amount is too big')) with it('raise a value error if amount have more than 2 decimals'): - float_value = unicode(round(random(), randint(3, 10))) + float_value = text_type(round(random(), randint(3, 10))) def callback(): self.recibo507._check_amount(float_value) @@ -133,7 +136,7 @@ def callback(): with context('Check amount'): with it('return True if amount is a unicode with less than 100000000 with 2 decimals'): - value = unicode(round(uniform(0, 99999999.99), 2)) + value = text_type(round(uniform(0, 99999999.99), 2)) expect(self.recibo507._check_amount(value)).to(be_true) with it('return True is amount is a int less than 100000000'): @@ -141,7 +144,7 @@ def callback(): expect(self.recibo507._check_amount(value)).to(be_true) with it('raise a value error if amount isn\'t less than 100000000'): - big_value = unicode(round(uniform(100000000, maxint), 2)) + big_value = text_type(round(uniform(100000000, maxint), 2)) def callback(): self.recibo507._check_amount(big_value) @@ -149,7 +152,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'amount is too big')) with it('raise a value error if amount have more than 2 decimals'): - float_value = unicode(round(random(), randint(3, 10))) + float_value = text_type(round(random(), randint(3, 10))) def callback(): self.recibo507._check_amount(float_value) diff --git a/spec/cuaderno57_Recibo_input_spec.py b/spec/cuaderno57_Recibo_input_spec.py index 46aff5a..2144d8e 100644 --- a/spec/cuaderno57_Recibo_input_spec.py +++ b/spec/cuaderno57_Recibo_input_spec.py @@ -3,6 +3,9 @@ from expects import expect, be_true, raise_error from random import randint, uniform, random from bankbarcode.cuaderno57 import Recibo +from six import text_type +import sys +maxint = sys.maxsize with description('Check input values for Recibo'): @@ -12,11 +15,11 @@ with context('Check entity'): with it('return True if length of value is 8, a NIF/CIF, without the letter'): - value = unicode(randint(0, 99999999)).zfill(8) + value = text_type(randint(0, 99999999)).zfill(8) expect(self.recibo._check_entity(value)).to(be_true) with it('raise a value error if length of value is less than 8'): - short_value = unicode(randint(0, 9999999)) + short_value = text_type(randint(0, 9999999)) short_error = 'entity is too short, entity should be a NIF/CIF, without the letter' def callback(): @@ -25,7 +28,7 @@ def callback(): expect(callback).to(raise_error(ValueError, short_error)) with it('raise a value error if length of value is greater than 8'): - long_value = unicode(randint(100000000, maxint)) + long_value = text_type(randint(100000000, maxint)) long_error = 'entity is too long, entity should be a NIF/CIF, without the letter' def callback(): @@ -36,11 +39,11 @@ def callback(): with context('Check suffix'): with it('return True if the length of value is 3'): - value = unicode(randint(0, 999)).zfill(3) + value = text_type(randint(0, 999)).zfill(3) expect(self.recibo._check_suffix(value)).to(be_true) with it('raise a value error if length of value is less than 3'): - short_value = unicode(randint(0, 99)) + short_value = text_type(randint(0, 99)) def callback(): self.recibo._check_suffix(short_value) @@ -48,7 +51,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'suffix is too short, suffix lenth should be 3')) with it('raise a value error if length of value is greater than 3'): - long_value = unicode(randint(1000, maxint)) + long_value = text_type(randint(1000, maxint)) def callback(): self.recibo._check_suffix(long_value) @@ -58,11 +61,11 @@ def callback(): with context('Check reference'): with it('return True if the length of value is 11'): - value = unicode(randint(0, 9999999999)).zfill(11) + value = text_type(randint(0, 9999999999)).zfill(11) expect(self.recibo._check_ref(value)).to(be_true) with it('raise a value error if length of value is less than 11'): - short_value = unicode(randint(0, 9999999999)) + short_value = text_type(randint(0, 9999999999)) def callback(): self.recibo._check_ref(short_value) @@ -70,7 +73,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'ref is too short, ref lenth should be 11')) with it('raise a value error if length of value is greater than 11'): - long_value = unicode(randint(100000000000, maxint)) + long_value = text_type(randint(100000000000, maxint)) def callback(): self.recibo._check_ref(long_value) @@ -80,11 +83,11 @@ def callback(): with context('Check identification'): with it('return True if the length of value is 6'): - value = unicode(randint(0, 999999)).zfill(6) + value = text_type(randint(0, 999999)).zfill(6) expect(self.recibo._check_notice(value)).to(be_true) with it('raise a value error if length of value is less than 6'): - short_value = unicode(randint(0, 99999)) + short_value = text_type(randint(0, 99999)) def callback(): self.recibo._check_notice(short_value) @@ -92,7 +95,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'notice is too short, notice lenth should be 6')) with it('raise a value error if length of value is greater than 6'): - long_value = unicode(randint(1000000, maxint)) + long_value = text_type(randint(1000000, maxint)) def callback(): self.recibo._check_notice(long_value) @@ -102,7 +105,7 @@ def callback(): with context('Check amount'): with it('return True if amount is a unicode with less than 100000000 with 2 decimals'): - value = unicode(round(uniform(0, 99999999.99), 2)) + value = text_type(round(uniform(0, 99999999.99), 2)) expect(self.recibo._check_amount(value)).to(be_true) with it('return True is amount is a int less than 100000000'): @@ -110,7 +113,7 @@ def callback(): expect(self.recibo._check_amount(value)).to(be_true) with it('raise a value error if amount isn\'t less than 100000000'): - big_value = unicode(round(uniform(100000000, maxint), 2)) + big_value = text_type(round(uniform(100000000, maxint), 2)) def callback(): self.recibo._check_amount(big_value) @@ -118,7 +121,7 @@ def callback(): expect(callback).to(raise_error(ValueError, 'amount is too big')) with it('raise a value error if amount have more than 2 decimals'): - float_value = unicode(round(random(), randint(3, 10))) + float_value = text_type(round(random(), randint(3, 10))) def callback(): self.recibo._check_amount(float_value) diff --git a/spec/input_spec.py b/spec/input_spec.py index 972a709..9b25faa 100644 --- a/spec/input_spec.py +++ b/spec/input_spec.py @@ -2,6 +2,9 @@ from expects import expect, be_true, raise_error from random import randint from bankbarcode.bankbarcode import BankBarcode +from six import text_type +import sys +maxint = sys.maxsize with description('Check input values'): @@ -12,7 +15,7 @@ self.description = 'bar' with before.each: - self.value = unicode(randint(0, maxint)) + self.value = text_type(randint(0, maxint)) with it('return true for value with expected length'): expected_length = len(self.value) From 40209cfd43269cbaed0a7250619198a866b41355 Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 15:48:40 +0000 Subject: [PATCH 8/9] use bytesio instancoff stringio --- bankbarcode/bankbarcode.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bankbarcode/bankbarcode.py b/bankbarcode/bankbarcode.py index 1f11115..e2f3787 100644 --- a/bankbarcode/bankbarcode.py +++ b/bankbarcode/bankbarcode.py @@ -1,6 +1,7 @@ from barcode import generate import six from six.moves import StringIO +from six import BytesIO from six import string_types @@ -76,6 +77,6 @@ def svg(self, writer_options=None): http://pythonhosted.org/pyBarcode/writers/index.html?#common-options :return: a string with the barcode in SVG format """ - f = StringIO() + f = BytesIO() self.save(f, writer_options) return f.getvalue() From a248c56c04479ee22665388f8a72d6f948e45e21 Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 18 Jan 2022 16:06:28 +0000 Subject: [PATCH 9/9] Use decode on file value --- bankbarcode/bankbarcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bankbarcode/bankbarcode.py b/bankbarcode/bankbarcode.py index e2f3787..d0eb25c 100644 --- a/bankbarcode/bankbarcode.py +++ b/bankbarcode/bankbarcode.py @@ -79,4 +79,4 @@ def svg(self, writer_options=None): """ f = BytesIO() self.save(f, writer_options) - return f.getvalue() + return f.getvalue().decode('utf-8')