[Python-Dev] Python 2.5.1

Calvin Spealman ironfroggy at gmail.com
Sat Apr 28 14:43:16 CEST 2007

On 4/27/07, Khalid A. Bakr <khabkr at yahoo.com> wrote:
> Okay. It seems I mixed up WindowsError with the
> exception e in my post; at least it is now known that
> e is not a number. The patch is short and is as
> follows:
> Index: Lib/test/test_os.py
> ===================================================================
> --- Lib/test/test_os.py (revision 55014)
> +++ Lib/test/test_os.py (working copy)
> @@ -245,7 +245,8 @@
>              try:
>                  os.stat(r"c:\pagefile.sys")
>              except WindowsError, e:
> -                if e == 2: # file does not exist;
> cannot run test
> +                # file may not exist, or access is
> denied; cannot run test
> +                if e.winerror == 2 or e.winerror ==
> 5:
>                      return
>                  self.fail("Could not stat
> pagefile.sys")

I have a patch myself that creates an open file and uses that as the
test. My reasoning is that pagefile.sys was chosen as a file that
should always exist and be open, so its safe to test against, so we
should just be testing against a fixture, instead. It is here, and if
someone would reference a SF bug report, I'll attach to it, as well.

I should also point out that I got the time errors as well, but with
different incorrect results. However, I can't seem to reproduce it
this morning, but I can say that I did have the test failing for me on
VC yesterday.

Index: test_os.py
--- test_os.py	(revision 54982)
+++ test_os.py	(working copy)
@@ -6,6 +6,7 @@
 import unittest
 import warnings
 import sys
+import tempfile
 from test import test_support

 warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
@@ -241,13 +242,18 @@
             self.assertEquals(os.stat(self.fname).st_mtime, t1)

         def test_1686475(self):
+            fn = tempfile.mktemp()
+            openfile = open(fn, 'w')
             # Verify that an open file can be stat'ed
-                os.stat(r"c:\pagefile.sys")
+                os.stat(fn)
             except WindowsError, e:
                 if e == 2: # file does not exist; cannot run test
                 self.fail("Could not stat pagefile.sys")
+            finally:
+                openfile.close()
+                os.remove(fn)

 from test import mapping_tests

Read my blog! I depend on your acceptance of my opinion! I am interesting!

More information about the Python-Dev mailing list