Esempio n. 1
0
    def test_dynamic_creation(self):
        # setup test variables
        poketable = load_pokemon()
        pikachuindex = 30  # pikachu
        vcb_indices = [2, 6, 11]  # Venusaur, Charizard, Blastoise
        checklist = ['Venusaur', 'Charizard', 'Blastoise']
        fullpokegen = Pokemon.create_pokemon_generator(poketable)
        cutpokegen = Pokemon.create_pokemon_generator(
            poketable.iloc[vcb_indices + [pikachuindex]])

        # test single row creation from Data frame
        pikachu = Pokemon.from_data_frame(poketable.iloc[pikachuindex])
        self.checkPokemon(pikachu, "Pikachu")

        # test multi row creation from data frame
        vcb = Pokemon.from_data_frame(poketable.iloc[vcb_indices])
        self.assertIsInstance(vcb, list)
        self.checkPokemon(vcb, checklist)

        # test single row pokegen with full df
        pikachufullgen = fullpokegen(pikachuindex)
        self.checkPokemon(pikachufullgen, "Pikachu")

        # test multi row pokegen with full df
        vcbfullgen = fullpokegen(vcb_indices)
        self.assertIsInstance(vcbfullgen, list)
        self.checkPokemon(vcbfullgen, checklist)

        # test single row pokegen with cut df
        pikachucutgen = cutpokegen(pikachuindex)
        self.checkPokemon(pikachucutgen, "Pikachu")

        # test multi row pokegen with cut df
        vcbcutgen = cutpokegen(vcb_indices)
        self.assertIsInstance(vcbcutgen, list)
        self.checkPokemon(vcbcutgen, checklist)
Esempio n. 2
0
                     (s) or strsearchfcngen('Trainer list')(s)):
        attrs = {'align': 'center'}
        tables = soup.find_all('table', attrs=attrs)
        for tab in tables:
            rows = tab.find_all('tr')
            rows = rows[1:(len(rows) - 1)]
            trainername = ''
            for r in rows:
                candidatetrainer = list(r.children)[1]
                if candidatetrainer.has_attr('rowspan'):
                    trainername = candidatetrainer.get_text()
                    trainername = trainername[:(len(trainername) - 1)]
                    while trainername[0] == ' ':
                        trainername = trainername[1:len(trainername)]
                pokemon = r.find_all('td', align='center')
                pokelist = []
                for p in pokemon:
                    link = p.find('a')
                    if link:
                        pokenamestr = link['href']
                        pokenamestr = pokenamestr[6:pokenamestr.index('_')]
                        try:
                            level = int(p.get_text()[4:])
                        except ValueError:
                            level = 50
                        pokelist += Pokemon.from_data_frame(
                            poketable.loc[poketable.name == pokenamestr],
                            level=level)
                print(trainername)
                tdb_trainers.insert(Trainer(pokelist, trainername).to_dict())