diff --git a/.travis.yml b/.travis.yml
index 77e49547..ebef0578 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,8 +5,6 @@ python:
- "3.6"
matrix:
fast_finish: true
- allow_failures:
- - python: "3.6"
install:
- "pip install ."
- if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pip install unittest2; fi
diff --git a/gestionatr/cli.py b/gestionatr/cli.py
index 3a25a6ad..dc339961 100644
--- a/gestionatr/cli.py
+++ b/gestionatr/cli.py
@@ -1,4 +1,6 @@
# -*- encoding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
+import six
import sys
import click
@@ -29,24 +31,24 @@ def atr():
@click.option("--filename", "-f", help="path to XML filename", required=True)
@click.option("--sector", "-s", help="e (power) or g (gas)", default="e")
def test(filename, sector):
- with open(filename, 'r') as xml_file:
+ with open(filename, 'rb') as xml_file:
try:
data = xml_file.read()
- if sector == u'e':
+ if sector == 'e':
m = message.Message(data)
- elif sector == u'g':
+ elif sector == 'g':
m = message_gas.MessageGas(data)
m.parse_xml()
- sys.stdout.write(u'Correct File\n')
+ sys.stdout.write('Correct File\n')
except except_f1 as e:
- error_txt = unicode(e.value).encode(errors='ignore')
+ error_txt = six.text_type(e.value).encode(errors='ignore')
sys.stdout.write(
- u'WARNING: Invalid File: {0}\n'.format(error_txt)
+ 'WARNING: Invalid File: {0}\n'.format(error_txt)
)
except Exception as e:
- error_txt = unicode(e).encode(errors='ignore')
+ error_txt = six.text_type(e).encode(errors='ignore')
sys.stdout.write(
- u'WARNING: Invalid File: {0}\n'.format(error_txt)
+ 'WARNING: Invalid File: {0}\n'.format(error_txt)
)
finally:
sys.stdout.flush()
diff --git a/gestionatr/defs.py b/gestionatr/defs.py
index b0c104a0..0386dc6b 100644
--- a/gestionatr/defs.py
+++ b/gestionatr/defs.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
# Mapeig de distribuïdores
provincies_arago = ['22', '44', '50'] # Osca, Terol, Saragossa
diff --git a/gestionatr/defs_gas.py b/gestionatr/defs_gas.py
index 727dbbfe..f140b134 100644
--- a/gestionatr/defs_gas.py
+++ b/gestionatr/defs_gas.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
-from defs import SUBTYPES_R101
+from __future__ import absolute_import, unicode_literals
+from .defs import SUBTYPES_R101
TAULA_CATEGORIA_SUJETO = [
('COM', 'Comercializadora'),
diff --git a/gestionatr/helpers/__init__.py b/gestionatr/helpers/__init__.py
index 8cf31568..e63aac48 100644
--- a/gestionatr/helpers/__init__.py
+++ b/gestionatr/helpers/__init__.py
@@ -1,2 +1,3 @@
# -*- coding: utf-8 -*-
-from funcions import *
+from __future__ import absolute_import
+from .funcions import *
diff --git a/gestionatr/helpers/funcions.py b/gestionatr/helpers/funcions.py
index 59b3fbc9..8f8304e5 100644
--- a/gestionatr/helpers/funcions.py
+++ b/gestionatr/helpers/funcions.py
@@ -3,6 +3,8 @@
"""Helper functions for libComXml
"""
+from __future__ import absolute_import, unicode_literals
+
CODIS_REFACT = {'RT42011': '40',
'RT12012': '41',
'RM42012': '42'}
diff --git a/gestionatr/input/messages/A1.py b/gestionatr/input/messages/A1.py
index 0b6c013c..5595efd4 100644
--- a/gestionatr/input/messages/A1.py
+++ b/gestionatr/input/messages/A1.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from message import Message
-from Deadlines import ProcessDeadline
+from __future__ import absolute_import, unicode_literals
+from .message import Message
+from .Deadlines import ProcessDeadline
from gestionatr.input.messages import except_f1
-from D1 import DatosInstGen, DatosSuministro, Autoconsumo
+from .D1 import DatosInstGen, DatosSuministro, Autoconsumo
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/A12_26.py b/gestionatr/input/messages/A12_26.py
index 76cac467..396634b9 100644
--- a/gestionatr/input/messages/A12_26.py
+++ b/gestionatr/input/messages/A12_26.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
-from A1_46 import *
+from .A1_46 import *
class A12_26(A1_46):
diff --git a/gestionatr/input/messages/A19_45.py b/gestionatr/input/messages/A19_45.py
index a3aa0c48..787e7d0d 100644
--- a/gestionatr/input/messages/A19_45.py
+++ b/gestionatr/input/messages/A19_45.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
-from A12_26 import *
+from .A12_26 import *
class A19_45(A12_26):
diff --git a/gestionatr/input/messages/A1_02.py b/gestionatr/input/messages/A1_02.py
index ad1e75a3..cb363093 100644
--- a/gestionatr/input/messages/A1_02.py
+++ b/gestionatr/input/messages/A1_02.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
-from A1_41 import *
+from __future__ import absolute_import, unicode_literals
+from .A1_41 import *
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/A1_03.py b/gestionatr/input/messages/A1_03.py
index b9215364..220076d9 100644
--- a/gestionatr/input/messages/A1_03.py
+++ b/gestionatr/input/messages/A1_03.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
-from A1_44 import *
+from __future__ import absolute_import, unicode_literals
+from .A1_44 import *
class A1_03(A1_44):
diff --git a/gestionatr/input/messages/A1_04.py b/gestionatr/input/messages/A1_04.py
index 4cefad3c..99c397d5 100644
--- a/gestionatr/input/messages/A1_04.py
+++ b/gestionatr/input/messages/A1_04.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.utils import get_rec_attr
-from A1_44 import A1_44
+from .A1_44 import A1_44
class A1_04(A1_44):
diff --git a/gestionatr/input/messages/A1_05.py b/gestionatr/input/messages/A1_05.py
index b4cd22e0..403e8d9b 100644
--- a/gestionatr/input/messages/A1_05.py
+++ b/gestionatr/input/messages/A1_05.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
-from A1_02 import *
+from __future__ import absolute_import, unicode_literals
+from .A1_02 import *
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/A1_41.py b/gestionatr/input/messages/A1_41.py
index 12ee7f7b..537c3cc7 100644
--- a/gestionatr/input/messages/A1_41.py
+++ b/gestionatr/input/messages/A1_41.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/A1_44.py b/gestionatr/input/messages/A1_44.py
index 53c38e19..125b4f7d 100644
--- a/gestionatr/input/messages/A1_44.py
+++ b/gestionatr/input/messages/A1_44.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
-from A1_05 import *
+from .A1_05 import *
class A1_44(A1_05):
diff --git a/gestionatr/input/messages/A1_46.py b/gestionatr/input/messages/A1_46.py
index 99550f46..a0b79e44 100644
--- a/gestionatr/input/messages/A1_46.py
+++ b/gestionatr/input/messages/A1_46.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
-from A1_48 import *
+from .A1_48 import *
class A1_46(A1_48):
diff --git a/gestionatr/input/messages/A1_48.py b/gestionatr/input/messages/A1_48.py
index 09ede64c..45a9982f 100644
--- a/gestionatr/input/messages/A1_48.py
+++ b/gestionatr/input/messages/A1_48.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
-from A1_04 import *
+from .A1_04 import *
from gestionatr.defs_gas import SUBTYPES_A1_48
diff --git a/gestionatr/input/messages/A3.py b/gestionatr/input/messages/A3.py
index 4fb6ca31..e03cc91d 100644
--- a/gestionatr/input/messages/A3.py
+++ b/gestionatr/input/messages/A3.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-from C2 import C2
-from Deadlines import DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .C2 import C2
+from .Deadlines import DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/B1.py b/gestionatr/input/messages/B1.py
index f5f51f25..b9889e60 100644
--- a/gestionatr/input/messages/B1.py
+++ b/gestionatr/input/messages/B1.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-
-from C2 import C2, DatosSolicitud, Contacto
-from C1 import DatosAceptacion
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .C2 import C2, DatosSolicitud, Contacto
+from .C1 import DatosAceptacion
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/B70.py b/gestionatr/input/messages/B70.py
index 963b6761..99f83427 100644
--- a/gestionatr/input/messages/B70.py
+++ b/gestionatr/input/messages/B70.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
-from message_gas import MessageGas
+from __future__ import absolute_import, unicode_literals
+from .message_gas import MessageGas
from gestionatr.utils import get_rec_attr
from gestionatr.defs_gas import TIPUS_CONCEPTES
from datetime import datetime
diff --git a/gestionatr/input/messages/C1.py b/gestionatr/input/messages/C1.py
index f7935f60..bc7a72b0 100644
--- a/gestionatr/input/messages/C1.py
+++ b/gestionatr/input/messages/C1.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-from message import Message
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .message import Message
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/C2.py b/gestionatr/input/messages/C2.py
index 592f9f7e..8d27caa9 100644
--- a/gestionatr/input/messages/C2.py
+++ b/gestionatr/input/messages/C2.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-from C1 import C1, DatosSolicitud, Contrato, Cliente
-from Deadlines import DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .C1 import C1, DatosSolicitud, Contrato, Cliente
+from .Deadlines import DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/D1.py b/gestionatr/input/messages/D1.py
index 5a061a75..b7e460a1 100644
--- a/gestionatr/input/messages/D1.py
+++ b/gestionatr/input/messages/D1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.input.messages import C1
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/Deadlines.py b/gestionatr/input/messages/Deadlines.py
index 5f09c4f5..75818cbc 100644
--- a/gestionatr/input/messages/Deadlines.py
+++ b/gestionatr/input/messages/Deadlines.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import, unicode_literals
from collections import namedtuple
from datetime import datetime, timedelta
from workdays import workday
diff --git a/gestionatr/input/messages/F1.py b/gestionatr/input/messages/F1.py
index 7b377e17..6cfa7ecd 100644
--- a/gestionatr/input/messages/F1.py
+++ b/gestionatr/input/messages/F1.py
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
-from message import Message
+from __future__ import absolute_import, unicode_literals
+from .message import Message
from gestionatr.input.messages.C2 import Direccion
from gestionatr.defs import TARIFES_SEMPRE_MAX
from datetime import datetime, date
from gestionatr.utils import repartir_consums_entre_lectures
+import six
# Magnituds d'OCSUM
MAGNITUDS_OCSUM = {
@@ -1272,7 +1274,7 @@ def get_comptadors(self):
di, df = aparell_multi.get_dates_inici_i_final()
comptadors.append((di, df, aparell_multi))
- return [a[2] for a in sorted(comptadors, lambda x,y: cmp(x[0], y[0]))]
+ return [a[2] for a in sorted(comptadors, key=lambda x: x[0])]
def get_info_potencia(self):
"""Retorna els periodes de potència"""
diff --git a/gestionatr/input/messages/M1.py b/gestionatr/input/messages/M1.py
index c06c17a3..53ee63a8 100644
--- a/gestionatr/input/messages/M1.py
+++ b/gestionatr/input/messages/M1.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
-
-from C2 import C2, DatosSolicitud
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .C2 import C2, DatosSolicitud
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
diff --git a/gestionatr/input/messages/Q1.py b/gestionatr/input/messages/Q1.py
index 9eec5b27..d096d7d8 100644
--- a/gestionatr/input/messages/Q1.py
+++ b/gestionatr/input/messages/Q1.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
-from message import Message
+from __future__ import absolute_import, unicode_literals
+from .message import Message
from gestionatr.utils import get_rec_attr
-from Deadlines import ProcessDeadline
+from .Deadlines import ProcessDeadline
class Q1(Message, ProcessDeadline):
diff --git a/gestionatr/input/messages/R1.py b/gestionatr/input/messages/R1.py
index 2a8f5141..25b8bf2b 100644
--- a/gestionatr/input/messages/R1.py
+++ b/gestionatr/input/messages/R1.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from C2 import C2, Cliente, Contacto
-from C1 import DatosAceptacion
-from W1 import LecturaAportada
-from Deadlines import DeadLine, Workdays, Naturaldays
+from __future__ import absolute_import, unicode_literals
+from .C2 import C2, Cliente, Contacto
+from .C1 import DatosAceptacion
+from .W1 import LecturaAportada
+from .Deadlines import DeadLine, Workdays, Naturaldays
from gestionatr.utils import get_rec_attr
from gestionatr.defs import SUBTYPES_R101
diff --git a/gestionatr/input/messages/W1.py b/gestionatr/input/messages/W1.py
index de6a5519..282f3764 100644
--- a/gestionatr/input/messages/W1.py
+++ b/gestionatr/input/messages/W1.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.utils import get_rec_attr
-from C1 import C1
-from Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
+from .C1 import C1
+from .Deadlines import ProcessDeadline, DeadLine, Workdays, Naturaldays
class W1(C1):
diff --git a/gestionatr/input/messages/__init__.py b/gestionatr/input/messages/__init__.py
index 31a4b343..51928b36 100644
--- a/gestionatr/input/messages/__init__.py
+++ b/gestionatr/input/messages/__init__.py
@@ -1,25 +1,26 @@
# -*- coding: utf-8 -*-
-from message import Message, except_f1
-from C1 import C1
-from C2 import C2
-from A1 import A1
-from A3 import A3
-from B1 import B1
-from M1 import M1
-from D1 import D1
-from W1 import W1
-from Q1 import Q1
-from R1 import R1
-from F1 import F1
-from message_gas import MessageGas
-from A1_41 import A1_41
-from B70 import B7031, B7032, B70
-from A1_02 import A1_02
-from A1_05 import A1_05
-from A1_44 import A1_44
-from A1_03 import A1_03
-from A1_04 import A1_04
-from A1_48 import A1_48
-from A1_46 import A1_46
-from A12_26 import A12_26
-from A19_45 import A19_45
+from __future__ import absolute_import
+from .message import Message, except_f1
+from .C1 import C1
+from .C2 import C2
+from .A1 import A1
+from .A3 import A3
+from .B1 import B1
+from .M1 import M1
+from .D1 import D1
+from .W1 import W1
+from .Q1 import Q1
+from .R1 import R1
+from .F1 import F1
+from .message_gas import MessageGas
+from .A1_41 import A1_41
+from .B70 import B7031, B7032, B70
+from .A1_02 import A1_02
+from .A1_05 import A1_05
+from .A1_44 import A1_44
+from .A1_03 import A1_03
+from .A1_04 import A1_04
+from .A1_48 import A1_48
+from .A1_46 import A1_46
+from .A12_26 import A12_26
+from .A19_45 import A19_45
diff --git a/gestionatr/input/messages/defs.py b/gestionatr/input/messages/defs.py
index d5b6040a..d9f1c793 100644
--- a/gestionatr/input/messages/defs.py
+++ b/gestionatr/input/messages/defs.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
# Definició de variables de llibreria
# Taula 107 del document d'OCSUM:
# OCSUM - E - Tablas de códigos 2012.05.23.doc
diff --git a/gestionatr/input/messages/message.py b/gestionatr/input/messages/message.py
index 12dc4d1a..5ccccdba 100644
--- a/gestionatr/input/messages/message.py
+++ b/gestionatr/input/messages/message.py
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
+from io import IOBase
from lxml import objectify, etree
from gestionatr import utils
+import six
XSD_DATA = {'F1': {'01': 'Facturacion.xsd'},
'Q1': {'01': 'SaldoLecturasFacturacion.xsd'},
@@ -121,7 +124,7 @@ def __init__(self, xml, force_tipus=None):
"""Construir mensaje base."""
self.obj = None
self.error = None
- if isinstance(xml, file):
+ if (six.PY2 and isinstance(xml, file)) or isinstance(xml, IOBase):
self.check_fpos(xml)
xml = xml.read()
self.xml_orig = xml
@@ -146,7 +149,7 @@ def __init__(self, xml, force_tipus=None):
@staticmethod
def check_fpos(f_obj):
"""Setejar la posició actual dels fixers"""
- if isinstance(f_obj, file) and f_obj.tell() != 0:
+ if isinstance(f_obj, IOBase) and f_obj.tell() != 0:
f_obj.seek(0)
def set_tipus(self):
@@ -226,9 +229,8 @@ def set_xsd(self):
self._header = MAIN_MESSAGE_XSD[fitxer.split(".xsd")[0]]
except:
self._header = fitxer.split(".xsd")[0]
- xsd = utils.get_data(fitxer)
- self.f_xsd = open(xsd, 'r')
- except except_f1, e:
+ self.xsd = utils.get_data(fitxer)
+ except except_f1 as e:
raise e
except:
msg = u"Fichero '{0}' corrupto".format(
@@ -242,18 +244,20 @@ def get_pas_xml(self):
def parse_xml(self, validate=True):
"""Importar contenido del xml"""
- self.check_fpos(self.f_xsd)
- schema = etree.XMLSchema(file=self.f_xsd)
- parser = objectify.makeparser(schema=schema)
- try:
- self.obj = objectify.fromstring(self.str_xml, parser)
- except Exception as e:
- self.error = e.message
- if validate:
- raise except_f1('Error', u'Documento inválido: {0}'.format(e))
- else:
- parser = objectify.makeparser(schema=None)
+ with open(self.xsd, 'rb') as f_xsd:
+ self.f_xsd = f_xsd
+ self.check_fpos(self.f_xsd)
+ schema = etree.XMLSchema(file=self.f_xsd)
+ parser = objectify.makeparser(schema=schema)
+ try:
self.obj = objectify.fromstring(self.str_xml, parser)
+ except Exception as e:
+ self.error = e.message
+ if validate:
+ raise except_f1('Error', u'Documento inválido: {0}'.format(e))
+ else:
+ parser = objectify.makeparser(schema=None)
+ self.obj = objectify.fromstring(self.str_xml, parser)
# Funcions relacionades amb la capçalera del XML
@property
diff --git a/gestionatr/input/messages/message_gas.py b/gestionatr/input/messages/message_gas.py
index 369a4cd2..273eacfa 100644
--- a/gestionatr/input/messages/message_gas.py
+++ b/gestionatr/input/messages/message_gas.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from lxml import objectify, etree
from gestionatr import utils
-from message import XSD_DATA, MAIN_MESSAGE_XSD, Message, except_f1
+from .message import XSD_DATA, MAIN_MESSAGE_XSD, Message, except_f1
from gestionatr.utils import get_rec_attr
XSD_DATA.update({
diff --git a/gestionatr/output/messages/base.py b/gestionatr/output/messages/base.py
index 6777931b..60a52a03 100644
--- a/gestionatr/output/messages/base.py
+++ b/gestionatr/output/messages/base.py
@@ -3,8 +3,9 @@
# pylint: disable=E1002
# pylint: disable=E1101
# pylint: disable=C0111
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
+import six
class Cabecera(XmlModel):
@@ -127,4 +128,4 @@ def rep_ruedas(n_rodes):
def rep_cut(length):
# if empty return text to avoid False
- return lambda text: text and unicode(text)[:length].strip() or text
+ return lambda text: text and six.text_type(text)[:length].strip() or text
diff --git a/gestionatr/output/messages/base_gas.py b/gestionatr/output/messages/base_gas.py
index 96200817..77254acf 100644
--- a/gestionatr/output/messages/base_gas.py
+++ b/gestionatr/output/messages/base_gas.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
diff --git a/gestionatr/output/messages/sw_a1.py b/gestionatr/output/messages/sw_a1.py
index 296e4e93..87158d20 100644
--- a/gestionatr/output/messages/sw_a1.py
+++ b/gestionatr/output/messages/sw_a1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.sw_d1 import Autoconsumo, DatosSuministro, DatosInstGen
diff --git a/gestionatr/output/messages/sw_a1_02.py b/gestionatr/output/messages/sw_a1_02.py
index 613a387e..26415ac8 100644
--- a/gestionatr/output/messages/sw_a1_02.py
+++ b/gestionatr/output/messages/sw_a1_02.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
diff --git a/gestionatr/output/messages/sw_a1_03.py b/gestionatr/output/messages/sw_a1_03.py
index d0866616..b886153d 100644
--- a/gestionatr/output/messages/sw_a1_03.py
+++ b/gestionatr/output/messages/sw_a1_03.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
diff --git a/gestionatr/output/messages/sw_a1_04.py b/gestionatr/output/messages/sw_a1_04.py
index 04614745..c5759628 100644
--- a/gestionatr/output/messages/sw_a1_04.py
+++ b/gestionatr/output/messages/sw_a1_04.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
from gestionatr.output.messages.sw_a1_41 import Registerdoclist, Registerdoc
diff --git a/gestionatr/output/messages/sw_a1_05.py b/gestionatr/output/messages/sw_a1_05.py
index 478b97df..d0cbc39f 100644
--- a/gestionatr/output/messages/sw_a1_05.py
+++ b/gestionatr/output/messages/sw_a1_05.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
from gestionatr.output.messages.sw_a1_41 import Registerdoclist, Registerdoc
diff --git a/gestionatr/output/messages/sw_a1_41.py b/gestionatr/output/messages/sw_a1_41.py
index 0d19df9a..712634d8 100644
--- a/gestionatr/output/messages/sw_a1_41.py
+++ b/gestionatr/output/messages/sw_a1_41.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
diff --git a/gestionatr/output/messages/sw_a1_44.py b/gestionatr/output/messages/sw_a1_44.py
index e405506f..8d2648aa 100644
--- a/gestionatr/output/messages/sw_a1_44.py
+++ b/gestionatr/output/messages/sw_a1_44.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
from gestionatr.output.messages.sw_a1_05 import Registerdoclist, Registerdoc
diff --git a/gestionatr/output/messages/sw_a1_46.py b/gestionatr/output/messages/sw_a1_46.py
index 6dd80c1e..edd0cd3f 100644
--- a/gestionatr/output/messages/sw_a1_46.py
+++ b/gestionatr/output/messages/sw_a1_46.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
from gestionatr.output.messages.sw_a1_05 import Registerdoclist, Registerdoc
diff --git a/gestionatr/output/messages/sw_a1_48.py b/gestionatr/output/messages/sw_a1_48.py
index e6e08a09..31db6a5a 100644
--- a/gestionatr/output/messages/sw_a1_48.py
+++ b/gestionatr/output/messages/sw_a1_48.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base_gas import Heading
from gestionatr.output.messages.sw_a1_05 import Registerdoclist, Registerdoc
diff --git a/gestionatr/output/messages/sw_a3.py b/gestionatr/output/messages/sw_a3.py
index 4744a242..ebcdf70f 100644
--- a/gestionatr/output/messages/sw_a3.py
+++ b/gestionatr/output/messages/sw_a3.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.output.messages.sw_c2 import *
diff --git a/gestionatr/output/messages/sw_b1.py b/gestionatr/output/messages/sw_b1.py
index 1cebc405..ba983d81 100644
--- a/gestionatr/output/messages/sw_b1.py
+++ b/gestionatr/output/messages/sw_b1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.output.messages.sw_c2 import *
diff --git a/gestionatr/output/messages/sw_c1.py b/gestionatr/output/messages/sw_c1.py
index 1eb59fc9..e50d91f3 100644
--- a/gestionatr/output/messages/sw_c1.py
+++ b/gestionatr/output/messages/sw_c1.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base import Cabecera
diff --git a/gestionatr/output/messages/sw_c2.py b/gestionatr/output/messages/sw_c2.py
index df1f150e..82b31d6a 100644
--- a/gestionatr/output/messages/sw_c2.py
+++ b/gestionatr/output/messages/sw_c2.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.output.messages.sw_c1 import *
from gestionatr.output.messages.base import rep_cut
diff --git a/gestionatr/output/messages/sw_d1.py b/gestionatr/output/messages/sw_d1.py
index fd068b36..04bba17a 100644
--- a/gestionatr/output/messages/sw_d1.py
+++ b/gestionatr/output/messages/sw_d1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base import Cabecera
diff --git a/gestionatr/output/messages/sw_f1.py b/gestionatr/output/messages/sw_f1.py
index 8915cdab..41d89db2 100644
--- a/gestionatr/output/messages/sw_f1.py
+++ b/gestionatr/output/messages/sw_f1.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base import Cabecera, rep_fecha, \
rep_fecha_sin_hora, rep_decimal, rep_entera, rep_entera2, rep_ruedas, rep_cut
diff --git a/gestionatr/output/messages/sw_m1.py b/gestionatr/output/messages/sw_m1.py
index 2ae24eb9..5c2fbf75 100644
--- a/gestionatr/output/messages/sw_m1.py
+++ b/gestionatr/output/messages/sw_m1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.output.messages.sw_c2 import *
diff --git a/gestionatr/output/messages/sw_q1.py b/gestionatr/output/messages/sw_q1.py
index 74d7dcd5..6acd6a01 100644
--- a/gestionatr/output/messages/sw_q1.py
+++ b/gestionatr/output/messages/sw_q1.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-
+from __future__ import absolute_import, unicode_literals
from libcomxml.core import XmlModel, XmlField
from gestionatr.output.messages.base import Cabecera
diff --git a/gestionatr/output/messages/sw_r1.py b/gestionatr/output/messages/sw_r1.py
index ebfc6904..4e35ece6 100644
--- a/gestionatr/output/messages/sw_r1.py
+++ b/gestionatr/output/messages/sw_r1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.output.messages.sw_c2 import *
from gestionatr.output.messages.base import CabeceraReclamacion
diff --git a/gestionatr/output/messages/sw_w1.py b/gestionatr/output/messages/sw_w1.py
index 63652139..8cf4d839 100644
--- a/gestionatr/output/messages/sw_w1.py
+++ b/gestionatr/output/messages/sw_w1.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from gestionatr.output.messages.sw_c1 import *
diff --git a/gestionatr/parser_xml_defs_gas.py b/gestionatr/parser_xml_defs_gas.py
index 6f1a5a7f..2bbc5290 100644
--- a/gestionatr/parser_xml_defs_gas.py
+++ b/gestionatr/parser_xml_defs_gas.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import, unicode_literals
import click
from lxml import objectify
diff --git a/gestionatr/utils.py b/gestionatr/utils.py
index f7f1cb4c..cba5f07c 100644
--- a/gestionatr/utils.py
+++ b/gestionatr/utils.py
@@ -1,8 +1,12 @@
+from __future__ import absolute_import, unicode_literals
from gestionatr import defs
from gestionatr import defs_gas
import os
from collections import namedtuple
from datetime import datetime
+import six
+if six.PY3:
+ from functools import reduce
_ROOT = os.path.abspath(os.path.dirname(__file__))
diff --git a/requirements.txt b/requirements.txt
index 385ee1a2..065b31fb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,3 +2,4 @@ lxml
libcomxml
workdays
click
+six
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 27319609..a4e8291d 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
from click.testing import CliRunner
from .utils import get_data
from gestionatr.cli import atr, test
@@ -18,7 +19,6 @@ def test_version(self):
def test_atr_test_default_e(self):
runner = CliRunner()
-
result = runner.invoke(test, ['-f', get_data('f101_factura_atr.xml')])
expect(result.output).to(equal('Correct File\n'))
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index c303f96e..bb3ab25f 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
from . import unittest
from gestionatr.helpers import *
from .utils import get_data
@@ -30,7 +31,8 @@ def test_parse_totals_refact(self):
def test_validate_xml(self):
from gestionatr.utils import validate_xml
- xml_c101_minim = open(get_data("c101_minim.xml"), "r")
- xml_c101_ok = xml_c101_minim.read()
- res = validate_xml(xml_c101_ok)
- self.assertTrue(res.valid)
+ with open(get_data("c101_minim.xml"), "rb") as xml_c101_minim:
+ xml_c101_ok = xml_c101_minim.read()
+ res = validate_xml(xml_c101_ok)
+ self.assertTrue(res.valid)
+
diff --git a/tests/test_input.py b/tests/test_input.py
index 00dfc325..99579e04 100644
--- a/tests/test_input.py
+++ b/tests/test_input.py
@@ -6,12 +6,23 @@
from gestionatr.input.messages.F1 import agrupar_lectures_per_data, obtenir_data_inici_i_final
from . import unittest
from .utils import get_data
+import six
+class TestCaseCompat(unittest.TestCase):
-class test_MessageBase(unittest.TestCase):
+ def assertItemsEqual(self, first, second, msg=None):
+ if six.PY3:
+ return self.assertCountEqual(first, second, msg)
+ else:
+ return super(TestCaseCompat, self).assertItemsEqual(
+ first, second, msg
+ )
+
+
+class test_MessageBase(TestCaseCompat):
def setUp(self):
- self.xml_c101_cabecera = open(get_data("c101.xml"), "r")
+ self.xml_c101_cabecera = open(get_data("c101.xml"), "rb")
def tearDown(self):
self.xml_c101_cabecera.close()
@@ -30,10 +41,10 @@ def test_cabecera_model(self):
self.assertEqual(c.data_sollicitud, u'2016-07-21 12:59:47')
-class test_Deadline(unittest.TestCase):
+class test_Deadline(TestCaseCompat):
def setUp(self):
- self.xml_c101_completo = open(get_data("c101.xml"), "r")
+ self.xml_c101_completo = open(get_data("c101.xml"), "rb")
def test_limit(self):
c = C1(self.xml_c101_completo)
@@ -45,20 +56,20 @@ def tearDown(self):
self.xml_c101_completo.close()
-class test_C1(unittest.TestCase):
+class test_C1(TestCaseCompat):
def setUp(self):
- self.xml_c101_completo = open(get_data("c101.xml"), "r")
- self.xml_c101_minim = open(get_data("c101_minim.xml"), "r")
- self.xml_c102_accept = open(get_data("c102_accept.xml"), "r")
- self.xml_c102_reject = open(get_data("c102_reject.xml"), "r")
- self.xml_c104 = open(get_data("c104.xml"), "r")
- self.xml_c105 = open(get_data("c105.xml"), "r")
- self.xml_c106 = open(get_data("c106.xml"), "r")
- self.xml_c108 = open(get_data("c108.xml"), "r")
- self.xml_c109 = open(get_data("c109.xml"), "r")
- self.xml_c111 = open(get_data("c111.xml"), "r")
- self.xml_c112 = open(get_data("c112.xml"), "r")
+ self.xml_c101_completo = open(get_data("c101.xml"), "rb")
+ self.xml_c101_minim = open(get_data("c101_minim.xml"), "rb")
+ self.xml_c102_accept = open(get_data("c102_accept.xml"), "rb")
+ self.xml_c102_reject = open(get_data("c102_reject.xml"), "rb")
+ self.xml_c104 = open(get_data("c104.xml"), "rb")
+ self.xml_c105 = open(get_data("c105.xml"), "rb")
+ self.xml_c106 = open(get_data("c106.xml"), "rb")
+ self.xml_c108 = open(get_data("c108.xml"), "rb")
+ self.xml_c109 = open(get_data("c109.xml"), "rb")
+ self.xml_c111 = open(get_data("c111.xml"), "rb")
+ self.xml_c112 = open(get_data("c112.xml"), "rb")
def tearDown(self):
self.xml_c101_completo.close()
@@ -343,12 +354,12 @@ def test_c112(self):
self.assertEqual(c.fecha_rechazo, u'2017-02-02')
-class test_C2(unittest.TestCase):
+class test_C2(TestCaseCompat):
def setUp(self):
- self.xml_c201_completo = open(get_data("c201.xml"), "r")
- self.xml_c202_accept = open(get_data("c202_accept.xml"), "r")
- self.xml_c203 = open(get_data("c203.xml"), "r")
+ self.xml_c201_completo = open(get_data("c201.xml"), "rb")
+ self.xml_c202_accept = open(get_data("c202_accept.xml"), "rb")
+ self.xml_c203 = open(get_data("c203.xml"), "rb")
def tearDown(self):
self.xml_c201_completo.close()
@@ -494,12 +505,12 @@ def test_c203(self):
self.assertEqual(i2.comentarios, u'Com 2')
-class test_A1(unittest.TestCase):
+class test_A1(TestCaseCompat):
def setUp(self):
- self.xml_a101 = open(get_data("a101.xml"), "r")
- self.xml_a102_accept = open(get_data("a102_accept.xml"), "r")
- self.xml_a102_reject = open(get_data("a102_reject.xml"), "r")
+ self.xml_a101 = open(get_data("a101.xml"), "rb")
+ self.xml_a102_accept = open(get_data("a102_accept.xml"), "rb")
+ self.xml_a102_reject = open(get_data("a102_reject.xml"), "rb")
def tearDown(self):
self.xml_a101.close()
@@ -626,11 +637,11 @@ def test_a102_reject(self):
-class test_A3(unittest.TestCase):
+class test_A3(TestCaseCompat):
def setUp(self):
- self.xml_a301 = open(get_data("a301.xml"), "r")
- self.xml_a301_correos = open(get_data("a301_correos.xml"), "r")
+ self.xml_a301 = open(get_data("a301.xml"), "rb")
+ self.xml_a301_correos = open(get_data("a301_correos.xml"), "rb")
def tearDown(self):
self.xml_a301.close()
@@ -736,13 +747,13 @@ def test_a301_correos(self):
self.assertEqual(direccion.apartado_de_correos, u'A1234')
-class test_B1(unittest.TestCase):
+class test_B1(TestCaseCompat):
def setUp(self):
- self.xml_b101 = open(get_data("b101.xml"), "r")
- self.xml_b102_accept = open(get_data("b102_accept.xml"), "r")
- self.xml_b104_accept = open(get_data("b104_accept.xml"), "r")
- self.xml_b105 = open(get_data("b105.xml"), "r")
+ self.xml_b101 = open(get_data("b101.xml"), "rb")
+ self.xml_b102_accept = open(get_data("b102_accept.xml"), "rb")
+ self.xml_b104_accept = open(get_data("b104_accept.xml"), "rb")
+ self.xml_b105 = open(get_data("b105.xml"), "rb")
def tearDown(self):
self.xml_b101.close()
@@ -852,10 +863,10 @@ def test_b105(self):
self.assertEqual(md2.fecha_lectura_firme, u'2003-01-03')
-class test_M1(unittest.TestCase):
+class test_M1(TestCaseCompat):
def setUp(self):
- self.xml_m101 = open(get_data("m101.xml"), "r")
+ self.xml_m101 = open(get_data("m101.xml"), "rb")
def tearDown(self):
self.xml_m101.close()
@@ -915,14 +926,14 @@ def test_m101(self):
self.assertFalse(m1.comentarios)
-class test_D1(unittest.TestCase):
+class test_D1(TestCaseCompat):
def setUp(self):
- self.xml_d101 = open(get_data("d101.xml"), "r")
- self.xml_d101_min_with_info = open(get_data("d101_min_with_info.xml"), "r")
- self.xml_d101_fully_min = open(get_data("d101_fully_min.xml"), "r")
- self.xml_d102_accept = open(get_data("d102_accept.xml"), "r")
- self.xml_d102_reject = open(get_data("d102_reject.xml"), "r")
+ self.xml_d101 = open(get_data("d101.xml"), "rb")
+ self.xml_d101_min_with_info = open(get_data("d101_min_with_info.xml"), "rb")
+ self.xml_d101_fully_min = open(get_data("d101_fully_min.xml"), "rb")
+ self.xml_d102_accept = open(get_data("d102_accept.xml"), "rb")
+ self.xml_d102_reject = open(get_data("d102_reject.xml"), "rb")
def tearDown(self):
self.xml_d101.close()
@@ -1065,12 +1076,12 @@ def test_d102_reject(self):
self.assertEqual(rej.codigo_motivo, u'F1')
self.assertEqual(rej.comentarios, u'Motiu de rebuig F1')
-class test_W1(unittest.TestCase):
+class test_W1(TestCaseCompat):
def setUp(self):
- self.xml_w101 = open(get_data("w101.xml"), "r")
- self.xml_w102_accept = open(get_data("w102_accept.xml"), "r")
- self.xml_w102_reject = open(get_data("w102_reject.xml"), "r")
+ self.xml_w101 = open(get_data("w101.xml"), "rb")
+ self.xml_w102_accept = open(get_data("w102_accept.xml"), "rb")
+ self.xml_w102_reject = open(get_data("w102_reject.xml"), "rb")
def tearDown(self):
self.xml_w101.close()
@@ -1116,10 +1127,10 @@ def test_w102_reject(self):
self.assertEqual(rej1.comentarios, 'Motiu de rebuig 01: No existe Punto de Suministro asociado al CUPS')
-class test_Q1(unittest.TestCase):
+class test_Q1(TestCaseCompat):
def setUp(self):
- self.xml_q101 = open(get_data("q101.xml"), "r")
+ self.xml_q101 = open(get_data("q101.xml"), "rb")
def tearDown(self):
self.xml_q101.close()
@@ -1161,16 +1172,16 @@ def test_q101(self):
self.assertEqual(anomalia.tipo_anomalia, u'05')
-class test_R1(unittest.TestCase):
+class test_R1(TestCaseCompat):
def setUp(self):
- self.xml_r101 = open(get_data("r101.xml"), "r")
- self.xml_r102_accept = open(get_data("r102_accept.xml"), "r")
- self.xml_r103 = open(get_data("r103.xml"), "r")
- self.xml_r103_intervenciones = open(get_data("r103_intervenciones.xml"), "r")
- self.xml_r103_no_add_info = open(get_data("r103_no_add_info.xml"), "r")
- self.xml_r104 = open(get_data("r104.xml"), "r")
- self.xml_r105 = open(get_data("r105.xml"), "r")
+ self.xml_r101 = open(get_data("r101.xml"), "rb")
+ self.xml_r102_accept = open(get_data("r102_accept.xml"), "rb")
+ self.xml_r103 = open(get_data("r103.xml"), "rb")
+ self.xml_r103_intervenciones = open(get_data("r103_intervenciones.xml"), "rb")
+ self.xml_r103_no_add_info = open(get_data("r103_no_add_info.xml"), "rb")
+ self.xml_r104 = open(get_data("r104.xml"), "rb")
+ self.xml_r105 = open(get_data("r105.xml"), "rb")
def tearDown(self):
self.xml_r101.close()
@@ -1465,27 +1476,27 @@ def test_r105(self):
self.assertEqual(r1.cod_contrato, u'383922379')
-class test_F1(unittest.TestCase):
+class test_F1(TestCaseCompat):
def setUp(self):
- with open(get_data("f101_factura_atr.xml"), "r") as f:
+ with open(get_data("f101_factura_atr.xml"), "rb") as f:
self.xml_f101_atr_invoice = f.read()
- with open(get_data("f101_factura_atr_30A.xml"), "r") as f:
+ with open(get_data("f101_factura_atr_30A.xml"), "rb") as f:
self.xml_f101_atr_invoice_30A = f.read()
- with open(get_data("f101_factura_atr_61B_exceso.xml"), "r") as f:
+ with open(get_data("f101_factura_atr_61B_exceso.xml"), "rb") as f:
self.xml_f101_atr_invoice_61B = f.read()
- with open(get_data("f101_factura_atr_ajuste.xml"), "r") as f:
+ with open(get_data("f101_factura_atr_ajuste.xml"), "rb") as f:
self.xml_f101_atr_invoice_ajuste = f.read()
- with open(get_data("f101_factura_atr_empty_periods.xml"), "r") as f:
+ with open(get_data("f101_factura_atr_empty_periods.xml"), "rb") as f:
self.xml_f101_atr_invoice_empty_periods = f.read()
- with open(get_data("f101_factura_otros.xml"), "r") as f:
+ with open(get_data("f101_factura_otros.xml"), "rb") as f:
self.xml_f101_other_invoice = f.read()
with open(get_data("f101_spaces.xml"), "r") as f:
self.xml_f101_spaces = f.read()
- with open(get_data("f101_factura_atr_free_interpretation.xml"), "r") as f:
+ with open(get_data("f101_factura_atr_free_interpretation.xml"), "rb") as f:
self.xml_f101_free_interpretation = f.read()
- with open(get_data("f101_factura_empty_rent.xml"), "r") as f:
+ with open(get_data("f101_factura_empty_rent.xml"), "rb") as f:
self.xml_f101_empty_rent = f.read()
- with open(get_data("F1_periodos_DH.xml"), "r") as f:
+ with open(get_data("F1_periodos_DH.xml"), "rb") as f:
self.xml_f101_integradores_dh = f.read()
def testATRInvoice(self):
@@ -2047,8 +2058,8 @@ def test_sin_base_imponible(self):
f1_sin_base = F1(
self.xml_f101_atr_invoice.replace(
- '63.21',
- '0.0'
+ '63.21'.encode('utf-8'),
+ '0.0'.encode('utf-8')
)
)
f1_sin_base.parse_xml()
@@ -2197,7 +2208,7 @@ def test_agrupar_i_obtenir_dates_maximetre(self):
lectures_agrupades = agrupar_lectures_per_data(lectures)
self.assertEqual(
- lectures_agrupades.keys(),
+ list(lectures_agrupades.keys()),
[
('2017-03-31', u'2017-04-17'), # Energy readings
('2017-04-30', u'2017-04-30') # Maximeter readings
@@ -2489,7 +2500,7 @@ def test_empty_rents_dont_return(self):
class test_MessageGas(unittest.TestCase):
def setUp(self):
- self.xml_a241 = open(get_data("a241.xml"), "r")
+ self.xml_a241 = open(get_data("a241.xml"), "rb")
def tearDown(self):
self.xml_a241.close()
@@ -2507,10 +2518,10 @@ def test_gas_header(self):
class test_A1_41(unittest.TestCase):
def setUp(self):
- self.xml_a241 = open(get_data("a241.xml"), "r")
- self.xml_a341 = open(get_data("a341.xml"), "r")
- self.xml_a441 = open(get_data("a441.xml"), "r")
- self.xml_a3s41 = open(get_data("a3s41.xml"), "r")
+ self.xml_a241 = open(get_data("a241.xml"), "rb")
+ self.xml_a341 = open(get_data("a341.xml"), "rb")
+ self.xml_a441 = open(get_data("a441.xml"), "rb")
+ self.xml_a3s41 = open(get_data("a3s41.xml"), "rb")
def tearDown(self):
self.xml_a241.close()
@@ -2678,8 +2689,8 @@ def test_a3s41(self):
class test_B70(unittest.TestCase):
def setUp(self):
- self.xml_b7031 = open(get_data("b7031.xml"), "r")
- self.xml_b7032 = open(get_data("b7032.xml"), "r")
+ self.xml_b7031 = open(get_data("b7031.xml"), "rb")
+ self.xml_b7032 = open(get_data("b7032.xml"), "rb")
def tearDown(self):
self.xml_b7031.close()
@@ -3033,10 +3044,10 @@ def test_b7032(self):
class test_A1_02(unittest.TestCase):
def setUp(self):
- self.xml_a202 = open(get_data("a202.xml"), "r")
- self.xml_a302 = open(get_data("a302.xml"), "r")
- self.xml_a3s02 = open(get_data("a3s02.xml"), "r")
- self.xml_a402 = open(get_data("a402.xml"), "r")
+ self.xml_a202 = open(get_data("a202.xml"), "rb")
+ self.xml_a302 = open(get_data("a302.xml"), "rb")
+ self.xml_a3s02 = open(get_data("a3s02.xml"), "rb")
+ self.xml_a402 = open(get_data("a402.xml"), "rb")
def tearDown(self):
self.xml_a202.close()
@@ -3163,9 +3174,9 @@ def test_a402(self):
class test_A1_05(unittest.TestCase):
def setUp(self):
- self.xml_a205 = open(get_data("a205.xml"), "r")
- self.xml_a305 = open(get_data("a305.xml"), "r")
- self.xml_a405 = open(get_data("a405.xml"), "r")
+ self.xml_a205 = open(get_data("a205.xml"), "rb")
+ self.xml_a305 = open(get_data("a305.xml"), "rb")
+ self.xml_a405 = open(get_data("a405.xml"), "rb")
def tearDown(self):
self.xml_a205.close()
@@ -3268,9 +3279,9 @@ def test_a405(self):
class test_A1_44(unittest.TestCase):
def setUp(self):
- self.xml_a244 = open(get_data("a244.xml"), "r")
- self.xml_a344 = open(get_data("a344.xml"), "r")
- self.xml_a444 = open(get_data("a444.xml"), "r")
+ self.xml_a244 = open(get_data("a244.xml"), "rb")
+ self.xml_a344 = open(get_data("a344.xml"), "rb")
+ self.xml_a444 = open(get_data("a444.xml"), "rb")
def tearDown(self):
self.xml_a244.close()
@@ -3415,8 +3426,8 @@ def test_a444(self):
class test_A1_03(unittest.TestCase):
def setUp(self):
- self.xml_a203 = open(get_data("a203.xml"), "r")
- self.xml_a2s03 = open(get_data("a2s03.xml"), "r")
+ self.xml_a203 = open(get_data("a203.xml"), "rb")
+ self.xml_a2s03 = open(get_data("a2s03.xml"), "rb")
def tearDown(self):
self.xml_a203.close()
@@ -3459,9 +3470,9 @@ def test_a2s03(self):
class test_A1_04(unittest.TestCase):
def setUp(self):
- self.xml_a204 = open(get_data("a204.xml"), "r")
- self.xml_a304 = open(get_data("a304.xml"), "r")
- self.xml_a404 = open(get_data("a404.xml"), "r")
+ self.xml_a204 = open(get_data("a204.xml"), "rb")
+ self.xml_a304 = open(get_data("a304.xml"), "rb")
+ self.xml_a404 = open(get_data("a404.xml"), "rb")
def tearDown(self):
self.xml_a204.close()
@@ -3570,11 +3581,11 @@ def test_a404(self):
class test_A1_48(unittest.TestCase):
def setUp(self):
- self.xml_a148 = open(get_data("a148.xml"), "r")
- self.xml_a248 = open(get_data("a248.xml"), "r")
- self.xml_a2548 = open(get_data("a2548.xml"), "r")
- self.xml_a2648 = open(get_data("a2648.xml"), "r")
- self.xml_a348 = open(get_data("a348.xml"), "r")
+ self.xml_a148 = open(get_data("a148.xml"), "rb")
+ self.xml_a248 = open(get_data("a248.xml"), "rb")
+ self.xml_a2548 = open(get_data("a2548.xml"), "rb")
+ self.xml_a2648 = open(get_data("a2648.xml"), "rb")
+ self.xml_a348 = open(get_data("a348.xml"), "rb")
def tearDown(self):
self.xml_a148.close()
@@ -3857,7 +3868,7 @@ def test_a348(self):
class test_A1_46(unittest.TestCase):
def setUp(self):
- self.xml_a246 = open(get_data("a246.xml"), "r")
+ self.xml_a246 = open(get_data("a246.xml"), "rb")
def tearDown(self):
self.xml_a246.close()
@@ -3881,7 +3892,7 @@ def test_a246(self):
class test_A12_26(unittest.TestCase):
def setUp(self):
- self.xml_a1226 = open(get_data("a1226.xml"), "r")
+ self.xml_a1226 = open(get_data("a1226.xml"), "rb")
def tearDown(self):
self.xml_a1226.close()
@@ -3961,7 +3972,7 @@ def test_a246(self):
class test_A19_45(unittest.TestCase):
def setUp(self):
- self.xml_a1945 = open(get_data("a1945.xml"), "r")
+ self.xml_a1945 = open(get_data("a1945.xml"), "rb")
def tearDown(self):
self.xml_a1945.close()
diff --git a/tests/test_output.py b/tests/test_output.py
index d2498a4b..3d596b94 100644
--- a/tests/test_output.py
+++ b/tests/test_output.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, unicode_literals
import copy
from gestionatr.output.messages import sw_a1_02 as a1_02
@@ -28,14 +29,14 @@
class test_C1(unittest.TestCase):
def setUp(self):
- self.xml_c101_completo = open(get_data("c101.xml"), "r")
- self.xml_c102_accept = open(get_data("c102_accept.xml"), "r")
- self.xml_c102_reject = open(get_data("c102_reject.xml"), "r")
- self.xml_c105 = open(get_data("c105.xml"), "r")
- self.xml_c106 = open(get_data("c106.xml"), "r")
- self.xml_c109 = open(get_data("c109.xml"), "r")
- self.xml_c111 = open(get_data("c111.xml"), "r")
- self.xml_c112 = open(get_data("c112.xml"), "r")
+ self.xml_c101_completo = open(get_data("c101.xml"), "rb")
+ self.xml_c102_accept = open(get_data("c102_accept.xml"), "rb")
+ self.xml_c102_reject = open(get_data("c102_reject.xml"), "rb")
+ self.xml_c105 = open(get_data("c105.xml"), "rb")
+ self.xml_c106 = open(get_data("c106.xml"), "rb")
+ self.xml_c109 = open(get_data("c109.xml"), "rb")
+ self.xml_c111 = open(get_data("c111.xml"), "rb")
+ self.xml_c112 = open(get_data("c112.xml"), "rb")
# RegistrosDocumento
self.registros_documento = c1.RegistrosDocumento()
@@ -525,9 +526,9 @@ def test_create_pas12(self):
class test_C2(unittest.TestCase):
def setUp(self):
- self.xml_c201_completo = open(get_data("c201.xml"), "r")
- self.xml_c202_accept = open(get_data("c202_accept.xml"), "r")
- self.xml_c203 = open(get_data("c203.xml"), "r")
+ self.xml_c201_completo = open(get_data("c201.xml"), "rb")
+ self.xml_c202_accept = open(get_data("c202_accept.xml"), "rb")
+ self.xml_c203 = open(get_data("c203.xml"), "rb")
def tearDown(self):
self.xml_c201_completo.close()
@@ -767,9 +768,9 @@ def test_create_pas03(self):
class test_A1(unittest.TestCase):
def setUp(self):
- self.xml_a101 = open(get_data("a101.xml"), "r")
- self.xml_a102_accept = open(get_data("a102_accept.xml"), "r")
- self.xml_a102_reject = open(get_data("a102_reject.xml"), "r")
+ self.xml_a101 = open(get_data("a101.xml"), "rb")
+ self.xml_a102_accept = open(get_data("a102_accept.xml"), "rb")
+ self.xml_a102_reject = open(get_data("a102_reject.xml"), "rb")
def tearDown(self):
self.xml_a101.close()
@@ -1090,8 +1091,8 @@ def test_create_pas02_rej(self):
class test_A3(unittest.TestCase):
def setUp(self):
- self.xml_a301 = open(get_data("a301.xml"), "r")
- self.xml_a301_correos = open(get_data("a301_correos.xml"), "r")
+ self.xml_a301 = open(get_data("a301.xml"), "rb")
+ self.xml_a301_correos = open(get_data("a301_correos.xml"), "rb")
def tearDown(self):
self.xml_a301.close()
@@ -1328,7 +1329,7 @@ def test_create_pas01_correos(self):
class test_M1(unittest.TestCase):
def setUp(self):
- self.xml_m101 = open(get_data("m101.xml"), "r")
+ self.xml_m101 = open(get_data("m101.xml"), "rb")
def tearDown(self):
self.xml_m101.close()
@@ -1418,9 +1419,9 @@ def test_create_pas01(self):
class test_D1(unittest.TestCase):
def setUp(self):
- self.xml_d101 = open(get_data("d101.xml"), "r")
- self.xml_d102_accept = open(get_data("d102_accept.xml"), "r")
- self.xml_d102_reject = open(get_data("d102_reject.xml"), "r")
+ self.xml_d101 = open(get_data("d101.xml"), "rb")
+ self.xml_d102_accept = open(get_data("d102_accept.xml"), "rb")
+ self.xml_d102_reject = open(get_data("d102_reject.xml"), "rb")
def tearDown(self):
self.xml_d101.close()
@@ -1729,7 +1730,7 @@ def test_create_pas02_rej(self):
class test_Q1(unittest.TestCase):
def setUp(self):
- self.xml_q101 = open(get_data("q101.xml"), "r")
+ self.xml_q101 = open(get_data("q101.xml"), "rb")
def tearDown(self):
self.xml_q101.close()
@@ -1905,9 +1906,9 @@ def test_create_pas01(self):
class test_W1(unittest.TestCase):
def setUp(self):
- self.xml_w101 = open(get_data("w101.xml"), "r")
- self.xml_w102_accept = open(get_data("w102_accept.xml"), "r")
- self.xml_w102_reject = open(get_data("w102_reject.xml"), "r")
+ self.xml_w101 = open(get_data("w101.xml"), "rb")
+ self.xml_w102_accept = open(get_data("w102_accept.xml"), "rb")
+ self.xml_w102_reject = open(get_data("w102_reject.xml"), "rb")
def tearDown(self):
self.xml_w101.close()
@@ -2034,10 +2035,10 @@ def test_create_pas02_rej(self):
class test_B1(unittest.TestCase):
def setUp(self):
- self.xml_b101 = open(get_data("b101.xml"), "r")
- self.xml_b102_accept = open(get_data("b102_accept.xml"), "r")
- self.xml_b104_accept = open(get_data("b104_accept.xml"), "r")
- self.xml_b105 = open(get_data("b105.xml"), "r")
+ self.xml_b101 = open(get_data("b101.xml"), "rb")
+ self.xml_b102_accept = open(get_data("b102_accept.xml"), "rb")
+ self.xml_b104_accept = open(get_data("b104_accept.xml"), "rb")
+ self.xml_b105 = open(get_data("b105.xml"), "rb")
def tearDown(self):
self.xml_b101.close()
@@ -2306,12 +2307,12 @@ def test_create_pas05(self):
class test_R1(unittest.TestCase):
def setUp(self):
- self.xml_r101 = open(get_data("r101.xml"), "r")
- self.xml_r102_accept = open(get_data("r102_accept.xml"), "r")
- self.xml_r103 = open(get_data("r103.xml"), "r")
- self.xml_r103_intervenciones = open(get_data("r103_intervenciones.xml"), "r")
- self.xml_r104 = open(get_data("r104.xml"), "r")
- self.xml_r105 = open(get_data("r105.xml"), "r")
+ self.xml_r101 = open(get_data("r101.xml"), "rb")
+ self.xml_r102_accept = open(get_data("r102_accept.xml"), "rb")
+ self.xml_r103 = open(get_data("r103.xml"), "rb")
+ self.xml_r103_intervenciones = open(get_data("r103_intervenciones.xml"), "rb")
+ self.xml_r104 = open(get_data("r104.xml"), "rb")
+ self.xml_r105 = open(get_data("r105.xml"), "rb")
def tearDown(self):
self.xml_r101.close()
@@ -3018,15 +3019,15 @@ def test_create_pas05(self):
class test_F1(unittest.TestCase):
def setUp(self):
- self.xml_f101_factura_atr = open(get_data("f101_factura_atr.xml"), "r")
+ self.xml_f101_factura_atr = open(get_data("f101_factura_atr.xml"), "rb")
self.xml_f101_factura_otros = open(
- get_data("f101_factura_otros.xml"), "r"
+ get_data("f101_factura_otros.xml"), "rb"
)
self.xml_f101_factura_atr_direccion_suministro = open(
- get_data("f101_factura_atr_direccion_suministro.xml"), "r"
+ get_data("f101_factura_atr_direccion_suministro.xml"), "rb"
)
self.xml_f101_factura_atr_medidas_baja = open(
- get_data("f101_factura_atr_medidas_baja.xml"), "r"
+ get_data("f101_factura_atr_medidas_baja.xml"), "rb"
)
direccion_suministro = f1.DireccionSuministro()
@@ -3426,6 +3427,9 @@ def setUp(self):
def tearDown(self):
self.xml_f101_factura_atr.close()
+ self.xml_f101_factura_otros.close()
+ self.xml_f101_factura_atr_direccion_suministro.close()
+ self.xml_f101_factura_atr_medidas_baja.close()
def with_factura_atr(self):
cabecera = get_header(process='F1', step='01')
@@ -3541,7 +3545,7 @@ def test_create_pas01_other_invoice(self):
class test_A1_41(unittest.TestCase):
def setUp(self):
- self.xml_a141 = open(get_data("a141.xml"), "r")
+ self.xml_a141 = open(get_data("a141.xml"), "rb")
def tearDown(self):
self.xml_a141.close()
@@ -3642,7 +3646,7 @@ def test_create_a141(self):
class test_A1_02(unittest.TestCase):
def setUp(self):
- self.xml_a102 = open(get_data("a102.xml"), "r")
+ self.xml_a102 = open(get_data("a102.xml"), "rb")
def tearDown(self):
self.xml_a102.close()
@@ -3696,7 +3700,7 @@ def test_create_a102(self):
class test_A1_05(unittest.TestCase):
def setUp(self):
- self.xml_a105 = open(get_data("a105.xml"), "r")
+ self.xml_a105 = open(get_data("a105.xml"), "rb")
def tearDown(self):
self.xml_a105.close()
@@ -3797,7 +3801,7 @@ def test_create_a105(self):
class test_A1_44(unittest.TestCase):
def setUp(self):
- self.xml_a144 = open(get_data("a144.xml"), "r")
+ self.xml_a144 = open(get_data("a144.xml"), "rb")
def tearDown(self):
self.xml_a144.close()
@@ -3879,7 +3883,7 @@ def test_create_a144(self):
class test_A1_03(unittest.TestCase):
def setUp(self):
- self.xml_a103 = open(get_data("a103.xml"), "r")
+ self.xml_a103 = open(get_data("a103.xml"), "rb")
def tearDown(self):
self.xml_a103.close()
@@ -3930,7 +3934,7 @@ def test_create_a103(self):
class test_A1_04(unittest.TestCase):
def setUp(self):
- self.xml_a104 = open(get_data("a104.xml"), "r")
+ self.xml_a104 = open(get_data("a104.xml"), "rb")
def tearDown(self):
self.xml_a104.close()
@@ -3989,8 +3993,8 @@ def test_create_a104(self):
class test_A1_48(unittest.TestCase):
def setUp(self):
- self.xml_a148 = open(get_data("a148.xml"), "r")
- self.xml_a2648 = open(get_data("a2648.xml"), "r")
+ self.xml_a148 = open(get_data("a148.xml"), "rb")
+ self.xml_a2648 = open(get_data("a2648.xml"), "rb")
def tearDown(self):
self.xml_a148.close()
@@ -4427,7 +4431,7 @@ def test_create_a2648(self):
class test_A1_46(unittest.TestCase):
def setUp(self):
- self.xml_a146 = open(get_data("a146.xml"), "r")
+ self.xml_a146 = open(get_data("a146.xml"), "rb")
def tearDown(self):
self.xml_a146.close()
diff --git a/tests/utils.py b/tests/utils.py
index 2bffe214..cf05cb37 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -193,6 +193,13 @@ def get_medida():
def assertXmlEqual(got, want):
from lxml.doctestcompare import LXMLOutputChecker
from doctest import Example
+ import six
+
+ if isinstance(want, six.binary_type):
+ from lxml import etree
+ from io import BytesIO
+ x = etree.parse(BytesIO(want))
+ want = etree.tostring(x, encoding='unicode')
checker = LXMLOutputChecker()
if checker.check_output(want, got, 0):