make doctests work
authorAlexander Solovyov <alexander@solovyov.net>
Wed, 05 Jan 2011 20:17:20 +0100
changeset 157 398576a5d0c5
parent 156 aa103491ab43
child 158 c3ab9c848675
make doctests work previously they would fail because sys.stdout object was captured by function write() much earlier than doctest had any possibility to monkey patch it
opster.py
--- a/opster.py	Wed Dec 29 10:51:26 2010 +0100
+++ b/opster.py	Wed Jan 05 20:17:20 2011 +0100
@@ -18,7 +18,8 @@
 except locale.Error:
     ENCODING = 'UTF-8'
 
-def write(text, out=sys.stdout):
+def write(text, out=None):
+    out = out or sys.stdout
     if isinstance(text, unicode):
         return out.write(text.encode(ENCODING))
     out.write(text)
@@ -242,7 +243,6 @@
      -p --port       port to listen on (default: 8000)
      -d --daemonize  daemonize process
         --pid-file   name of file to write process ID to
-    <BLANKLINE>
     '''
     write(usage + '\n')
     doc = func.__doc__ or '(no help text available)'
@@ -644,3 +644,7 @@
 
 class Abort(OpsterError):
     'Processing error, abort execution'
+
+if __name__ == '__main__':
+    import doctest
+    doctest.testmod()