Skip to content

Commit

Permalink
Merge branch 'master' into imp_no_error_missing_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ecarreras committed Aug 30, 2016
2 parents ab75c85 + 2d9be92 commit 51b8707
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ script:
after_success:
- coveralls
- coverage report
deploy:
provider: pypi
user: gisce
password:
secure: mxWzYVAFP/JgavnLxT3jvHno6+8ItIDaXJ3IWts+uqxNEVxZ1bcv2NR/sj/CbHiCz+52nRIpcfHCOx4hv4RtS3WGWz+SS/DOLSPgUGFrlpI2wMOWKHQYQMlES6wHqfVx01+HZCIqHED0ArB76QkPItKjPpe9bxtZ8/tiXXrfFkW77sRGInqqHK8A7exT+E5Y+ZgZME3BdJzljyIx1qEQZLWv299j95rvFD2rheo3m/I7r6dAdYTAbjkkCf7IgcfOzHuIVENbYNgrPMEOnPHISj2BwCKHoPHJGG3C9R73njEKV9frJXNv6pCd8Ib5trejoGM/5bcIvToQgsoURYWI8qi/FRTDAkC/TOk2VtnMAGuq70wHK8SfM5SPLm6nR8fJsEOFsa2EYdf5ocyosgquFUgcPSmy1A0NnWYz6j1JChhrhRzXZ6oS9lLaYcw7qBdUdIjA5HMfNaRJd75SzlgUOI2MrApRQgvgV90cA5y8bnQ47Xgn+aomR5TA3dhgVl8XewOI340iJ/MdUYDh0nQm6j0lUD77upI+PHcLajP0htkWWIa2tMo61zWvDkXhahRgCywULAqnxNmtEfv9m0YkUEzV077LdR+G7s9vFoIwwfFH/fsPdAMek8j/QLLY4MC9PEGFXbnQVWTkdwT5PbQUgPC81oIsX9Ov48bL2r/qK2o=
on:
tags: true
repo: gisce/switching
2 changes: 1 addition & 1 deletion switching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import os

__version__ = '2.6.41'
__version__ = '2.7.1'

_ROOT = os.path.abspath(os.path.dirname(__file__))

Expand Down
44 changes: 21 additions & 23 deletions switching/output/messages/mesures.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,41 @@ def __init__(self):
super(Integrador, self).__init__('Integrador', 'integrador')


class NoICP(XmlModel):
class DatosAparato(XmlModel):

