Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GigantPro committed Jul 19, 2023
1 parent 4b1394e commit ae57de6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion frozenclass/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
class CacheController:
"""The main class of the cache logic. Includes all caches logic"""
def cache(*, ttl: time | None = time(minute=10)) -> Callable: # ( TTL_end, result )
"""Function-decorate for runtime caching. The cache can either be overwritten or remain until the program terminates.
"""Function-decorate for runtime caching.
The cache can either be overwritten or remain until the program terminates.
:param ttl: Time-To-Live of cached valume, defaults to time(minute=10)
:type ttl: time | None, optional
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ disable = [
"E0401",
"W1401",
"W0212",
"C0103"
"C0103",
"E0211"
]
32 changes: 16 additions & 16 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,63 @@

def test_cache_with_time():
b = 1

@CacheController.cache(ttl=time(second=1))
def test_cache(a):
def test_cache():
return b

assert test_cache(1) == 1
assert test_cache() == 1

b = 2
assert test_cache(1) == 1
assert test_cache() == 1

sleep(1)
assert test_cache(1) == 2
assert test_cache() == 2


def test_cache_without_time():
b = 1

@CacheController.cache(ttl=None)
def test_cache(a):
def test_cache():
return b

assert test_cache(1) == 1
assert test_cache() == 1

b = 2
assert test_cache(1) == 1
assert test_cache() == 1

sleep(1)
assert test_cache(1) == 1
assert test_cache() == 1

def test_speed():
base = sqlite3.connect('test_saves/test.db')
cur = base.cursor()

base.execute('CREATE TABLE IF NOT EXISTS test (number PRIMARY KEY, value)')
try:
[cur.execute(f'INSERT INTO test VALUES (?, ?)', (i, i ** 2)) for i in range(1000)]
except:
[cur.execute('INSERT INTO test VALUES (?, ?)', (i, i ** 2)) for i in range(1000)]
except: # pylint: disable=bare-except
pass
base.commit()

@CacheController.cache(ttl=time(second=1))
def test_cache(cur):
return cur.execute('SELECT * FROM test').fetchall()

def test_cache_without_lib(cur):
def test_cache_without_lib(cur): # pylint: disable=possibly-unused-variable
return cur.execute('SELECT * FROM test').fetchall()

assert (timeit('test_cache(cur)', globals=locals(), number=1000) / 1000) < .00001
assert(timeit('test_cache(cur)', globals=locals(), number=1000) / 1000) < \
(timeit('test_cache_without_lib(cur)', globals=locals(), number=1000) / 1000)


@CacheController.cache(ttl=None)
def test_cache(cur):
def test_cache(cur): # pylint: disable=function-redefined
return cur.execute('SELECT * FROM test').fetchall()

def test_cache_without_lib(cur):
def test_cache_without_lib(cur): # pylint: disable=function-redefined
return cur.execute('SELECT * FROM test').fetchall()

assert (timeit('test_cache(cur)', globals=locals(), number=1000) / 1000) < .00001
Expand Down

0 comments on commit ae57de6

Please sign in to comment.