Пример #1
0
 def test_update1(self):
     data1 = {'a': 3, 'b': 4, 'c': 5}
     data2 = {'a': 4, 'b': 5, 'c': 6}
     d1 = LoggedDict(exclusions={'a'})
     r1 = d1.update(data1)
     self.assertTrue(r1)
     self.assertEqual(d1['b'], 4)
     self.assertEqual(d1['c'], 5)
Пример #2
0
    def __init__(self, id, **kwargs):
        self.id = id
        self.edicion = kwargs.get('edicion', None)
        self.URL = generaURLPlantilla(self)
        self.timestamp = None

        self.club = LoggedDict()
        self.jugadores = DictOfLoggedDict()
        self.tecnicos = DictOfLoggedDict()
Пример #3
0
    def test_purge1(self):
        data1 = {'a': 3, 'b': 4, 'c': 5}
        d1 = LoggedDict(exclusions={'a'})
        d1.update(data1)

        r1 = d1.purge(['c'])
        self.assertTrue(r1)

        with self.assertRaises(ValueError):
            v1 = d1['c']
Пример #4
0
    def test_update2(self):
        data1 = {'a': 3, 'b': 4, 'c': 5}
        data2 = {'a': 4}
        d1 = LoggedDict(exclusions={'a'})
        d1.update(data1)
        r1 = d1.update(data2)

        self.assertFalse(r1)
        self.assertEqual(d1['b'], 4)
        self.assertEqual(d1['c'], 5)
Пример #5
0
    def test_setget2(self):
        d1 = LoggedDict(exclusions={'a'})

        d1['b'] = 3
        d1['b'] = 4
        v1 = d1['b']
        self.assertEqual(v1, 4)
        self.assertEqual(len(d1), 1)

        lv1 = d1.getValue('b')
        self.assertEqual(len(lv1), 2)
Пример #6
0
    def test_setget1(self):
        d1 = LoggedDict(exclusions={'a'})

        d1['b'] = 3
        v1 = d1['b']

        self.assertEqual(v1, 3)
        self.assertEqual(len(d1), 1)
Пример #7
0
class PlantillaACB(object):
    def __init__(self, id, **kwargs):
        self.id = id
        self.edicion = kwargs.get('edicion', None)
        self.URL = generaURLPlantilla(self)
        self.timestamp = None

        self.club = LoggedDict()
        self.jugadores = DictOfLoggedDict()
        self.tecnicos = DictOfLoggedDict()

    def descargaYactualizaPlantilla(self,
                                    home=None,
                                    browser=None,
                                    config=Namespace(),
                                    extraTrads=None):
        """
        Descarga los datos y llama al procedimiento para actualizar
        :param home:
        :param browser:
        :param config:
        :param extraTrads:
        :return:
        """
        if browser is None:
            browser = creaBrowser(config)

        data = descargaURLplantilla(self.URL,
                                    home,
                                    browser,
                                    config,
                                    otrosNombres=extraTrads)

        return self.actualizaPlantillaDescargada(data)

    def actualizaPlantillaDescargada(self, data):
        result = False

        currTimestamp = data.get('timestamp', gmtime())

        result = result | self.club.update(data.get('club', {}), currTimestamp)

        result = result | self.jugadores.update(data.get('jugadores', {}),
                                                currTimestamp)
        result = result | self.tecnicos.update(data.get('tecnicos', {}),
                                               currTimestamp)

        if self.edicion is None:
            self.edicion = data['edicion']
            result = True

        if result:
            self.timestamp = data.get('timestamp', gmtime())

        return result

    def getValorJugadores(self, clave, default=None):
        return self.jugadores.extractKey(key=clave, default=default)

    def __str__(self):
        result = "%s [%s] Year: %s Jugadores conocidos: %i Entrenadores conocidos: %i" % (
            self.club.get('nombreActual', "TBD"), self.id, self.edicion,
            len(self.jugadores), len(self.tecnicos))
        return result

    __repr__ = __str__
Пример #8
0
    def test_constructor1(self):
        d1 = LoggedDict()

        self.assertEqual(len(d1), 0)
Пример #9
0
    def test_constructor2(self):
        d1 = LoggedDict(exclusions={'a'})

        with self.assertRaises(KeyError):
            d1['a'] = 3