Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
e62f8c18
Commit
e62f8c18
authored
Aug 13, 2009
by
Josh Roesslein
Browse files
Added memcache cache test. All cache tests are passing.
parent
45bb5a15
Changes
3
Hide whitespace changes
Inline
Side-by-side
TODO
View file @
e62f8c18
Stuff that needs to be done...
- finish unit tests
- search API
- streaming tests
- api tests
- caching system
- memcache? database?
+ memory and file caches implemented
- needs docs, tutors, examples, etc
- database based
- reference docuements
- tutorial
- streaming
- commandline client
tests.py
View file @
e62f8c18
...
...
@@ -134,11 +134,11 @@ class TweepyAuthTests(unittest.TestCase):
class
TweepyCacheTests
(
unittest
.
TestCase
):
timeout
=
2.0
memcache_servers
=
[
'127.0.0.1:11211'
]
# must be running for test to pass
def
_run_tests
(
self
):
def
_run_tests
(
self
,
do_cleanup
=
True
):
# test store and get
self
.
cache
.
store
(
'testkey'
,
'testvalue'
)
self
.
assertEqual
(
self
.
cache
.
count
(),
1
,
'Count is wrong'
)
self
.
assertEqual
(
self
.
cache
.
get
(
'testkey'
),
'testvalue'
,
'Stored value does not match retrieved value'
)
# test timeout
...
...
@@ -146,14 +146,18 @@ class TweepyCacheTests(unittest.TestCase):
self
.
assertEqual
(
self
.
cache
.
get
(
'testkey'
),
None
,
'Cache entry should have expired'
)
# test cleanup
self
.
cache
.
store
(
'testkey'
,
'testvalue'
)
sleep
(
self
.
timeout
)
self
.
cache
.
cleanup
()
self
.
assertEqual
(
self
.
cache
.
count
(),
0
,
'Cache cleanup failed'
)
if
do_cleanup
:
self
.
cache
.
store
(
'testkey'
,
'testvalue'
)
sleep
(
self
.
timeout
)
self
.
cache
.
cleanup
()
self
.
assertEqual
(
self
.
cache
.
count
(),
0
,
'Cache cleanup failed'
)
# test count
for
i
in
range
(
0
,
20
):
self
.
cache
.
store
(
'testkey%i'
%
i
,
'testvalue'
)
self
.
assertEqual
(
self
.
cache
.
count
(),
20
,
'Count is wrong'
)
# test flush
for
i
in
range
(
0
,
10
):
self
.
cache
.
store
(
'testkey%i'
%
i
,
'testvalue'
)
self
.
cache
.
flush
()
self
.
assertEqual
(
self
.
cache
.
count
(),
0
,
'Cache failed to flush'
)
...
...
@@ -167,7 +171,10 @@ class TweepyCacheTests(unittest.TestCase):
self
.
_run_tests
()
self
.
cache
.
flush
()
os
.
rmdir
(
'cache_test_dir'
)
def
testmemcache
(
self
):
self
.
cache
=
MemCache
(
self
.
memcache_servers
,
self
.
timeout
)
self
.
_run_tests
(
do_cleanup
=
False
)
if
__name__
==
'__main__'
:
unittest
.
main
()
...
...
tweepy/cache.py
View file @
e62f8c18
...
...
@@ -234,11 +234,13 @@ class MemCache(Cache):
return
value
def
count
(
self
):
# TODO: implement
raise
NotImplementedError
count
=
0
for
sid
,
stats
in
self
.
client
.
get_stats
():
count
+=
int
(
stats
.
get
(
'curr_items'
,
0
))
return
count
def
cleanup
(
self
):
# not implemented for this cache
# not implemented for this cache
since server handles it
return
def
flush
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment