Пример #1
0
    def test___init___with_source(self):
        raw_map = {
            "not_in": (time.perf_counter() - 50, "goodbye"),
            "ok": (time.perf_counter() + 30, "no"),
            "blam": (time.perf_counter() + 20, "bye"),
        }
        mocK_map = mapping.MRIMutableMapping(raw_map, expiry=datetime.timedelta(seconds=42))

        assert mocK_map == {"blam": "bye", "ok": "no"}
Пример #2
0
 def test___setitem___removes_old_entry_instead_of_replacing(self):
     mock_map = mapping.MRIMutableMapping(
         {
             "ok": (time.perf_counter() + 50, "no"),
             "bar": (time.perf_counter() + 60, "bat"),
             "foo": (time.perf_counter() + 70, "blam"),
         },
         expiry=datetime.timedelta(seconds=100),
     )
     mock_map["ok"] = "foo"
     assert list(mock_map.items())[2] == ("ok", "foo")
Пример #3
0
    def test_freeze(self):
        raw_map = {
            "bash": (999999999999999999999999, "gtuutueu"),
            "blam": (999999999999999999999999, "poke"),
            "owowo": (999999999999999999999999, "no you"),
        }
        mock_map = mapping.MRIMutableMapping(raw_map, expiry=datetime.timedelta(seconds=6523423))
        result = mock_map.freeze()

        assert result == {"bash": "gtuutueu", "blam": "poke", "owowo": "no you"}
        assert isinstance(result, mapping._FrozenMRIMapping)
Пример #4
0
 async def test___setitem___garbage_collection(self):
     mock_map = mapping.MRIMutableMapping(
         expiry=datetime.timedelta(seconds=hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 3)
     )
     mock_map.update({"OK": "no", "blam": "booga"})
     await asyncio.sleep(hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 2)
     assert mock_map == {"OK": "no", "blam": "booga"}
     mock_map.update({"ayanami": "rei", "owo": "awoo"})
     assert mock_map == {"OK": "no", "blam": "booga", "ayanami": "rei", "owo": "awoo"}
     await asyncio.sleep(hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 2)
     mock_map.update({"nyaa": "qt"})
     assert mock_map == {"ayanami": "rei", "owo": "awoo", "nyaa": "qt"}
Пример #5
0
 async def test___delitem___garbage_collection(self):
     mock_map = mapping.MRIMutableMapping(
         expiry=datetime.timedelta(seconds=hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 3)
     )
     mock_map.update({"nyaa": "see", "awwo": "awoo2"})
     await asyncio.sleep(hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 2)
     assert mock_map == {"nyaa": "see", "awwo": "awoo2"}
     mock_map.update({"ayanami": "shinji", "rei": "aww"})
     assert mock_map == {"nyaa": "see", "awwo": "awoo2", "ayanami": "shinji", "rei": "aww"}
     await asyncio.sleep(hikari_test_helpers.REASONABLE_QUICK_RESPONSE_TIME * 2)
     del mock_map["ayanami"]
     assert mock_map == {"rei": "aww"}
Пример #6
0
    def test_copy(self):
        raw_map = {
            "floom": (999999999999999999999999, "buebue"),
            "bash": (999999999999999999999999, "bunny_time"),
        }
        mock_map = mapping.MRIMutableMapping(raw_map, expiry=datetime.timedelta(seconds=4523412))
        result = mock_map.copy()

        assert result is not mock_map
        assert isinstance(result, mapping.MRIMutableMapping)

        # 158 mediation?
        # TODO: fix this properly so the cast isn't needed, if we can find out what went wrong?
        assert dict(result) == {"floom": "buebue", "bash": "bunny_time"}, "got: " + repr(dict(result))
Пример #7
0
 def test___setitem__(self):
     mock_map = mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=100))
     mock_map["blat"] = 42
     assert mock_map == {"blat": 42}
Пример #8
0
 def test___len__(self):
     mock_map = mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=100))
     mock_map.update({"o": "k", "boop": "bop", "k": "o", "awoo": "blam", "rei": "cute", "hikari": "rei"})
     assert len(mock_map) == 6
Пример #9
0
 def test___iter__(self):
     mock_map = mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=100))
     mock_map.update({"o": "k", "k": "o", "awoo": "blam", "hikari": "rei"})
     assert list(mock_map) == ["o", "k", "awoo", "hikari"]
Пример #10
0
    def test___getitem___for_unknown_entry(self):
        mock_map = mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=100))
        mock_map["blam"] = 8

        with pytest.raises(KeyError):
            mock_map["OK"]
Пример #11
0
 def test___getitem___for_valid_entry(self):
     mock_map = mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=100))
     mock_map["OK"] = 42
     mock_map["blam"] = 8
     assert mock_map["OK"] == 42
Пример #12
0
 def test___delitem__(self):
     mock_map = mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=100))
     mock_map.update({"ok": "no", "ayanami": "rei qt"})
     del mock_map["ok"]
     assert mock_map == {"ayanami": "rei qt"}
Пример #13
0
    def test___init___raises_value_error_on_invalid_expiry(self):
        with pytest.raises(ValueError, match="expiry time must be greater than 0 microseconds."):
            mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=0))

        with pytest.raises(ValueError, match="expiry time must be greater than 0 microseconds."):
            mapping.MRIMutableMapping(expiry=datetime.timedelta(seconds=-50))