Skip to content

Commit d42229e

Browse files
ran black and falke8 to follow PEP8 & removed unittest dependency
Signed-off-by: SONIABHISHEK121 <[email protected]>
1 parent bde2d02 commit d42229e

File tree

1 file changed

+90
-56
lines changed

1 file changed

+90
-56
lines changed

tests/test_formato_xml.py

Lines changed: 90 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22
# -*- coding: utf8 -*-
3+
34
# This program is free software; you can redistribute it and/or modify
45
# it under the terms of the GNU General Public License as published by the
56
# Free Software Foundation; either version 3, or (at your option) any later
@@ -16,123 +17,156 @@
1617
__copyright__ = "Copyright (C) 2010-2019 Mariano Reingart"
1718
__license__ = "GPL 3.0"
1819

19-
2020
import os
21-
import unittest
2221
import pytest
2322
from decimal import Decimal
2423
from pyafipws.formatos import formato_xml
2524

25+
2626
@pytest.mark.dontusefix
27-
class TestFormatoXML(unittest.TestCase):
28-
def setUp(self):
27+
class TestFormatoXML:
28+
@pytest.fixture(autouse=True)
29+
def setup_teardown(self):
2930
# Configuración inicial de los archivos de entrada y salida
3031
self.entrada_xml = "datos/facturas.xml"
3132
self.salida_xml = "tests/test_salida.xml"
32-
33-
def tearDown(self):
33+
yield
3434
# Limpiar el archivo de salida después de cada prueba
3535
if os.path.exists(self.salida_xml):
3636
os.remove(self.salida_xml)
3737

3838
def test_leer(self):
3939
# Prueba de la función leer
4040
regs = formato_xml.leer(self.entrada_xml)
41-
self.assertEqual(len(regs), 1)
41+
assert len(regs) == 1
4242
reg = regs[0]
43-
self.assertEqual(reg["concepto"], 1)
44-
self.assertEqual(reg["tipo_doc"], 80)
45-
self.assertEqual(reg["nro_doc"], 30500010912)
46-
self.assertEqual(reg["tipo_cbte"], 6)
47-
self.assertEqual(reg["punto_vta"], 5)
48-
self.assertEqual(reg["cbt_numero"], 7)
49-
self.assertEqual(reg["imp_total"], Decimal("1085.57"))
50-
self.assertEqual(reg["imp_neto"], Decimal("889.82"))
51-
self.assertEqual(reg["imp_iva"], Decimal("186.86"))
52-
self.assertEqual(reg["imp_trib"], Decimal("8.89"))
53-
self.assertEqual(reg["imp_op_ex"], Decimal("0.00"))
54-
self.assertEqual(reg["fecha_cbte"], "20110609")
55-
self.assertEqual(reg["fecha_venc_pago"], "")
56-
self.assertEqual(reg["fecha_serv_desde"], "")
57-
self.assertEqual(reg["fecha_serv_hasta"], "")
58-
self.assertEqual(reg["moneda_id"], "PES")
59-
self.assertEqual(reg["moneda_ctz"], Decimal("1.000000"))
60-
self.assertEqual(str(reg["cae"]), "61233038185853")
61-
self.assertEqual(reg["fecha_vto"], "20110619")
62-
self.assertEqual(len(reg["detalles"]), 1)
63-
self.assertEqual(len(reg["ivas"]), 1)
64-
self.assertEqual(len(reg["tributos"]), 1)
65-
self.assertEqual(len(reg["cbtes_asoc"]), 0)
66-
self.assertEqual(len(reg["opcionales"]), 0)
43+
assert reg["concepto"] == 1
44+
assert reg["tipo_doc"] == 80
45+
assert reg["nro_doc"] == 30500010912
46+
assert reg["tipo_cbte"] == 6
47+
assert reg["punto_vta"] == 5
48+
assert reg["cbt_numero"] == 7
49+
assert reg["imp_total"] == Decimal("1085.57")
50+
assert reg["imp_neto"] == Decimal("889.82")
51+
assert reg["imp_iva"] == Decimal("186.86")
52+
assert reg["imp_trib"] == Decimal("8.89")
53+
assert reg["imp_op_ex"] == Decimal("0.00")
54+
assert reg["fecha_cbte"] == "20110609"
55+
assert reg["fecha_venc_pago"] == ""
56+
assert reg["fecha_serv_desde"] == ""
57+
assert reg["fecha_serv_hasta"] == ""
58+
assert reg["moneda_id"] == "PES"
59+
assert reg["moneda_ctz"] == Decimal("1.000000")
60+
assert str(reg["cae"]) == "61233038185853"
61+
assert reg["fecha_vto"] == "20110619"
62+
assert len(reg["detalles"]) == 1
63+
assert len(reg["ivas"]) == 1
64+
assert len(reg["tributos"]) == 1
65+
assert len(reg["cbtes_asoc"]) == 0
66+
assert len(reg["opcionales"]) == 0
6767

6868
def test_escribir(self):
6969
# Prueba de la función escribir
7070
regs = formato_xml.leer(self.entrada_xml)
7171
formato_xml.escribir(regs, self.salida_xml)
72-
self.assertTrue(os.path.exists(self.salida_xml))
72+
assert os.path.exists(self.salida_xml)
7373

