Beispiel #1
0
def test_datetimes():
    # Ignore seconds in comparisons, because they are off by one what is reported by Windows.
    # This might be a little nuance worth investigating at some point.

    # Played at 20 Feb 2011 22:44:48 UTC+2
    replay = sc2reader.read("test_replays/build17811/1.SC2Replay")
    assert replay.utc_date == datetime.datetime(2011, 2, 20, 20, 44, 47)

    # Played at 21 Feb 2011 00:42:13 UTC+2
    replay = sc2reader.read("test_replays/build17811/2.SC2Replay")
    assert replay.utc_date == datetime.datetime(2011, 2, 20, 22, 42, 12)

    # Played at 25 Feb 2011 16:36:28 UTC+2
    replay = sc2reader.read("test_replays/build17811/3.SC2Replay")
    assert replay.utc_date == datetime.datetime(2011, 2, 25, 14, 36, 26)
Beispiel #2
0
def test_datetimes():
    # Ignore seconds in comparisons, because they are off by one what is reported by Windows.
    # This might be a little nuance worth investigating at some point.

    # Played at 20 Feb 2011 22:44:48 UTC+2
    replay = sc2reader.read("test_replays/build17811/1.SC2Replay")
    assert replay.utc_date == datetime.datetime(2011, 2, 20, 20, 44, 47)

    # Played at 21 Feb 2011 00:42:13 UTC+2
    replay = sc2reader.read("test_replays/build17811/2.SC2Replay")
    assert replay.utc_date == datetime.datetime(2011, 2, 20, 22, 42, 12)

    # Played at 25 Feb 2011 16:36:28 UTC+2
    replay = sc2reader.read("test_replays/build17811/3.SC2Replay")
    assert replay.utc_date == datetime.datetime(2011, 2, 25, 14, 36, 26)
Beispiel #3
0
def test_3v3():
    replay = sc2reader.read("test_replays/build17811/3.SC2Replay")
    assert replay.type == "3v3"

    # Because it's a 3v3 and all of the members of Team 2 quit, we should know the winner.
    assert replay.results[1] == "Won"
    assert replay.results[2] == "Lost"
Beispiel #4
0
def test_16():
    replay = sc2reader.read("test_replays/build17811/16.SC2Replay")
    print replay.realm
    print len(replay.players)
    print replay.players[0].actual_race
    print replay.players[1].actual_race
    assert 1 == 0
Beispiel #5
0
def test_3v3():
    replay = sc2reader.read("test_replays/build17811/3.SC2Replay")
    assert replay.type == "3v3"

    # Because it's a 3v3 and all of the members of Team 2 quit, we should know the winner.
    assert replay.results[1] == "Won"
    assert replay.results[2] == "Lost"
Beispiel #6
0
def test_16():
    replay = sc2reader.read("test_replays/build17811/16.SC2Replay")
    print replay.realm
    print len(replay.players)
    print replay.players[0].actual_race
    print replay.players[1].actual_race
    assert 1 == 0
Beispiel #7
0
def test_ffa():
    replay = sc2reader.read("test_replays/build17811/8.SC2Replay")
    assert replay.type == "FFA"

    # Player 'Boom' won because the last building of the last player was destroyed,
    # but the winner cannot be parsed because "Player has left" event isn't generated.
    # Unknown result is the best we can do.
    assert replay.winner_known == False
Beispiel #8
0
def test_ffa():
    replay = sc2reader.read("test_replays/build17811/8.SC2Replay")
    assert replay.type == "FFA"

    # Player 'Boom' won because the last building of the last player was destroyed,
    # but the winner cannot be parsed because "Player has left" event isn't generated.
    # Unknown result is the best we can do.
    assert replay.winner_known == False
Beispiel #9
0
def test_25():
    replay = sc2reader.read("test_replays/build17811/25.SC2Replay")
    print replay.realm
    print len(replay.players)
    print replay.players[0].actual_race
    print replay.players[1].actual_race
    print replay.players[0].choosen_race
    print replay.players[1].choosen_race
    print replay.players[0].name
    print replay.players[1].name
    assert 1 == 0
Beispiel #10
0
def test_25():
    replay = sc2reader.read("test_replays/build17811/25.SC2Replay")
    print replay.realm
    print len(replay.players)
    print replay.players[0].actual_race
    print replay.players[1].actual_race
    print replay.players[0].choosen_race
    print replay.players[1].choosen_race
    print replay.players[0].name
    print replay.players[1].name
    assert 1 == 0
Beispiel #11
0
def parse_replays():
    # Run four times to dampen noise
    for run in range(1,4):
        file_list = []
        rootdir = "test_replays/build17811/"
        for root, sub_folders, files in os.walk(rootdir):
            for file in files:
                basename, extension = os.path.splitext(file)
                if (basename not in skipnames and extension.lower() == ".sc2replay"):
                    file_list.append(os.path.join(root,file))

        for file in file_list:
            print file
            replay = sc2reader.read(file)
