fix user login for windows 3.5
authorAurelien Campeas
Wed, 09 Sep 2009 17:58:47 +0200
branch3.5
changeset 3153 93ce84956679
parent 3152 7ef7c82daf59
child 3154 575a42bce11f
fix user login for windows
common/test/unittest_mail.py
devtools/__init__.py
--- a/common/test/unittest_mail.py	Wed Sep 09 17:58:09 2009 +0200
+++ b/common/test/unittest_mail.py	Wed Sep 09 17:58:47 2009 +0200
@@ -8,7 +8,7 @@
 """
 
 import os
-import pwd
+import sys
 
 from logilab.common.testlib import unittest_main
 from logilab.common.umessage import message_from_string
@@ -22,7 +22,11 @@
     (man 3 getlogin)
     Another solution would be to use $LOGNAME, $USER or $USERNAME
     """
-    return pwd.getpwuid(os.getuid())[0]
+    if sys.platform != 'win32':
+        import pwd
+        return pwd.getpwuid(os.getuid())[0]
+    else:
+        return os.environ.get('USERNAME')
 
 
 class EmailTC(EnvBasedTC):
--- a/devtools/__init__.py	Wed Sep 09 17:58:09 2009 +0200
+++ b/devtools/__init__.py	Wed Sep 09 17:58:47 2009 +0200
@@ -130,7 +130,7 @@
         self.set_option('sender-addr', 'cubicweb-test@logilab.fr')
         try:
             send_to =  '%s@logilab.fr' % os.getlogin()
-        except OSError:
+        except (OSError, AttributeError):
             send_to =  '%s@logilab.fr' % (os.environ.get('USER')
                                           or os.environ.get('USERNAME')
                                           or os.environ.get('LOGNAME'))