git.fiddlerwoaroof.com
Browse code

unit testing and refactoring

Ed L authored on 01/06/2011 20:27:16
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+import sys
2
+
3
+def public(f):
4
+  """Use a decorator to avoid retyping function/class names.
5
+
6
+  * Based on an idea by Duncan Booth:
7
+  http://groups.google.com/group/comp.lang.python/msg/11cbb03e09611b8a
8
+  * Improved via a suggestion by Dave Angel:
9
+  http://groups.google.com/group/comp.lang.python/msg/3d400fb22d8a42e1
10
+  """
11
+  all = sys.modules[f.__module__].__dict__.setdefault('__all__', [])
12
+  if f.__name__ not in all:  # Prevent duplicates if run from an IDE.
13
+      all.append(f.__name__)
14
+  return f
15
+
16
+public(public)  # Emulate decorating ourself
17
+