Beispiel #12
0
def parse_replays():
    # Run four times to dampen noise
    for run in range(1, 4):
        file_list = []
        rootdir = "test_replays/build17811/"
        for root, sub_folders, files in os.walk(rootdir):
            for file in files:
                basename, extension = os.path.splitext(file)
                if (basename not in skipnames
                        and extension.lower() == ".sc2replay"):
                    file_list.append(os.path.join(root, file))

        for file in file_list:
            print file
            replay = sc2reader.read(file)
Beispiel #13
0
def test_kr_realm_and_tampered_messages():
    replay = sc2reader.read("test_replays/build17811/11.SC2Replay")
    assert replay.person["명지대학교"].url == "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/"
    assert replay.person["티에스엘사기수"].url == "http://kr.battle.net/sc2/en/profile/102472/1/티에스엘사기수/"

    assert replay.messages[0].text == "sc2.replays.net"
    assert replay.messages[5].text == "sc2.replays.net"

    print replay.players[1].choosen_race
    print replay.players[1].actual_race

    print replay.players[0].choosen_race
    print replay.players[0].actual_race

    print replay.map
Beispiel #14
0
def test_two_player_game_without_winner():
    replay = sc2reader.read("test_replays/build17811/23.SC2Replay")
    print replay.realm
    print len(replay.players)
    print replay.players[0].actual_race
    print replay.players[1].actual_race
    print replay.players[0].choosen_race
    print replay.players[1].choosen_race
    print replay.players[0].name
    print replay.players[1].name
    print len(replay.actors)
    print replay.players[0].result
    print replay.players[1].result
    print replay.actors[2].result
    print replay.actors[3].result
    assert replay.players[0].result == "Win" or replay.players[1].result == "Win"
Beispiel #15
0
def test_kr_realm_and_tampered_messages():
    replay = sc2reader.read("test_replays/build17811/11.SC2Replay")
    assert replay.person[
        '명지대학교'].url == "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/"
    assert replay.person[
        '티에스엘사기수'].url == "http://kr.battle.net/sc2/en/profile/102472/1/티에스엘사기수/"

    assert replay.messages[0].text == "sc2.replays.net"
    assert replay.messages[5].text == "sc2.replays.net"

    print replay.players[1].choosen_race
    print replay.players[1].actual_race

    print replay.players[0].choosen_race
    print replay.players[0].actual_race

    print replay.map
Beispiel #16
0
def test_two_player_game_without_winner():
    replay = sc2reader.read("test_replays/build17811/23.SC2Replay")
    print replay.realm
    print len(replay.players)
    print replay.players[0].actual_race
    print replay.players[1].actual_race
    print replay.players[0].choosen_race
    print replay.players[1].choosen_race
    print replay.players[0].name
    print replay.players[1].name
    print len(replay.actors)
    print replay.players[0].result
    print replay.players[1].result
    print replay.actors[2].result
    print replay.actors[3].result
    assert replay.players[0].result == 'Win' or replay.players[
        1].result == 'Win'
def show_replay(replay_id):
    """docstring for show_replay"""

    # load the replay file
    path = os.path.join(UPLOAD_FOLDER, replay_id)
    replays = sc2reader.read(path, load_level=4)
    replay = replays[0]

    players = list()
    winners = list()

    for team in replay.teams:
        for person in team:
            players.append(person)
            if person.result == "Win":
                winners.append(person)

    return render_template("replayview.html", winners=winners, matchlength=replay.length, players=players)
Beispiel #18
0
def test_random_player2():
    replay = sc2reader.read("test_replays/build17811/6.SC2Replay")
    permafrost = replay.person["Permafrost"]
    assert permafrost.choosen_race == "Random"
    assert permafrost.actual_race == "Protoss"
Beispiel #19
0
def test_empty():
    # Todo: Are we happy with it raising a ValueError? Should it be rather ParseError or something else?
    # Maybe a "production" mode would be nice to have, so that it simply returns a status of the parse without
    # raising an exception.
    with pytest.raises(ValueError):
        sc2reader.read("test_replays/corrupted/empty.SC2Replay")
Beispiel #20
0
def test_random_player():
    replay = sc2reader.read("test_replays/build17811/3.SC2Replay")

    gogeta = replay.person["Gogeta"]
    assert gogeta.choosen_race == "Random"
    assert gogeta.actual_race == "Terran"
Beispiel #21
0
import sys, sc2reader

sc2reader.read(sys.argv[1])
Beispiel #22
0
def test_unknown_winner():
    replay = sc2reader.read("test_replays/build17811/10.SC2Replay")

    # Recording player (Boom) left second in a 4v4, so the winner shouldn't be known
    assert replay.winner_known == False
