Skip to content

Commit 2adb874

Browse files
committed
Split out tests into separate file
1 parent 7dd7eea commit 2adb874

File tree

4 files changed

+58
-52
lines changed

4 files changed

+58
-52
lines changed

.idea/misc.xml

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/pickleshare.iml

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pickleshare.py

-45
Original file line numberDiff line numberDiff line change
@@ -286,51 +286,6 @@ def __repr__(self):
286286
self.__dict__['keydir'],
287287
";".join([Path(k).basename() for k in keys]))
288288

289-
290-
def test():
291-
db = PickleShareDB('~/testpickleshare')
292-
db.clear()
293-
print("Should be empty:",db.items())
294-
db['hello'] = 15
295-
db['aku ankka'] = [1,2,313]
296-
db['paths/nest/ok/keyname'] = [1,(5,46)]
297-
db.hset('hash', 'aku', 12)
298-
db.hset('hash', 'ankka', 313)
299-
print("12 =",db.hget('hash','aku'))
300-
print("313 =",db.hget('hash','ankka'))
301-
print("all hashed",db.hdict('hash'))
302-
print(db.keys())
303-
print(db.keys('paths/nest/ok/k*'))
304-
print(dict(db)) # snapsot of whole db
305-
db.uncache() # frees memory, causes re-reads later
306-
307-
# shorthand for accessing deeply nested files
308-
lnk = db.getlink('myobjects/test')
309-
lnk.foo = 2
310-
lnk.bar = lnk.foo + 5
311-
print(lnk.bar) # 7
312-
313-
def stress():
314-
db = PickleShareDB('~/fsdbtest')
315-
import time,sys
316-
for i in range(1000):
317-
for j in range(1000):
318-
if i % 15 == 0 and i < 200:
319-
if str(j) in db:
320-
del db[str(j)]
321-
continue
322-
323-
if j%33 == 0:
324-
time.sleep(0.02)
325-
326-
db[str(j)] = db.get(str(j), []) + [(i,j,"proc %d" % os.getpid())]
327-
db.hset('hash',j, db.hget('hash',j,15) + 1 )
328-
329-
print(i, end=' ')
330-
sys.stdout.flush()
331-
if i % 10 == 0:
332-
db.uncache()
333-
334289
def main():
335290
import textwrap
336291
usage = textwrap.dedent("""\

test_pickleshare.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from __future__ import print_function
2+
import os
3+
4+
from pickleshare import PickleShareDB
5+
6+
def test_pickleshare(tmpdir):
7+
db = PickleShareDB(tmpdir)
8+
db.clear()
9+
print("Should be empty:",db.items())
10+
assert len(db) == 0
11+
db['hello'] = 15
12+
assert db['hello'] == 15
13+
db['aku ankka'] = [1,2,313]
14+
assert db['aku ankka'] == [1,2,313]
15+
db['paths/nest/ok/keyname'] = [1,(5,46)]
16+
assert db['paths/nest/ok/keyname'] == [1,(5,46)]
17+
18+
db.hset('hash', 'aku', 12)
19+
db.hset('hash', 'ankka', 313)
20+
assert db.hget('hash', 'aku') == 12
21+
assert db.hget('hash', 'ankka') == 313
22+
23+
print("all hashed",db.hdict('hash'))
24+
print(db.keys())
25+
print(db.keys('paths/nest/ok/k*'))
26+
print(dict(db)) # snapsot of whole db
27+
db.uncache() # frees memory, causes re-reads later
28+
29+
# shorthand for accessing deeply nested files
30+
lnk = db.getlink('myobjects/test')
31+
lnk.foo = 2
32+
lnk.bar = lnk.foo + 5
33+
assert lnk.bar == 7
34+
35+
def test_stress(tmpdir):
36+
db = PickleShareDB(tmpdir)
37+
import time,sys
38+
for i in range(100):
39+
for j in range(500):
40+
if i % 15 == 0 and i < 70:
41+
if str(j) in db:
42+
del db[str(j)]
43+
continue
44+
45+
if j%33 == 0:
46+
time.sleep(0.02)
47+
48+
db[str(j)] = db.get(str(j), []) + [(i,j,"proc %d" % os.getpid())]
49+
db.hset('hash',j, db.hget('hash',j,15) + 1 )
50+
51+
print(i, end=' ')
52+
sys.stdout.flush()
53+
if i % 10 == 0:
54+
db.uncache()

0 commit comments

Comments
 (0)