[pypy-commit] pypy pytest: make winreg tests importable and skipping on unix, use setup_module as well
RonnyPfannschmidt
noreply at buildbot.pypy.org
Fri Feb 8 10:28:55 CET 2013
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: pytest
Changeset: r60965:ec2f3369976c
Date: 2013-02-08 10:26 +0100
http://bitbucket.org/pypy/pypy/changeset/ec2f3369976c/
Log: make winreg tests importable and skipping on unix, use setup_module
as well
diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py
--- a/pypy/module/_winreg/interp_winreg.py
+++ b/pypy/module/_winreg/interp_winreg.py
@@ -2,7 +2,7 @@
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.error import OperationError, wrap_windowserror
+from pypy.interpreter.error import OperationError, wrap_oserror2
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib import rwinreg, rwin32
from rpython.rlib.rarithmetic import r_uint, intmask
@@ -691,7 +691,10 @@
try:
return space.wrap(rwinreg.ExpandEnvironmentStrings(source))
except WindowsError, e:
- raise wrap_windowserror(space, e)
+ # use it instead of wrap_windowserror
+ # since it delegates directly to it but is importable on all platforms
+ # needed for avoiding test failure on unix
+ raise wrap_oserror2(space, e)
def DisableReflectionKey(space, w_key):
"""Disables registry reflection for 32-bit processes running on a 64-bit
diff --git a/pypy/module/_winreg/test/test_winreg.py b/pypy/module/_winreg/test/test_winreg.py
--- a/pypy/module/_winreg/test/test_winreg.py
+++ b/pypy/module/_winreg/test/test_winreg.py
@@ -1,22 +1,24 @@
from rpython.tool.udir import udir
import os, sys, py
+pytestmark = py.test.mark.skipif('sys.platform != "win32"', reason='_winreg is a win32 module')
-if sys.platform != 'win32':
- py.test.skip("_winreg is a win32 module")
+canSaveKey = None
-try:
- # To call SaveKey, the process must have Backup Privileges
- import win32api
- import win32security
- priv_flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
- hToken = win32security.OpenProcessToken (win32api.GetCurrentProcess (), priv_flags)
- privilege_id = win32security.LookupPrivilegeValue (None, "SeBackupPrivilege")
- win32security.AdjustTokenPrivileges (hToken, 0, [(privilege_id, win32security.SE_PRIVILEGE_ENABLED)])
-except:
- canSaveKey = False
-else:
- canSaveKey = True
+
+def setup_module(mod):
+ try:
+ # To call SaveKey, the process must have Backup Privileges
+ import win32api
+ import win32security
+ priv_flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
+ hToken = win32security.OpenProcessToken (win32api.GetCurrentProcess (), priv_flags)
+ privilege_id = win32security.LookupPrivilegeValue (None, "SeBackupPrivilege")
+ win32security.AdjustTokenPrivileges (hToken, 0, [(privilege_id, win32security.SE_PRIVILEGE_ENABLED)])
+ except:
+ mod.canSaveKey = False
+ else:
+ mod.canSaveKey = True
class AppTestHKey:
spaceconfig = dict(usemodules=('_winreg',))
@@ -36,6 +38,7 @@
cls.test_key_name = "SOFTWARE\\Pypy Registry Test Key - Delete Me"
cls.w_root_key = space.wrap(cls.root_key)
cls.w_test_key_name = space.wrap(cls.test_key_name)
+ assert canSaveKey is not None
cls.w_canSaveKey = space.wrap(canSaveKey)
cls.w_tmpfilename = space.wrap(str(udir.join('winreg-temp')))
More information about the pypy-commit
mailing list