Beispiel #1
0
 def items(self) -> Dict[Item, int]:
     """A dictionary of items mapped to how many of them are recommended."""
     return SearchableDictionary(
         {
             Item(id=item.id, region=self.__region): item.count
             for item in self._data[BlockData].items
         }
     )  # TODO Add version; low priority and hopefully it's just never an issue
Beispiel #2
0
 def runes(self) -> Dict[Rune, int]:
     return SearchableDictionary({
         Rune(id=rune.id,
              region=self.__region,
              version=get_latest_version(self.__region, endpoint="rune")):
         rune.count
         for rune in self._data[CurrentGameParticipantData].runes
     })
Beispiel #3
0
 def masteries(self) -> Dict[Mastery, int]:
     return SearchableDictionary({
         Mastery(id=mastery.id,
                 region=self.__region,
                 version=get_latest_version(self.__region,
                                            endpoint="mastery")):
         mastery.points
         for mastery in self._data[CurrentGameParticipantData].masteries
     })
Beispiel #4
0
 def runes(self) -> Mapping[StaticdataRune, int]:
     try:
         counter = Counter(slot.id for slot in self._data[RunePageData].runes)
         return SearchableDictionary({StaticdataRune(id=id, region=self.region, version=get_latest_version(self.region, endpoint="rune")): count for id, count in counter.items()})
     except KeyError as error:
         # Return an empty dict if the rune page has no runes set
         if "current" in self._data[RunePageData]._dto:
             return {}
         else:
             raise error
Beispiel #5
0
 def masteries(self) -> Mapping[StaticdataMastery, int]:
     try:
         return SearchableDictionary({
             StaticdataMastery(id=mastery.id,
                               region=self.region,
                               version=get_latest_version(
                                   self.region, endpoint="mastery")):
             mastery.points
             for mastery in self._data[MasteryPageData].masteries
         })
     except KeyError as error:
         # Return an empty dict if the mastery page has no masteries set
         if "current" in self._data[MasteryPageData]._dto:
             return {}
         else:
             raise error
Beispiel #6
0
def test_delete_dict_normal():
    dict_ = SearchableDictionary({
        other: outer,
        inner: normal,
        "value": defined
    })
    with pytest.raises(SearchError):
        del dict_["tionary"]

    assert dict_ == {other: outer, inner: normal, "value": defined}

    del dict_[other]
    assert dict_ == {inner: normal, "value": defined}

    del dict_["value"]
    assert dict_ == {inner: normal}

    del dict_[inner]
    assert dict_ == {}
Beispiel #7
0
def test_delete_dict_key():
    dict_ = SearchableDictionary({
        other: outer,
        inner: normal,
        "value": defined
    })

    with pytest.raises(SearchError):
        del dict_["tionary"]

    with pytest.raises(SearchError):
        del dict_[0.0]

    with pytest.raises(SearchError):
        del dict_[bytes()]

    assert dict_ == {other: outer, inner: normal, "value": defined}

    del dict_["hello"]
    assert dict_ == {"value": defined}

    del dict_[defined]
    assert dict_ == {}
 def masteries(self) -> Mapping[StaticdataMastery, int]:
     return SearchableDictionary({
         StaticdataMastery(id=mastery.id, region=self.region.value):
         mastery.points
         for mastery in self._data[MasteryPageData].masteries
     })
Beispiel #9
0
 def items(self) -> Dict[Item, int]:
     """A dictionary of items mapped to how many of them are recommended."""
     return SearchableDictionary({Item(id=item.id): item.count for item in self._data[BlockData].items})
Beispiel #10
0
 def masteries(self) -> Dict[Mastery, int]:
     return SearchableDictionary({
         Mastery(id=mastery.id): mastery.points
         for mastery in self._data[CurrentGameParticipantData].masteries
     })
Beispiel #11
0
 def runes(self) -> Dict[Rune, int]:
     return SearchableDictionary({
         Rune(id=rune.id): rune.count
         for rune in self._data[CurrentGameParticipantData].runes
     })
Beispiel #12
0
def test_dict_delete():
    dict_ = SearchableDictionary({
        other: outer,
        inner: normal,
        "value": defined
    })

    with pytest.raises(SearchError):
        dict_.delete("tionary")

    with pytest.raises(SearchError):
        dict_.delete(0.0)

    with pytest.raises(SearchError):
        dict_.delete(bytes())

    assert dict_ == {other: outer, inner: normal, "value": defined}

    dict_.delete("hello")
    assert dict_ == {"value": defined}

    dict_.delete(defined)
    assert dict_ == {}
Beispiel #13
0
        return isinstance(item, int)


class NonSearchable(object):
    def __init__(self, value):
        self.value = value


inner = Inner(["hello", "world"])
normal = NonSearchable(100.0)
outer = Outer(inner, normal, ["cat", "dog"], 100)
other = Inner(["foo", "bar"])
defined = ContainsDefined(["larry", "moe", "curly"])
list_ = SearchableList([other, normal, outer, inner, defined])
set_ = SearchableSet({other, normal, outer, inner, defined})
dict_ = SearchableDictionary({other: outer, inner: normal, "value": defined})


def test_simple_search():
    assert 100 in outer
    assert 0 not in outer


def test_bad_type():
    with pytest.raises(SearchError):
        100.0 in inner


def test_nested_key():
    assert 100.0 in outer
    assert 0.0 not in outer
Beispiel #14
0
 def runes(self) -> Mapping[StaticdataRune, int]:
     counter = Counter(slot.id for slot in self._data[RunePageData].runes)
     return SearchableDictionary({StaticdataRune(id=id, region=self.region.value): count for id, count in counter.items()})