Beispiel #23
0
def test_referee():
    replay = sc2reader.read("test_replays/build17811/14.SC2Replay")
Beispiel #24
0
def test_encrypted():
    replay = sc2reader.read("test_replays/build17811/4.SC2Replay")
Beispiel #25
0
def test_observers():
    replay = sc2reader.read("test_replays/build17811/13.SC2Replay")
Beispiel #26
0
def test_random_player2():
    replay = sc2reader.read("test_replays/build17811/6.SC2Replay")
    permafrost = replay.person["Permafrost"]
    assert permafrost.choosen_race == "Random"
    assert permafrost.actual_race == "Protoss"
Beispiel #27
0
def parse_replays():
    # Run four times to dampen noise
    for run in range(1, 4):
        sc2reader.read("test_replays/1.3.0.18092", verbose=True)
Beispiel #28
0
def test_empty():
    # Todo: Are we happy with it raising a ValueError? Should it be rather ParseError or something else?
    # Maybe a "production" mode would be nice to have, so that it simply returns a status of the parse without
    # raising an exception.
    with pytest.raises(ValueError):
        sc2reader.read("test_replays/corrupted/empty.SC2Replay")
Beispiel #29
0
def test_private_category():
    replay = sc2reader.read("test_replays/build17811/2.SC2Replay")
    assert replay.is_private == True
    assert replay.is_ladder == False
Beispiel #30
0
def test_unknown_winner():
    replay = sc2reader.read("test_replays/build17811/10.SC2Replay")

    # Recording player (Boom) left second in a 4v4, so the winner shouldn't be known
    assert replay.winner_known == False
Beispiel #31
0
def test_observers():
    replay = sc2reader.read("test_replays/build17811/13.SC2Replay")
Beispiel #32
0
def test_us_realm():
    replay = sc2reader.read("test_replays/build17811/5.SC2Replay")
    assert replay.person["ShadesofGray"].url == "http://us.battle.net/sc2/en/profile/2358439/1/ShadesofGray/"
    assert replay.person["reddawn"].url == "http://us.battle.net/sc2/en/profile/2198663/1/reddawn/"
Beispiel #33
0
def test_2v2():
    replay = sc2reader.read("test_replays/build17811/7.SC2Replay")
    assert replay.type == "2v2"
Beispiel #34
0
def test_us_realm():
    replay = sc2reader.read("test_replays/build17811/5.SC2Replay")
    assert replay.person[
        'ShadesofGray'].url == "http://us.battle.net/sc2/en/profile/2358439/1/ShadesofGray/"
    assert replay.person[
        'reddawn'].url == "http://us.battle.net/sc2/en/profile/2198663/1/reddawn/"
Beispiel #35
0
def test_4v4():
    replay = sc2reader.read("test_replays/build17811/9.SC2Replay")
    assert replay.type == "4v4"
Beispiel #36
0
def test_encrypted():
    replay = sc2reader.read("test_replays/build17811/4.SC2Replay")
Beispiel #37
0
def test_referee():
    replay = sc2reader.read("test_replays/build17811/14.SC2Replay")
Beispiel #38
0
def test_private_category():
    replay = sc2reader.read("test_replays/build17811/2.SC2Replay")
    assert replay.is_private == True
    assert replay.is_ladder == False
Beispiel #39
0
def test_random_player():
    replay = sc2reader.read("test_replays/build17811/3.SC2Replay")

    gogeta = replay.person['Gogeta']
    assert gogeta.choosen_race == "Random"
    assert gogeta.actual_race == "Terran"
Beispiel #40
0
def test_standard_1v1():
    replay = sc2reader.read("test_replays/build17811/1.SC2Replay")

    assert replay.length == (32, 47)
    assert replay.map == "Lost Temple"
    assert replay.build == 17811
    assert replay.release_string == "1.2.2.17811"
    assert replay.speed == "Faster"
    assert replay.type == "1v1"

    assert replay.is_ladder == True
    assert replay.is_private == False

    assert len(replay.players) == 2
    assert replay.person[1].name == "Emperor"
    assert replay.person[2].name == "Boom"
    emperor = replay.person["Emperor"]
    assert emperor.team == 1
    assert emperor.choosen_race == "Protoss"
    assert emperor.actual_race == "Protoss"
    assert emperor.recorder == False

    boom = replay.person["Boom"]
    assert boom.team == 2
    assert boom.choosen_race == "Terran"
    assert boom.actual_race == "Terran"
    assert boom.recorder == True

    for player in replay.players:
        assert player.type == "Human"

    # Because it is a 1v1 and the recording player quit, we should know the winner.
    assert emperor.result == "Won"
    assert boom.result == "Lost"

    assert emperor.url == "http://eu.battle.net/sc2/en/profile/520049/1/Emperor/"
    assert boom.url == "http://eu.battle.net/sc2/en/profile/1694745/1/Boom/"

    assert len(replay.messages) == 12
    assert replay.messages[0].text == "hf"
    assert replay.messages[0].sender.name == "Emperor"
    assert replay.messages[1].text == "HEYA"
    assert replay.messages[1].sender.name == "Boom"
    assert replay.messages[2].text == "gl hf"
    assert replay.messages[2].sender.name == "Boom"
    assert replay.messages[3].text == "sry for caps"
    assert replay.messages[3].sender.name == "Boom"
    assert replay.messages[4].text == "^^"
    assert replay.messages[4].sender.name == "Emperor"
    assert replay.messages[5].text == "noppe"
    assert replay.messages[5].sender.name == "Emperor"
    assert replay.messages[6].text == "you greedy bastard"
    assert replay.messages[6].sender.name == "Boom"
    assert replay.messages[7].text == "ggg"
    assert replay.messages[7].sender.name == "Boom"
    assert replay.messages[8].text == "WG"
    assert replay.messages[8].sender.name == "Emperor"
    assert replay.messages[9].text == "wg? :)"
    assert replay.messages[9].sender.name == "Boom"
    assert replay.messages[10].text == "wipe"
    assert replay.messages[10].sender.name == "Emperor"
    assert replay.messages[11].text == "huh?"
    assert replay.messages[11].sender.name == "Boom"

    for msg in replay.messages:
        assert msg.sent_to_all == True
Beispiel #41
0
def parse_replays():
    # Run four times to dampen noise
    for run in range(1,4):
        sc2reader.read("test_replays/1.3.0.18092",verbose=True)
Beispiel #42
0
def test_standard_1v1():
    replay = sc2reader.read("test_replays/build17811/1.SC2Replay")

    assert replay.length == (32, 47)
    assert replay.map == "Lost Temple"
    assert replay.build == 17811
    assert replay.release_string == "1.2.2.17811"
    assert replay.speed == "Faster"
    assert replay.type == "1v1"

    assert replay.is_ladder == True
    assert replay.is_private == False

    assert len(replay.players) == 2
    assert replay.person[1].name == "Emperor"
    assert replay.person[2].name == "Boom"
    emperor = replay.person['Emperor']
    assert emperor.team == 1
    assert emperor.choosen_race == "Protoss"
    assert emperor.actual_race == "Protoss"
    assert emperor.recorder == False

    boom = replay.person['Boom']
    assert boom.team == 2
    assert boom.choosen_race == "Terran"
    assert boom.actual_race == "Terran"
    assert boom.recorder == True

    for player in replay.players:
        assert player.type == "Human"

    # Because it is a 1v1 and the recording player quit, we should know the winner.
    assert emperor.result == "Won"
    assert boom.result == "Lost"

    assert emperor.url == "http://eu.battle.net/sc2/en/profile/520049/1/Emperor/"
    assert boom.url == "http://eu.battle.net/sc2/en/profile/1694745/1/Boom/"

    assert len(replay.messages) == 12
    assert replay.messages[0].text == "hf"
    assert replay.messages[0].sender.name == "Emperor"
    assert replay.messages[1].text == "HEYA"
    assert replay.messages[1].sender.name == "Boom"
    assert replay.messages[2].text == "gl hf"
    assert replay.messages[2].sender.name == "Boom"
    assert replay.messages[3].text == "sry for caps"
    assert replay.messages[3].sender.name == "Boom"
    assert replay.messages[4].text == "^^"
    assert replay.messages[4].sender.name == "Emperor"
    assert replay.messages[5].text == "noppe"
    assert replay.messages[5].sender.name == "Emperor"
    assert replay.messages[6].text == "you greedy bastard"
    assert replay.messages[6].sender.name == "Boom"
    assert replay.messages[7].text == "ggg"
    assert replay.messages[7].sender.name == "Boom"
    assert replay.messages[8].text == "WG"
    assert replay.messages[8].sender.name == "Emperor"
    assert replay.messages[9].text == "wg? :)"
    assert replay.messages[9].sender.name == "Boom"
    assert replay.messages[10].text == "wipe"
    assert replay.messages[10].sender.name == "Emperor"
    assert replay.messages[11].text == "huh?"
    assert replay.messages[11].sender.name == "Boom"

    for msg in replay.messages:
        assert msg.sent_to_all == True
Beispiel #43
0
def test_4v4():
    replay = sc2reader.read("test_replays/build17811/9.SC2Replay")
    assert replay.type == "4v4"
Beispiel #44
0
def test_2v2():
    replay = sc2reader.read("test_replays/build17811/7.SC2Replay")
    assert replay.type == "2v2"
Beispiel #45
0
import sys, sc2reader


sc2reader.read(sys.argv[1])