def test_index():
    idx1 = index.getIndex()
    idx2 = index.getIndex()
    newCache = index.IndexCache()
    assert len(index.c.INCLUDED_KEYS) == 9
    x = index.c.InvalidMapSelection()
    try:
        raise index.c.InvalidMapSelection("test")
        assert False
    except:
        assert True
    assert isinstance(index.c.MAPS_FOLDER, str)
    assert isinstance(index.c.SC2_MAP_EXT, str)
Пример #2
0
def filterMapAttrs(records=getIndex(), **tags):
    """matches available maps if their attributes match as specified"""
    if len(tags) == 0:
        return records  # otherwise if unspecified, all given records match
    ret = []
    for record in records:  # attempt to match attributes
        if matchRecordAttrs(record, tags):
            ret.append(record)
    return ret
Пример #3
0
def filterMapNames(regexText,
                   records=getIndex(),
                   excludeRegex=False,
                   closestMatch=True):
    """matches each record against regexText according to parameters
    NOTE: the code could be written more simply, but this is loop-optimized to
          scale better with a large number of map records"""
    bestScr = 99999  # a big enough number to not be a valid file system path
    regex = re.compile(regexText, flags=re.IGNORECASE)
    ret = []
    if excludeRegex:  # match only records that do NOT contain regex
        if regexText and closestMatch:  # then maps with fewer characters are better matches
            for m in list(records):
                if re.search(regex, m.name):
                    continue  # map must NOT contain specified phrase
                score = len(
                    m.name
                )  # the map with the smallest map name means it has the largets matching character percentage
                if score == bestScr:
                    bestScr = score
                    ret.append(m)
                elif score < bestScr:  # new set of best maps
                    bestScr = score
                    ret = [m]
        else:  # all maps that match regex are included
            for m in list(records):
                if re.search(regex, m.name):
                    continue  # map must NOT contain specified phrase
                ret.append(m)  # any mapname containing regex matches
    else:  # only match records that contain regex
        if regexText and closestMatch:  # then maps with fewer characters are better matches
            for m in records:
                if not re.search(regex, m.name):
                    continue  # map must contain specified phrase if excludeRegex==True
                score = len(
                    m.name
                )  # the map with the smallest map name means it has the largets matching character percentage
                if score == bestScr:
                    bestScr = score
                    ret.append(m)
                elif score < bestScr:  # new group of best maps
                    bestScr = score
                    ret = [m]
        else:  # all maps that match regex are included
            for m in records:
                if not re.search(regex, m.name):
                    continue  # map must contain specified phrase if excludeRegex==True
                ret.append(m)  # any mapname containing regex matches
    return ret