_sort_order = ('noicp', 'periode_fabricacio', 'num_serie',
_sort_order = ('datosaparato', 'periode_fabricacio', 'num_serie',
'funcio', 'num_integradors', 'constant_energia',
'constant_max', 'enters', 'decimals')

def __init__(self):
self.noicp = XmlField('DatosAparatoNoICP')
def __init__(self, tagname='DatosAparato'):
self.datosaparato = XmlField(tagname)
self.periode_fabricacio = XmlField('PeriodoFabricacion')
self.num_serie = XmlField('NumeroSerie')
self.funcio = XmlField('FuncionAparato')
self.num_integradors = XmlField('NumIntegradores')
self.constant_energia = XmlField('ConstanteEnergia', rep=lambda x: '%.3f' % x)
self.constant_max = XmlField('ConstanteMaximetro', rep=lambda x: '%.3f' % x)
self.num_integradors = XmlField(
'NumIntegradores', rep=lambda x: '%i' % x
)
self.constant_energia = XmlField(
'ConstanteEnergia', rep=lambda x: '%.3f' % x
)
self.constant_max = XmlField(
'ConstanteMaximetro', rep=lambda x: '%.3f' % x
)
self.enters = XmlField('RuedasEnteras', rep=lambda x: '%i' % x)
self.decimals = XmlField('RuedasDecimales', rep=lambda x: '%i' % x)
super(NoICP, self).__init__('DatosAparatoNoICP', 'noicp')
super(DatosAparato, self).__init__(tagname, 'datosaparato')


class ICP(XmlModel):
class NoICP(DatosAparato):

_sort_order = ('icp', 'periode_fabricacio', 'num_serie',
'funcio', 'num_integradors', 'constant_energia',
'constant_max', 'enters', 'decimals')
def __init__(self):
super(NoICP, self).__init__(tagname='DatosAparatoNoICP')


class ICP(DatosAparato):

def __init__(self):
self.icp = XmlField('DatosAparatoICP')
self.periode_fabricacio = XmlField('PeriodoFabricacion')
self.num_serie = XmlField('NumeroSerie',
rep=lambda x: x[:10])
self.funcio = XmlField('FuncionAparato')
self.num_integradors = XmlField('NumIntegradores')
self.constant_energia = XmlField('ConstanteEnergia', rep=lambda x: '%.3f' % x)
self.constant_max = XmlField('ConstanteMaximetro', rep=lambda x: '%.3f' % x)
self.enters = XmlField('RuedasEnteras')
self.decimals = XmlField('RuedasDecimales')
super(ICP, self).__init__('DatosAparatoICP', 'icp')
super(ICP, self).__init__(tagname='DatosAparatoICP')


class Modelo(XmlModel):
Expand Down
10 changes: 10 additions & 0 deletions tests/data/DatosAparatoConIntegradores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DatosAparato>
<PeriodoFabricacion>2015</PeriodoFabricacion>
<NumeroSerie>753855</NumeroSerie>
<FuncionAparato>M</FuncionAparato>
<NumIntegradores>20</NumIntegradores>
<ConstanteEnergia>1.000</ConstanteEnergia>
<ConstanteMaximetro>1.000</ConstanteMaximetro>
<RuedasEnteras>1</RuedasEnteras>
<RuedasDecimales>0</RuedasDecimales>
</DatosAparato>
10 changes: 10 additions & 0 deletions tests/data/DatosAparatoICPConIntegradores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DatosAparatoICP>
<PeriodoFabricacion>2015</PeriodoFabricacion>
<NumeroSerie>753855</NumeroSerie>
<FuncionAparato>M</FuncionAparato>
<NumIntegradores>20</NumIntegradores>
<ConstanteEnergia>1.000</ConstanteEnergia>
<ConstanteMaximetro>1.000</ConstanteMaximetro>
<RuedasEnteras>1</RuedasEnteras>
<RuedasDecimales>0</RuedasDecimales>
</DatosAparatoICP>
10 changes: 10 additions & 0 deletions tests/data/DatosAparatoICPSinIntegradores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DatosAparatoICP>
<PeriodoFabricacion>2015</PeriodoFabricacion>
<NumeroSerie>753855</NumeroSerie>
<FuncionAparato>M</FuncionAparato>
<NumIntegradores>0</NumIntegradores>
<ConstanteEnergia>1.000</ConstanteEnergia>
<ConstanteMaximetro>1.000</ConstanteMaximetro>
<RuedasEnteras>1</RuedasEnteras>
<RuedasDecimales>0</RuedasDecimales>
</DatosAparatoICP>
10 changes: 10 additions & 0 deletions tests/data/DatosAparatoNoICPConIntegradores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DatosAparatoNoICP>
<PeriodoFabricacion>2015</PeriodoFabricacion>
<NumeroSerie>753855</NumeroSerie>
<FuncionAparato>M</FuncionAparato>
<NumIntegradores>20</NumIntegradores>
<ConstanteEnergia>1.000</ConstanteEnergia>
<ConstanteMaximetro>1.000</ConstanteMaximetro>
<RuedasEnteras>1</RuedasEnteras>
<RuedasDecimales>0</RuedasDecimales>
</DatosAparatoNoICP>
10 changes: 10 additions & 0 deletions tests/data/DatosAparatoNoICPSinIntegradores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DatosAparatoNoICP>
<PeriodoFabricacion>2015</PeriodoFabricacion>
<NumeroSerie>753855</NumeroSerie>
<FuncionAparato>M</FuncionAparato>
<NumIntegradores>0</NumIntegradores>
<ConstanteEnergia>1.000</ConstanteEnergia>
<ConstanteMaximetro>1.000</ConstanteMaximetro>
<RuedasEnteras>1</RuedasEnteras>
<RuedasDecimales>0</RuedasDecimales>
</DatosAparatoNoICP>
10 changes: 10 additions & 0 deletions tests/data/DatosAparatoSinIntegradores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<DatosAparato>
<PeriodoFabricacion>2015</PeriodoFabricacion>
<NumeroSerie>753855</NumeroSerie>
<FuncionAparato>M</FuncionAparato>
<NumIntegradores>0</NumIntegradores>
<ConstanteEnergia>1.000</ConstanteEnergia>
<ConstanteMaximetro>1.000</ConstanteMaximetro>
<RuedasEnteras>1</RuedasEnteras>
<RuedasDecimales>0</RuedasDecimales>
</DatosAparato>
138 changes: 138 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
)
from switching.output.messages.sw_c2 import CiePapel, DatosCie, DocTecnica,\
RegistroDoc, RegistrosDocumento
from switching.output.messages.mesures import NoICP, ICP, DatosAparato

