File: test_parser.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (55 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from io import StringIO

from check.focs_dump_parser.parser import _get_name_from_line, parse_buildings

file_ = StringIO(
    """
00:00:34.002036 {0x00002980} [info] log : Logger.cpp:137 : Added logger named "conditions"
00:00:34.001036 {0x00002980} [trace] parsing : BuildingsParser.cpp:258 : Start parsing FOCS for BuildingTypes: 108
00:00:34.002036 {0x00002980} [debug] log : LoggerWithOptionsDB.cpp:108 : Configure log source "effects" from optionsDB using threshold debug
00:00:34.002036 {0x00002980} [trace] parsing : BuildingsParser.cpp:260 : BuildingType BLD_ABANDON_OUTPOST : 4243737
BuildingType
    name = "BLD_ABANDON_OUTPOST"
    description = "BLD_ABANDON_OUTPOST_DESC"
00:00:34.002036 {0x00002980} [trace] parsing : BuildingsParser.cpp:260 : BuildingType BLD_ART_BLACK_HOLE : 4128519
BuildingType
    name = "BLD_ART_BLACK_HOLE"
    description = "BLD_ART_BLACK_HOLE_DESC"
00:00:34.029042 {0x00002980} [trace] parsing : BuildingsParser.cpp:261 : End parsing FOCS for BuildingTypes108
""".strip()
)


bld_abandon_outpost = """
BuildingType
    name = "BLD_ABANDON_OUTPOST"
    description = "BLD_ABANDON_OUTPOST_DESC"
""".lstrip()

bld_art_black_hole = """
BuildingType
    name = "BLD_ART_BLACK_HOLE"
    description = "BLD_ART_BLACK_HOLE_DESC"
""".lstrip()


def test_parse():
    assert parse_buildings(file_) == [
        ("BLD_ABANDON_OUTPOST", bld_abandon_outpost),
        ("BLD_ART_BLACK_HOLE", bld_art_black_hole),
    ]


def test_get_name_from_line():
    assert (
        _get_name_from_line(
            "00:00:34.002036 {0x00002980} [trace] parsing : BuildingsParser.cpp:260 : BuildingType BLD_ABANDON_OUTPOST : 4243737"
        )
        == "BLD_ABANDON_OUTPOST"
    )
    assert (
        _get_name_from_line(
            '00:00:34.002036 {0x00002980} [info] log : Logger.cpp:257 : Setting "conditions" logger threshold to "debug".'
        )
        is None
    )