Permalink
Browse files

Merge branch 'master' of http://github.com/JoshRosen/hyde into mergeb…

…ranch
  • Loading branch information...
2 parents 91743aa + 65e7ace commit 1cf9d0a87c66da68f1108c8b24b2561f19da25e1 @timo timo committed Aug 5, 2010
Showing with 73 additions and 9 deletions.
  1. +17 −9 hydeengine/path_util.py
  2. +56 −0 tests/test_path_util.py
View
@@ -1,24 +1,32 @@
import os
class PathUtil:
- @staticmethod
+ @staticmethod
def filter_hidden_inplace(item_list):
+ """
+ Given a list of filenames, removes filenames for invisible files (whose
+ names begin with dots) or files whose names end in tildes '~'.
+ Does not remove files with the filname '.htaccess'.
+ The list is modified in-place; this function has no return value.
+ """
- if(not len(item_list)):
+ if not item_list:
return
-
+
wanted = filter(
- lambda item:
- not ((item.startswith('.') and item != ".htaccess") or item.endswith('~')), item_list)
-
+ lambda item:
+ not ((item.startswith('.') and item != ".htaccess")
+ or item.endswith('~')),
+ item_list)
+
count = len(item_list)
good_item_count = len(wanted)
- if(count == good_item_count):
+ if count == good_item_count:
return
-
+
item_list[:good_item_count] = wanted
- for i in range(good_item_count, count):
+ for _ in range(good_item_count, count):
item_list.pop()
@staticmethod
View
@@ -0,0 +1,56 @@
+"""
+
+uses py.test
+
+sudo easy_install py
+
+http://codespeak.net/py/dist/test.html
+
+"""
+
+from hydeengine.path_util import PathUtil
+
+
+def test_filter_hidden_inplace():
+ # Empty lists are not modified.
+ empty_item_list = []
+ PathUtil.filter_hidden_inplace(empty_item_list)
+ assert empty_item_list == []
+
+ # .htacess is not filtered.
+ htaccess_list = [".htaccess"]
+ PathUtil.filter_hidden_inplace(htaccess_list)
+ assert htaccess_list == [".htaccess"]
+
+ # Invisible files and filenames ending in tildes are filtered.
+ item_list = [".htaccess", 'a.html', '.a.html', 'd.html~', 'b/c.html']
+ PathUtil.filter_hidden_inplace(item_list)
+ assert item_list == [".htaccess", 'a.html', 'b/c.html']
+
+
+def test_get_path_fragment():
+ fragment = PathUtil.get_path_fragment(
+ "/root/directory",
+ "/root/directory/sub/directory")
+ assert fragment == "sub/directory/"
+
+
+def test_get_mirror_dir():
+ # Example from get_mirror_folder() docstring in hydeengine/file_system.py
+ directory = "/usr/local/hyde/stuff"
+ source_root = "/usr/local/hyde"
+ mirror_root = "/usr/tmp"
+ mirror_dir = PathUtil.get_mirror_dir(directory, source_root, mirror_root,
+ ignore_root=False)
+ assert mirror_dir == "/usr/tmp/hyde/stuff/"
+ mirror_dir = PathUtil.get_mirror_dir(directory, source_root, mirror_root,
+ ignore_root=True)
+ assert mirror_dir == "/usr/tmp/stuff/"
+ mirror_dir = PathUtil.get_mirror_dir(source_root, source_root, mirror_root,
+ ignore_root=True)
+ assert mirror_dir == mirror_root
+
+
+# TODO: I haven't written any tests for mirror_dir_tree() because it doesn't
+# appear to be used anywhere and because it catches all exceptions without
+# handling them.

0 comments on commit 1cf9d0a

Please sign in to comment.