pyqtgraph/tests/util/test_lru_cache.py
Ogi Moore a6971c768d Move and Update test-data repo into pyqtgraph repo
To reduce complexity, and make it easier to add more images and tests,
the images in the `test-data` repository should be merged with the main
repository.  Furthermore, we can remove a lot of the subprocess work in
the image_testing.py file, as we no longer need to have it interact with
git.

The images are not the same.  Images were regenerated with Qt6, and now
have proper big and little endian handling thanks to @pijyoi

Second commit is a slightly modified variant of
2e135ab282d6007b34a3854921be54d0e9efb241 authored by @pijyoi
it is to convert qimages to RGBA8888 for testing.  Image
files were regenerated images for the big/little handling

Fixed issue with bogus test from test_NonUniformImage and generated a
new image
2021-05-31 21:05:00 -07:00

56 lines
1.3 KiB
Python

import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore')
from pyqtgraph.util.lru_cache import LRUCache
def testLRU():
lru = LRUCache(2, 1)
# check twice
checkLru(lru)
checkLru(lru)
def checkLru(lru):
lru[1] = 1
lru[2] = 2
lru[3] = 3
assert len(lru) == 2
assert set([2, 3]) == set(lru.keys())
assert set([2, 3]) == set(lru.values())
lru[2] = 2
assert set([2, 3]) == set(lru.values())
lru[1] = 1
set([2, 1]) == set(lru.values())
#Iterates from the used in the last access to others based on access time.
assert [(2, 2), (1, 1)] == list(lru.items(accessTime=True))
lru[2] = 2
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
del lru[2]
assert [(1, 1), ] == list(lru.items(accessTime=True))
lru[2] = 2
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
_a = lru[1]
assert [(2, 2), (1, 1)] == list(lru.items(accessTime=True))
_a = lru[2]
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
assert lru.get(2) == 2
assert lru.get(3) == None
assert [(1, 1), (2, 2)] == list(lru.items(accessTime=True))
lru.clear()
assert [] == list(lru.items())
if __name__ == '__main__':
testLRU()