Transition a -> alpha (\u03b1) to test unicode paths
authorW. Trevor King <wking@drexel.edu>
Tue, 20 Jul 2010 19:01:13 +0000 (15:01 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 20 Jul 2010 19:01:13 +0000 (15:01 -0400)
12 files changed:
README
dirtag/__init__.py
test/raw/a/a1.html [deleted file]
test/raw/a/a2.html [deleted file]
test/raw/a/a3.html [deleted file]
test/raw/α/α1.html [new file with mode: 0644]
test/raw/α/α2.html [new file with mode: 0644]
test/raw/α/α3.html [new file with mode: 0644]
test/tag/1/a1.html [deleted symlink]
test/tag/1/α1.html [new symlink]
test/tag/x/a2.html [deleted symlink]
test/tag/x/α2.html [new symlink]

diff --git a/README b/README
index c2fc95a312d522f2ff4f0c0ccd6dead6dab17f47..dfaf778e7df389edc3d4c6daba3dd18d3862d4a8 100644 (file)
--- a/README
+++ b/README
@@ -9,10 +9,10 @@ access tagged categories using the command line or dumb tools.
 For example, with a raw directory like this::
 
     raw
-    |-- a
-    |   |-- a1.html
-    |   |-- a2.html
-    |   `-- a3.html
+    |-- α
+    |   |-- α1.html
+    |   |-- α2.html
+    |   `-- α3.html
     `-- b
         |-- b1.svg
         |-- b2.html
@@ -22,19 +22,19 @@ You could create a tag directory like this::
 
     tag/
     |-- 1
-    |   |-- a1.html -> ../../raw/a/a1.html
+    |   |-- α1.html -> ../../rαw/α/α1.html
     |   `-- b1.svg -> ../../raw/b/b1.svg
     `-- x
-        |-- a2.html -> ../../raw/a/a2.html
+        |-- α2.html -> ../../rαw/α/α2.html
         |-- b3.html -> ../../raw/b/b3.html
         `-- y
             `-- b1.svg -> ../../../raw/b/b1.svg
 
 Corresponding to the following tags::
 
-    a1.html    1
-    a2.html    x
-    a3.html
+    α1.html   1
+    α2.html   x
+    α3.html
     b1.svg     1, x/y
     b2.html    
     b3.html    x
index 045c37cabc04af18f5b52df014e9b32a0eb666c6..f55b88f8e9f586691a6d44eb71810a968c95b780 100644 (file)
@@ -197,23 +197,26 @@ class Tree (list):
 def dir_tree(root_dir):
     """Generate a directory tree.
 
-    >>> t = dir_tree('test/tag')
-    >>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1)])
+    >>> t = dir_tree(u'test/tag')
+    >>> print '\\n'.join(['|'.join(x).encode('unicode escape')
+    ...                   for x in t.traverse(depth=1)])
     1
-    1|a1.html
     1|b1.svg
+    1|\\u03b11.html
     x
     x|y
     x|y|b1.svg
-    x|a2.html
     x|b3.html
-    >>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1, type='files')])
-    1|a1.html
+    x|\\u03b12.html
+    >>> print '\\n'.join(['|'.join(x).encode('unicode escape')
+    ...                   for x in t.traverse(depth=1, type='files')])
     1|b1.svg
+    1|\\u03b11.html
     x|y|b1.svg
-    x|a2.html
     x|b3.html
-    >>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1, type='dirs')])
+    x|\\u03b12.html
+    >>> print '\\n'.join(['|'.join(x).encode('unicode escape')
+    ...                   for x in t.traverse(depth=1, type='dirs')])
     1
     x
     x|y
@@ -237,24 +240,27 @@ def dir_tree(root_dir):
 
 class Dirtag (object):
     """
-    >>> d = Dirtag('test/raw', 'test/tag')
-    >>> print '\\n'.join(['\t'.join([x.type, x.root, '|'.join(x),
-    ...                              ','.join(['/'.join(t) for t in x.tags])])
+    >>> d = Dirtag(u'test/raw', u'test/tag')
+    >>> print '\\n'.join(['\t'.join([
+    ...                      x.type, x.root,
+    ...                      '|'.join(x).encode('unicode escape'),
+    ...                      ','.join(['/'.join(t) for t in x.tags])])
     ...                   for x in d.elements()]
     ...                 )  # doctest: +NORMALIZE_WHITESPACE
-    dir       test/raw      a      
-    file      test/raw      a|a1.html      1
-    file      test/raw      a|a2.html      x
-    file      test/raw      a|a3.html      
     dir       test/raw      b      
     file      test/raw      b|b1.svg      1,x/y
     file      test/raw      b|b2.html      
     file      test/raw      b|b3.html      x
-    >>> print '\\n'.join(['|'.join(x) for x in d.elements(['x'])])
-    x|y
-    x|y|b1.svg
-    x|a2.html
-    x|b3.html
+    dir       test/raw      \\u03b1      
+    file      test/raw      \\u03b1|\\u03b11.html      1
+    file      test/raw      \\u03b1|\\u03b12.html      x
+    file      test/raw      \\u03b1|\\u03b13.html      
+    >>> for x in d.elements(['x']):
+    ...     print repr('|'.join(x).encode('unicode escape'))
+    'x|y'
+    'x|y|b1.svg'
+    'x|b3.html'
+    'x|\\\\u03b12.html'
     >>> print '\\n'.join(['|'.join(x) for x in d.tags()])
     1
     x
@@ -264,16 +270,17 @@ class Dirtag (object):
     >>> print '\\n'.join(['|'.join(x) for x in d.tags(['b', 'b1.svg'])])
     1
     x|y
-    >>> print d.tag_path(['a', 'a3.html'], ['x', 'y'])
-    test/tag/x/y/a3.html
+    >>> d.tag_path(['a', u'\\u03b13.html'],
+    ...            ['x', 'y']).encode('unicode escape')
+    'test/tag/x/y/\\\\u03b13.html'
     >>> os.listdir('test/tag/x/y')
     ['b1.svg']
-    >>> d.add_tag(['a', 'a3.html'], ['x', 'y'])
-    >>> sorted(os.listdir('test/tag/x/y'))
-    ['a3.html', 'b1.svg']
-    >>> print 'Z'+os.path.realpath('test/tag/x/y/a3.html') # doctest: +ELLIPSIS
-    Z.../test/raw/a/a3.html
-    >>> d.remove_tag(['a', 'a3.html'], ['x', 'y'])
+    >>> d.add_tag([u'\\u03b1', u'\\u03b13.html'], ['x', 'y'])
+    >>> sorted(os.listdir(u'test/tag/x/y'))
+    [u'b1.svg', u'\\u03b13.html']
+    >>> 'Z'+os.path.realpath(u'test/tag/x/y/\u03b13.html').encode('unicode escape') # doctest: +ELLIPSIS
+    'Z.../test/raw/\\\\u03b1/\\\\u03b13.html'
+    >>> d.remove_tag([u'\\u03b1', u'\\u03b13.html'], ['x', 'y'])
     >>> os.listdir('test/tag/x/y')
     ['b1.svg']
     """
@@ -348,5 +355,11 @@ class Dirtag (object):
 
 
 if __name__ == '__main__':
+    # Uncomment the following lines if you're having problems with
+    # UTF-8 in your docstrings.
+    #import sys
+    #reload(sys)
+    #sys.setdefaultencoding('utf-8')
+
     import doctest
     doctest.testmod()
diff --git a/test/raw/a/a1.html b/test/raw/a/a1.html
deleted file mode 100644 (file)
index 7bb4bc6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<html><head/><body><h1>a1.html</h1></body></html>
diff --git a/test/raw/a/a2.html b/test/raw/a/a2.html
deleted file mode 100644 (file)
index 3172739..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<html><head/><body><h1>a2.html</h1></body></html>
diff --git a/test/raw/a/a3.html b/test/raw/a/a3.html
deleted file mode 100644 (file)
index 010e71c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<html><head/><body><h1>a3.html</h1></body></html>
diff --git a/test/raw/α/α1.html b/test/raw/α/α1.html
new file mode 100644 (file)
index 0000000..be67402
--- /dev/null
@@ -0,0 +1 @@
+<html><head/><body><h1>α1.html</h1></body></html>
diff --git a/test/raw/α/α2.html b/test/raw/α/α2.html
new file mode 100644 (file)
index 0000000..d574c08
--- /dev/null
@@ -0,0 +1 @@
+<html><head/><body><h1>α2.html</h1></body></html>
diff --git a/test/raw/α/α3.html b/test/raw/α/α3.html
new file mode 100644 (file)
index 0000000..4ebec45
--- /dev/null
@@ -0,0 +1 @@
+<html><head/><body><h1>α3.html</h1></body></html>
diff --git a/test/tag/1/a1.html b/test/tag/1/a1.html
deleted file mode 120000 (symlink)
index 56821b4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../raw/a/a1.html
\ No newline at end of file
diff --git a/test/tag/1/α1.html b/test/tag/1/α1.html
new file mode 120000 (symlink)
index 0000000..a012737
--- /dev/null
@@ -0,0 +1 @@
+../../raw/α/α1.html
\ No newline at end of file
diff --git a/test/tag/x/a2.html b/test/tag/x/a2.html
deleted file mode 120000 (symlink)
index 19bf565..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../raw/a/a2.html
\ No newline at end of file
diff --git a/test/tag/x/α2.html b/test/tag/x/α2.html
new file mode 120000 (symlink)
index 0000000..e54070d
--- /dev/null
@@ -0,0 +1 @@
+../../raw/α/α2.html
\ No newline at end of file