7474
# Verificar si el archivo escrito contiene el contenido XML esperado
7575
with open(self.salida_xml, "r") as f:
7676
xml_content = f.read()
77-
self.assertIn('<?xml version="1.0" encoding="UTF-8"?>', xml_content)
78-
self.assertIn("<comprobantes>", xml_content)
79-
self.assertIn("</comprobantes>", xml_content)
77+
assert '<?xml version="1.0" encoding="UTF-8"?>' in xml_content
78+
assert "<comprobantes>" in xml_content
79+
assert "</comprobantes>" in xml_content
8080

8181
def test_serializar(self):
8282
# Prueba de la función serializar
8383
regs = formato_xml.leer(self.entrada_xml)
8484
xml = formato_xml.serializar(regs)
85-
self.assertIsInstance(xml, str)
86-
self.assertTrue(xml.startswith('<?xml version="1.0" encoding="UTF-8"?>'))
87-
self.assertIn("<comprobantes>", xml)
88-
self.assertIn("<comprobante>", xml)
89-
self.assertIn("<detalles>", xml)
90-
self.assertIn("<ivas>", xml)
91-
self.assertIn("<tributos>", xml)
85+
assert isinstance(xml, str)
86+
assert xml.startswith('<?xml version="1.0" encoding="UTF-8"?>')
87+
assert "<comprobantes>" in xml
88+
assert "<comprobante>" in xml
89+
assert "<detalles>" in xml
90+
assert "<ivas>" in xml
91+
assert "<tributos>" in xml
9292

9393
def test_mapear(self):
9494
# Prueba de la función mapear
9595
# Mapeo con comportamiento predeterminado
9696
old = {"tipo_cbte": 1, "punto_vta": 2, "cbt_numero": 3}
97-
new = formato_xml.mapear({}, old, {"tipo": "tipo_cbte", "ptovta": "punto_vta", "numero": "cbt_numero"})
98-
self.assertEqual(new, {"tipo": 1, "ptovta": 2, "numero": 3})
97+
new = formato_xml.mapear(
98+
{},
99+
old,
100+
{
101+
"tipo": "tipo_cbte",
102+
"ptovta": "punto_vta",
103+
"numero": "cbt_numero"
104+
},
105+
)
106+
assert new == {"tipo": 1, "ptovta": 2, "numero": 3}
99107

100108
# Mapeo con swap=True
101109
old = {"tipo_cbte": 1, "punto_vta": 2, "cbt_numero": 3}
102-
new = formato_xml.mapear({}, old, {"tipo_cbte": "tipo", "punto_vta": "ptovta", "cbt_numero": "numero"}, swap=True)
103-
self.assertEqual(new, {"tipo": 1, "ptovta": 2, "numero": 3})
110+
new = formato_xml.mapear(
111+
{},
112+
old,
113+
{
114+
"tipo_cbte": "tipo",
115+
"punto_vta": "ptovta",
116+
"cbt_numero": "numero"
117+
},
118+
swap=True,
119+
)
120+
assert new == {"tipo": 1, "ptovta": 2, "numero": 3}
104121

105122
# Mapeo con valor faltante
106123
old = {"tipo_cbte": 1, "punto_vta": 2}
107-
new = formato_xml.mapear({}, old, {"tipo": "tipo_cbte", "ptovta": "punto_vta", "numero": "cbt_numero"})
108-
self.assertEqual(new, {"tipo": 1, "ptovta": 2})
124+
new = formato_xml.mapear(
125+
{},
126+
old,
127+
{
128+
"tipo": "tipo_cbte",
129+
"ptovta": "punto_vta",
130+
"numero": "cbt_numero"
131+
},
132+
)
133+
assert new == {"tipo": 1, "ptovta": 2}
109134

110135
# Mapeo con diccionario vacío
111136
old = {}
112-
new = formato_xml.mapear({}, old, {"tipo": "tipo_cbte", "ptovta": "punto_vta", "numero": "cbt_numero"})
113-
self.assertEqual(new, {})
137+
new = formato_xml.mapear(
138+
{},
139+
old,
140+
{
141+
"tipo": "tipo_cbte",
142+
"ptovta": "punto_vta",
143+
"numero": "cbt_numero"
144+
},
145+
)
146+
assert new == {}
114147

115148
def test_desserializar(self):
116149
# Prueba de la función desserializar
117150
xml_data = open(self.entrada_xml, "rb").read()
118151
regs = formato_xml.desserializar(xml_data)
119-
self.assertEqual(len(regs), 1)
152+
assert len(regs) == 1
120153
# Agregar más aserciones para los datos deserializados
121154

122155
def test_serializar_empty(self):
123156
# Prueba de la función serializar con una lista vacía
124157
regs = []
125158
xml = formato_xml.serializar(regs)
126-
self.assertIsInstance(xml, str)
127-
self.assertTrue(xml.startswith('<?xml version="1.0" encoding="UTF-8"?>'))
128-
self.assertIn("<comprobantes/>", xml)
159+
assert isinstance(xml, str)
160+
assert xml.startswith('<?xml version="1.0" encoding="UTF-8"?>')
161+
assert "<comprobantes/>" in xml
129162

130163
def test_mapear_exception(self):
131164
# Prueba para cubrir el manejo de excepciones en la función mapear
132165
old = {"a": 1, "b": 2}
133166
mapping = None # Proporcionar un mapeo inválido para provocar una excepción
134-
with self.assertRaises(Exception):
167+
with pytest.raises(Exception):
135168
formato_xml.mapear({}, old, mapping)
136169

170+
137171
if __name__ == "__main__":
138-
unittest.main()
172+
pytest.main()

0 commit comments

Comments
 (0)