Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webcache
Commits
f1d3b121
Commit
f1d3b121
authored
Feb 09, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified to_dir function to create full paths.
parent
7c41d0d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
26 deletions
+24
-26
cache.py
cache.py
+6
-12
tests/test_cache.py
tests/test_cache.py
+18
-14
No files found.
cache.py
View file @
f1d3b121
...
...
@@ -3,7 +3,7 @@ import cPickle as pickle
from
time
import
gmtime
from
datetime
import
datetime
,
timedelta
from
os
import
mkdir
from
os.path
import
getmtime
,
exists
from
os.path
import
getmtime
,
exists
,
dirname
,
realpath
from
hashlib
import
md5
from
copy
import
copy
...
...
@@ -13,16 +13,10 @@ ADMINISTRATION_FILE = 'administration.py'
def
to_dir
(
path
):
"""
Transform a path to a
directory, that can be used as prefix before a
filename.
Transform a path to a
n absolute directory, that can be used as prefix
before a
filename.
"""
if
not
path
:
return
''
if
path
[
-
1
]
!=
'/'
:
return
path
+
'/'
return
path
return
realpath
(
dirname
(
path
))
+
'/'
def
assert_file_exists
(
path
):
...
...
@@ -51,8 +45,8 @@ class Cache:
4. A dictionary containing arguments to the timedelta constructor, that
indicates how long the cache object sould live.
"""
self
.
root
=
to_dir
(
root
)
self
.
cached
=
to_dir
(
cached
)
self
.
root
=
to_dir
(
root
+
'/'
)
self
.
cached
=
to_dir
(
cached
+
'/'
)
self
.
files
=
map
(
lambda
f
:
self
.
root
+
f
,
files
)
self
.
expires
=
expires
...
...
tests/test_cache.py
View file @
f1d3b121
...
...
@@ -7,6 +7,9 @@ from cPickle import dumps
from
cache
import
ADMINISTRATION_FILE
,
assert_file_exists
,
to_dir
,
Cache
d
=
os
.
path
.
realpath
(
''
)
+
'/'
class
TestCache
(
unittest
.
TestCase
):
def
setUp
(
self
):
if
os
.
path
.
exists
(
'baz'
):
...
...
@@ -32,34 +35,35 @@ class TestCache(unittest.TestCase):
self
.
assertRaises
(
IOError
,
assert_file_exists
,
'foobar'
)
def
test_to_dir
(
self
):
self
.
assertEqual
(
to_dir
(
''
),
''
)
self
.
assertEqual
(
to_dir
(
'foo'
),
'foo/'
)
self
.
assertEqual
(
to_dir
(
'foo/'
),
'foo/'
)
self
.
assertEqual
(
to_dir
(
''
),
d
)
self
.
assertEqual
(
to_dir
(
'foo'
),
d
)
self
.
assertEqual
(
to_dir
(
'foo/'
),
d
+
'foo/'
)
self
.
assertEqual
(
to_dir
(
'foo/bar.txt'
),
d
+
'foo/'
)
def
test___init__
(
self
):
self
.
assertTrue
(
hasattr
(
self
.
c
,
'root'
))
self
.
assertEqual
(
self
.
c
.
root
,
'baz/'
)
self
.
assertEqual
(
self
.
c
.
root
,
d
+
'baz/'
)
self
.
assertTrue
(
hasattr
(
self
.
c
,
'files'
))
self
.
assertEqual
(
self
.
c
.
files
,
[
'baz/foo'
,
'baz/bar'
])
self
.
assertEqual
(
self
.
c
.
files
,
[
d
+
'baz/foo'
,
d
+
'baz/bar'
])
self
.
assertTrue
(
hasattr
(
self
.
c
,
'cached'
))
self
.
assertEqual
(
self
.
c
.
cached
,
'cached/'
)
self
.
assertEqual
(
self
.
c
.
cached
,
d
+
'cached/'
)
def
test___init___custom_root
(
self
):
c
=
Cache
(
root
=
'foo'
)
self
.
assertTrue
(
hasattr
(
c
,
'root'
))
self
.
assertEqual
(
c
.
root
,
'foo/'
)
self
.
assertEqual
(
c
.
root
,
d
+
'foo/'
)
def
test___init___custom_cached_dir
(
self
):
c
=
Cache
(
cached
=
'foo'
)
self
.
assertTrue
(
hasattr
(
c
,
'cached'
))
self
.
assertEqual
(
c
.
cached
,
'foo/'
)
self
.
assertEqual
(
c
.
cached
,
d
+
'foo/'
)
def
test___init___non_existant_file
(
self
):
self
.
assertRaises
(
IOError
,
Cache
,
files
=
[
'foo'
])
def
test_add
(
self
):
self
.
c
.
add
(
'baz'
)
self
.
assertIn
(
'baz/baz'
,
self
.
c
.
files
)
self
.
assertIn
(
d
+
'baz/baz'
,
self
.
c
.
files
)
def
test_add_non_relative
(
self
):
self
.
c
.
add
(
'baz'
,
absolute
=
True
)
...
...
@@ -67,16 +71,16 @@ class TestCache(unittest.TestCase):
def
test_remove
(
self
):
self
.
c
.
remove
(
'foo'
)
self
.
assertNotIn
(
'baz/foo'
,
self
.
c
.
files
)
self
.
assertNotIn
(
d
+
'baz/foo'
,
self
.
c
.
files
)
def
test_remove_non_relative
(
self
):
self
.
c
.
remove
(
'baz/foo'
,
absolute
=
True
)
self
.
assertNotIn
(
'baz/foo'
,
self
.
c
.
files
)
self
.
c
.
remove
(
d
+
'baz/foo'
,
absolute
=
True
)
self
.
assertNotIn
(
d
+
'baz/foo'
,
self
.
c
.
files
)
def
test_assert_modification_dates_exist
(
self
):
self
.
c
.
assert_modification_dates_exist
()
self
.
assertIn
(
'baz/foo'
,
self
.
c
.
modified
)
self
.
assertEqual
(
self
.
c
.
modified
[
'baz/foo'
],
self
.
assertIn
(
d
+
'baz/foo'
,
self
.
c
.
modified
)
self
.
assertEqual
(
self
.
c
.
modified
[
d
+
'baz/foo'
],
os
.
path
.
getmtime
(
'baz/foo'
))
modified
=
copy
(
self
.
c
.
modified
)
...
...
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