Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_timestamp_parsing():
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
assert parser.games[0].packets[0].ts == time(2, 59, 14, 608862)
# Test with an initial datetime
parser2 = LogParser()
parser2._current_date = datetime(2015, 1, 1)
parser2.read(StringIO(INITIAL_GAME))
parser2.flush()
assert parser2.games[0].packets[0].ts == datetime(2015, 1, 1, 2, 59, 14, 608862)
# Same test, with timezone
parser2 = LogParser()
parser2._current_date = parse_datetime("2015-01-01T02:58:00+0200")
def test_options_packet_with_errors():
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.read(StringIO(OPTIONS_WITH_ERRORS))
parser.flush()
packet_tree = parser.games[0]
options_packet = packet_tree.packets[-1]
op0 = options_packet.options[0]
assert op0.id == 0
assert op0.type == OptionType.END_TURN
assert op0.entity is None
assert op0.error == PlayReq.INVALID
assert op0.error_param is None
op1 = options_packet.options[1]
def test_game_initialization():
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
assert len(parser.games) == 1
packet_tree = parser.games[0]
game = packet_tree.export().game
assert len(game.entities) == 3
assert len(game.players) == 2
assert game.tags == {
GameTag.TURN: 1,
GameTag.ZONE: Zone.PLAY,
GameTag.ENTITY_ID: 1,
GameTag.NEXT_STEP: Step.BEGIN_MULLIGAN,
GameTag.CARDTYPE: CardType.GAME,
GameTag.STATE: State.RUNNING,
def test_info_outside_of_metadata():
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
info = u"D 02:59:14.6500380 GameState.DebugPrintPower() - Info[0] = 99"
parser.read(StringIO(info))
parser.flush()
def test_invalid_game_one_player():
parser = LogParser()
with pytest.raises(ParsingError):
parser.read(StringIO(INVALID_GAME))
def test_create_empty_game():
parser = LogParser()
parser.read(StringIO(EMPTY_GAME))
parser.flush()
# Test resulting game/entities
assert len(parser.games) == 1
packet_tree = parser.games[0]
game = packet_tree.export().game
assert len(game.entities) == 3
assert len(game.players) == 2
assert game.entities[0] is game
assert game.entities[0].id == 1
assert game.entities[1] is game.players[0]
assert game.entities[2] is game.players[1]
assert game.initial_state == State.INVALID
assert game.initial_step == Step.INVALID
def test_warn_level():
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
line = u"W 09:09:23.1428700 GameState.ReportStuck() - Stuck for 10s 89ms. {...}"
parser.read(StringIO(line))
parser.flush()
def test_empty_tasklist():
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
ts = datetime.now()
msg = "id=4 Player=The Innkeeper TaskList=1 ChoiceType=GENERAL CountMin=1 CountMax=1"
choices = parser.handle_entity_choices(ts, msg)
assert choices
assert choices.id == 4
assert choices.player.name == "The Innkeeper"
assert choices.tasklist == 1
assert choices.type == ChoiceType.GENERAL
assert choices.min == 1
assert choices.max == 1
# Test empty tasklist
msg = "id=4 Player=The Innkeeper TaskList= ChoiceType=GENERAL CountMin=1 CountMax=1"
def test_tag_change_unknown_entity_format():
# Format changed in 15590
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
entity_format = (
"[name=UNKNOWN ENTITY [cardType=INVALID] id=24 zone=DECK zonePos=0 cardId= player=1]"
)
id = parse_entity_id(entity_format)
assert id == 24
data = "TAG_CHANGE Entity=%s tag=ZONE value=HAND" % (entity_format)
packet = parser.handle_power(None, "TAG_CHANGE", data)
assert packet.power_type == PowerType.TAG_CHANGE
assert packet.entity == id
assert packet.tag == GameTag.ZONE
assert packet.value == Zone.HAND
parser = LogParser()
parser.read(StringIO(INITIAL_GAME))
parser.flush()
assert parser.games[0].packets[0].ts == time(2, 59, 14, 608862)
# Test with an initial datetime
parser2 = LogParser()
parser2._current_date = datetime(2015, 1, 1)
parser2.read(StringIO(INITIAL_GAME))
parser2.flush()
assert parser2.games[0].packets[0].ts == datetime(2015, 1, 1, 2, 59, 14, 608862)
# Same test, with timezone
parser2 = LogParser()
parser2._current_date = parse_datetime("2015-01-01T02:58:00+0200")
parser2.read(StringIO(INITIAL_GAME))
parser2.flush()
ts = parser2.games[0].packets[0].ts
assert ts.year == 2015
assert ts.hour == 2
assert ts.second == 14
assert ts.tzinfo
assert ts.utcoffset() == timedelta(hours=2)