from . import unittest
import os
import decimal
Expand Down Expand Up @@ -309,5 +311,141 @@ def test_build_tree_medida_baja(self):
xml, self.loadFile('CondContractualesMedidaBaja.xml')
)


class test_NoICP(unittest.TestCase):
def loadFile(self, filename):
with open(get_data(filename), "r") as f:
return f.read()

def setUp(self):
pass

def test_build_NoIntegradores(self):
c = NoICP()
c.feed({
'periode_fabricacio': 2015,
'num_serie': '753855',
'funcio': 'M',
'num_integradors': 0,
'constant_energia': 1.0,
'constant_max': 1.0,
'enters': 1,
'decimals': 0,
})
c.build_tree()
xml = str(c)
self.assertXmlEqual(xml, self.loadFile(
'DatosAparatoNoICPSinIntegradores.xml'
))

def test_build_Integradores(self):
c = NoICP()
c.feed({
'periode_fabricacio': 2015,
'num_serie': '753855',
'funcio': 'M',
'num_integradors': 20,
'constant_energia': 1.0,
'constant_max': 1.0,
'enters': 1,
'decimals': 0,
})
c.build_tree()
xml = str(c)
self.assertXmlEqual(xml, self.loadFile(
'DatosAparatoNoICPConIntegradores.xml'
))


class test_DatosAparato(unittest.TestCase):
def loadFile(self, filename):
with open(get_data(filename), "r") as f:
return f.read()

def setUp(self):
pass

def test_build_NoIntegradores(self):
c = DatosAparato()
c.feed({
'periode_fabricacio': 2015,
'num_serie': '753855',
'funcio': 'M',
'num_integradors': 0,
'constant_energia': 1.0,
'constant_max': 1.0,
'enters': 1,
'decimals': 0,
})
c.build_tree()
xml = str(c)
self.assertXmlEqual(xml, self.loadFile(
'DatosAparatoSinIntegradores.xml'
))

def test_build_Integradores(self):
c = DatosAparato()
c.feed({
'periode_fabricacio': 2015,
'num_serie': '753855',
'funcio': 'M',
'num_integradors': 20,
'constant_energia': 1.0,
'constant_max': 1.0,
'enters': 1,
'decimals': 0,
})
c.build_tree()
xml = str(c)
self.assertXmlEqual(xml, self.loadFile(
'DatosAparatoConIntegradores.xml'
))


class test_ICP(unittest.TestCase):
def loadFile(self, filename):
with open(get_data(filename), "r") as f:
return f.read()

def setUp(self):
pass

def test_build_NoIntegradores(self):
c = ICP()
c.feed({
'periode_fabricacio': 2015,
'num_serie': '753855',
'funcio': 'M',
'num_integradors': 0,
'constant_energia': 1.0,
'constant_max': 1.0,
'enters': 1,
'decimals': 0,
})
c.build_tree()
xml = str(c)
self.assertXmlEqual(xml, self.loadFile(
'DatosAparatoICPSinIntegradores.xml'
))

def test_build_Integradores(self):
c = ICP()
c.feed({
'periode_fabricacio': 2015,
'num_serie': '753855',
'funcio': 'M',
'num_integradors': 20,
'constant_energia': 1.0,
'constant_max': 1.0,
'enters': 1,
'decimals': 0,
})
c.build_tree()
xml = str(c)
self.assertXmlEqual(xml, self.loadFile(
'DatosAparatoICPConIntegradores.xml'
))


if __name__ == '__main__':
unittest.main()

0 comments on commit 51b8707

Please sign in to comment.