Beispiel #1
0
 def xml(self):
     return PlayerXMLDataset(username=self.playerdataset.username,
                             userid=self.playerdataset.userid,
                             name=self.playerdataset.name,
                             startposition=self.startposition,
                             colour=self.colour,
                             score=float(self.score),
                             new=self.new,
                             rating=self.rating,
                             win=self.win)
Beispiel #2
0
def one_winner_lower_is_better():
    plays_dataset = PlaysXMLDataset()
    plays_dataset.game_name = "No Thanks!"

    player_w = PlayerXMLDataset()
    player_w.name = "Winner"
    player_w.win = True
    player_w.score = 1

    player1 = PlayerXMLDataset()
    player1.name = "Player 1"
    player1.win = False
    player1.score = 8

    player2 = PlayerXMLDataset()
    player2.name = "Player 2"
    player2.win = False
    player2.score = 9

    player3 = PlayerXMLDataset()
    player3.name = "Player 3"
    player3.win = False
    player3.score = 10

    plays_dataset.add_player(player_w)
    plays_dataset.add_player(player1)
    plays_dataset.add_player(player2)
    plays_dataset.add_player(player3)

    return plays_dataset
Beispiel #3
0
def two_winners_no_score():
    plays_dataset = PlaysXMLDataset()
    plays_dataset.game_name = "Score Game"

    player_w = PlayerXMLDataset()
    player_w.name = "Winner"
    player_w.win = True

    player1 = PlayerXMLDataset()
    player1.name = "Player 1"
    player1.win = True

    player2 = PlayerXMLDataset()
    player2.name = "Player 2"
    player2.win = False

    player3 = PlayerXMLDataset()
    player3.name = "Player 3"
    player3.win = False

    plays_dataset.add_player(player_w)
    plays_dataset.add_player(player1)
    plays_dataset.add_player(player2)
    plays_dataset.add_player(player3)

    return plays_dataset
Beispiel #4
0
def second_place_tie():
    plays_dataset = PlaysXMLDataset()
    plays_dataset.game_name = "Score Game"

    player_w = PlayerXMLDataset()
    player_w.name = "Winner"
    player_w.win = True
    player_w.score = 10

    player1 = PlayerXMLDataset()
    player1.name = "Player 1"
    player1.win = False
    player1.score = 8

    player2 = PlayerXMLDataset()
    player2.name = "Player 2"
    player2.win = False
    player2.score = 8

    player3 = PlayerXMLDataset()
    player3.name = "Player 3"
    player3.win = False
    player3.score = 1

    plays_dataset.add_player(player_w)
    plays_dataset.add_player(player1)
    plays_dataset.add_player(player2)
    plays_dataset.add_player(player3)

    return plays_dataset
Beispiel #5
0
class ReadXMLTests(unittest.TestCase):
    readxml = ReadXML()

    attr1 = [
        'id', 'date', 'quantity', 'length', 'incomplete', 'nowinstats',
        'location', 'game_name', 'gameid'
    ]
    attr2 = [
        'username', 'userid', 'name', 'startposition', 'colour', 'score',
        'new', 'rating', 'win'
    ]

    xml_data = [
        PlaysXMLDataset(id=38023491,
                        date="2019-09-29",
                        quantity=1,
                        length=0,
                        incomplete=0,
                        nowinstats=0,
                        location="",
                        game_name="Asking for Trobils",
                        gameid=156442),
        PlaysXMLDataset(id=38021178,
                        date="2019-09-29",
                        quantity=1,
                        length=0,
                        incomplete=0,
                        nowinstats=0,
                        location="",
                        game_name="Coup",
                        gameid=131357)
    ]

    xml_data[0].players = [
        PlayerXMLDataset(username="******",
                         userid=508171,
                         name="Richard Allen",
                         position=1,
                         colour="",
                         score=32,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Jeff",
                         position=2,
                         colour="",
                         score=30,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Tanya",
                         position=3,
                         colour="",
                         score=41.1,
                         new=False,
                         rating=0,
                         win=True),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Arden",
                         position=4,
                         colour="",
                         score=35,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Shelly",
                         position=5,
                         colour="",
                         score=29,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Alex",
                         position=6,
                         colour="",
                         score=32,
                         new=False,
                         rating=0,
                         win=False)
    ]

    xml_data[1].players = [
        PlayerXMLDataset(username="******",
                         userid=508171,
                         name="Richard Allen",
                         position=1,
                         colour="",
                         score=0,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Jeff",
                         position=2,
                         colour="",
                         score=0,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Tanya",
                         position=3,
                         colour="",
                         score=0,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Damon",
                         position=4,
                         colour="",
                         score=0,
                         new=False,
                         rating=0,
                         win=False),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Arden",
                         position=5,
                         colour="",
                         score=0,
                         new=False,
                         rating=0,
                         win=True),
        PlayerXMLDataset(username="",
                         userid=0,
                         name="Shelly",
                         position=6,
                         colour="",
                         score=0,
                         new=False,
                         rating=0,
                         win=False)
    ]

    def test_read_xml_file(self):
        self.readxml.read_xml_file('test.xml')
        for x in self.attr1:
            play_fun1 = operator.attrgetter(x)
            for play_one, play_two in zip(self.readxml.plays, self.xml_data):
                self.assertEqual(play_fun1(play_one), play_fun1(play_two))
                for y in self.attr2:
                    play_fun2 = operator.attrgetter(y)
                    for player_one, player_two in zip(play_one.players,
                                                      play_two.players):
                        self.assertEqual(play_fun2(player_one),
                                         play_fun2(player_two))
Beispiel #6
0
 def xml(self):
     return PlayerXMLDataset(username=self.username,
                             userid=self.userid,
                             name=self.name)
Beispiel #7
0
    def _load_players(player):
        rtn = PlayerXMLDataset()
        rtn.username = player.attributes['username'].value
        rtn.userid = int(player.attributes['userid'].value)
        rtn.name = player.attributes['name'].value
        try:
            rtn.position = int(player.attributes['startposition'].value)
        except ValueError:
            pass
        rtn.colour = player.attributes['color'].value
        try:
            rtn.score = float(player.attributes['score'].value)
        except ValueError:
            pass
        rtn.new = bool(int(player.attributes['new'].value))
        rtn.rating = int(player.attributes['rating'].value)
        rtn.win = bool(int(player.attributes['win'].value))

        return rtn