Skip to content

Commit ce48179

Browse files
committed
readding
1 parent 401c9f1 commit ce48179

File tree

10 files changed

+21
-25
lines changed

10 files changed

+21
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
tests/persistence/temp
2+
13
# Editors
24
.vscode/
35
.idea/

tests/keeps_value/_cachedir/5a314621d3e0e63d1426fad8eb278455_0/func.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/keeps_value/_memoized.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/keeps_value/_memoized_systemp.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/keeps_value/_non_memoized.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

tests/keeps_value/run_me_twice.py renamed to tests/persistence/run_me_in_process.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from pathlib import Path
33
from filememo import memoize
44

5-
cache_path = Path(__file__).parent / "_cachedir"
5+
cache_path = Path(__file__).parent / "temp" / "cachedir"
66

77

88
def increase_value_in_file(basename: str):
9-
file = (Path(__file__).parent / basename)
9+
file = (Path(__file__).parent / "temp" / basename)
10+
file.parent.mkdir(exist_ok=True)
1011
try:
1112
t = file.read_text()
1213
except FileNotFoundError:

tests/test_different_functions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,14 @@ def static(a, b):
5757

5858
@classmethod
5959
@memoize(version=ver)
60-
def clmethod(cls, a, b):
60+
def class_method(cls, a, b):
6161
global class_method_calls
6262
class_method_calls += 1
6363
return a * b
6464

6565

6666
class TestDecorator(unittest.TestCase):
6767

68-
# test caching BETWEEN program runs
69-
7068
def test_calls_count(self):
7169
with TemporaryDirectory() as td:
7270
tempTestDir = Path(td) / "TestDecorator"
@@ -167,8 +165,8 @@ def test_static(self):
167165

168166
def test_class_method(self):
169167
self.assertEqual(class_method_calls, 0)
170-
self.assertEqual(Class.clmethod(2, 3), 6)
171-
self.assertEqual(Class.clmethod(2, 3), 6)
168+
self.assertEqual(Class.class_method(2, 3), 6)
169+
self.assertEqual(Class.class_method(2, 3), 6)
172170
self.assertEqual(class_method_calls, 1)
173171

174172
def test_noargs(self):
@@ -180,7 +178,7 @@ def test_noargs(self):
180178
def test_path_as_path(self):
181179
with TemporaryDirectory() as td:
182180
@memoize(dir_path=Path(td)) # not string
183-
def function(a: int, b: int) -> int:
181+
def function(_: int, __: int) -> int:
184182
pass
185183

186184
function(1, 1)

tests/test_exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import time
66
import unittest
7-
from datetime import timedelta, datetime
8-
from pathlib import Path
7+
from datetime import timedelta
98
from tempfile import TemporaryDirectory
109

1110
from filememo import memoize

tests/test_persistense.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
from pathlib import Path
1010
from subprocess import check_call
1111

12-
from .keeps_value.run_me_twice import cache_path
12+
from .persistence.run_me_in_process import cache_path
13+
14+
output_dir = Path(__file__).parent / "persistence" / "temp"
15+
module = 'tests.persistence.run_me_in_process'
1316

1417

1518
class TestPersist(unittest.TestCase):
@@ -21,7 +24,7 @@ def test_memoized(self):
2124
if cache_path.exists():
2225
shutil.rmtree(cache_path)
2326

24-
f = Path(__file__).parent / "keeps_value" / "_memoized.txt"
27+
f = output_dir / "_memoized.txt"
2528
if f.exists():
2629
os.remove(f)
2730

@@ -31,7 +34,7 @@ def test_memoized(self):
3134
for _ in range(3):
3235
check_call((sys.executable,
3336
'-m',
34-
'tests.keeps_value.run_me_twice',
37+
module,
3538
'memoized'))
3639

3740
self.assertTrue(cache_path.exists())
@@ -44,7 +47,7 @@ def test_non_memoized(self):
4447
if cache_path.exists():
4548
shutil.rmtree(cache_path)
4649

47-
f = Path(__file__).parent / "keeps_value" / "_non_memoized.txt"
50+
f = output_dir / "_non_memoized.txt"
4851
if f.exists():
4952
os.remove(f)
5053

@@ -54,7 +57,7 @@ def test_non_memoized(self):
5457
for _ in range(3):
5558
check_call((sys.executable,
5659
'-m',
57-
'tests.keeps_value.run_me_twice',
60+
module,
5861
'non_memoized'))
5962

6063
self.assertTrue(cache_path.exists())
@@ -65,7 +68,7 @@ def test_systemp(self):
6568
# the values are cached between calls. In other words, it's not
6669
# a new temp directory each time
6770

68-
f = Path(__file__).parent / "keeps_value" / "_memoized_systemp.txt"
71+
f = output_dir / "_memoized_systemp.txt"
6972
if f.exists():
7073
os.remove(f)
7174

@@ -76,11 +79,8 @@ def test_systemp(self):
7679
for _ in range(3):
7780
check_call((sys.executable,
7881
'-m',
79-
'tests.keeps_value.run_me_twice',
82+
module,
8083
'systemp',
81-
str(version)
82-
))
84+
str(version)))
8385

8486
self.assertEqual(f.read_text(), '1')
85-
86-
# self.assertLessEqual(int(f.read_text()), 1)

0 commit comments

Comments
 (0)