[Pytest-commit] commit/pytest: 3 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sun Jun 9 15:07:49 CEST 2013


3 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/2aa2693b68ca/
Changeset:   2aa2693b68ca
User:        embray
Date:        2013-05-29 00:11:12
Summary:     Adds a test for and fixes #112.  If attempting to write to the __pycache__ directory raises a permission error _write_pyc() should just return False to prevent any further write attempts.
Affected #:  2 files

diff -r 5d0b6123d6541ad497cc592d72b9ed50a7c26915 -r 2aa2693b68ca556926e21bb478d4941d3f6ab23f _pytest/assertion/rewrite.py
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -177,6 +177,10 @@
             # This happens when we get a EEXIST in find_module creating the
             # __pycache__ directory and __pycache__ is by some non-dir node.
             return False
+        elif err == errno.EACCES:
+            # The directory is read-only; this can happen for example when
+            # running the tests in a package installed as root
+            return False
         raise
     try:
         fp.write(imp.get_magic())

diff -r 5d0b6123d6541ad497cc592d72b9ed50a7c26915 -r 2aa2693b68ca556926e21bb478d4941d3f6ab23f testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -1,4 +1,5 @@
 import os
+import stat
 import sys
 import zipfile
 import py
@@ -323,6 +324,18 @@
     assert "@py_builtins" in globals()""")
         assert testdir.runpytest().ret == 0
 
+    def test_pycache_is_readonly(self, testdir):
+        cache = testdir.tmpdir.mkdir("__pycache__")
+        old_mode = cache.stat().mode
+        cache.chmod(old_mode ^ stat.S_IWRITE)
+        testdir.makepyfile("""
+def test_rewritten():
+    assert "@py_builtins" in globals()""")
+        try:
+            assert testdir.runpytest().ret == 0
+        finally:
+            cache.chmod(old_mode)
+
     def test_zipfile(self, testdir):
         z = testdir.tmpdir.join("myzip.zip")
         z_fn = str(z)
@@ -346,8 +359,12 @@
 def test_rewritten():
     assert "@py_builtins" in globals()
 """).encode("utf-8"), "wb")
+        old_mode = sub.stat().mode
         sub.chmod(320)
-        assert testdir.runpytest().ret == 0
+        try:
+            assert testdir.runpytest().ret == 0
+        finally:
+            sub.chmod(old_mode)
 
     def test_dont_write_bytecode(self, testdir, monkeypatch):
         testdir.makepyfile("""


https://bitbucket.org/hpk42/pytest/commits/f99690dd59d9/
Changeset:   f99690dd59d9
User:        embray
Date:        2013-06-07 23:30:10
Summary:     reindent a few of the blockquotes in these tests
Affected #:  1 file

diff -r 2aa2693b68ca556926e21bb478d4941d3f6ab23f -r f99690dd59d9cf9b0e63c902a5be9d0ce9f54bfb testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -320,8 +320,8 @@
     def test_pycache_is_a_file(self, testdir):
         testdir.tmpdir.join("__pycache__").write("Hello")
         testdir.makepyfile("""
-def test_rewritten():
-    assert "@py_builtins" in globals()""")
+            def test_rewritten():
+                assert "@py_builtins" in globals()""")
         assert testdir.runpytest().ret == 0
 
     def test_pycache_is_readonly(self, testdir):
@@ -329,8 +329,8 @@
         old_mode = cache.stat().mode
         cache.chmod(old_mode ^ stat.S_IWRITE)
         testdir.makepyfile("""
-def test_rewritten():
-    assert "@py_builtins" in globals()""")
+            def test_rewritten():
+                assert "@py_builtins" in globals()""")
         try:
             assert testdir.runpytest().ret == 0
         finally:
@@ -347,9 +347,9 @@
             f.close()
         z.chmod(256)
         testdir.makepyfile("""
-import sys
-sys.path.append(%r)
-import test_gum.test_lizard""" % (z_fn,))
+            import sys
+            sys.path.append(%r)
+            import test_gum.test_lizard""" % (z_fn,))
         assert testdir.runpytest().ret == 0
 
     def test_readonly(self, testdir):
@@ -358,7 +358,7 @@
         py.builtin._totext("""
 def test_rewritten():
     assert "@py_builtins" in globals()
-""").encode("utf-8"), "wb")
+            """).encode("utf-8"), "wb")
         old_mode = sub.stat().mode
         sub.chmod(320)
         try:
@@ -368,11 +368,11 @@
 
     def test_dont_write_bytecode(self, testdir, monkeypatch):
         testdir.makepyfile("""
-import os
-def test_no_bytecode():
-    assert "__pycache__" in __cached__
-    assert not os.path.exists(__cached__)
-    assert not os.path.exists(os.path.dirname(__cached__))""")
+            import os
+            def test_no_bytecode():
+                assert "__pycache__" in __cached__
+                assert not os.path.exists(__cached__)
+                assert not os.path.exists(os.path.dirname(__cached__))""")
         monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
         assert testdir.runpytest().ret == 0
 


https://bitbucket.org/hpk42/pytest/commits/b7cb68e2408e/
Changeset:   b7cb68e2408e
User:        hpk42
Date:        2013-06-09 15:07:44
Summary:     Merged in embray/pytest (pull request #37)

Adds a test for and fixes #112
Affected #:  2 files

diff -r 8826e5d7f9c59063fcfc97f9e22ba09210aa3957 -r b7cb68e2408e680812186531f7aed23d04b36711 _pytest/assertion/rewrite.py
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -177,6 +177,10 @@
             # This happens when we get a EEXIST in find_module creating the
             # __pycache__ directory and __pycache__ is by some non-dir node.
             return False
+        elif err == errno.EACCES:
+            # The directory is read-only; this can happen for example when
+            # running the tests in a package installed as root
+            return False
         raise
     try:
         fp.write(imp.get_magic())

diff -r 8826e5d7f9c59063fcfc97f9e22ba09210aa3957 -r b7cb68e2408e680812186531f7aed23d04b36711 testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -1,4 +1,5 @@
 import os
+import stat
 import sys
 import zipfile
 import py
@@ -319,10 +320,22 @@
     def test_pycache_is_a_file(self, testdir):
         testdir.tmpdir.join("__pycache__").write("Hello")
         testdir.makepyfile("""
-def test_rewritten():
-    assert "@py_builtins" in globals()""")
+            def test_rewritten():
+                assert "@py_builtins" in globals()""")
         assert testdir.runpytest().ret == 0
 
+    def test_pycache_is_readonly(self, testdir):
+        cache = testdir.tmpdir.mkdir("__pycache__")
+        old_mode = cache.stat().mode
+        cache.chmod(old_mode ^ stat.S_IWRITE)
+        testdir.makepyfile("""
+            def test_rewritten():
+                assert "@py_builtins" in globals()""")
+        try:
+            assert testdir.runpytest().ret == 0
+        finally:
+            cache.chmod(old_mode)
+
     def test_zipfile(self, testdir):
         z = testdir.tmpdir.join("myzip.zip")
         z_fn = str(z)
@@ -334,9 +347,9 @@
             f.close()
         z.chmod(256)
         testdir.makepyfile("""
-import sys
-sys.path.append(%r)
-import test_gum.test_lizard""" % (z_fn,))
+            import sys
+            sys.path.append(%r)
+            import test_gum.test_lizard""" % (z_fn,))
         assert testdir.runpytest().ret == 0
 
     def test_readonly(self, testdir):
@@ -345,17 +358,21 @@
         py.builtin._totext("""
 def test_rewritten():
     assert "@py_builtins" in globals()
-""").encode("utf-8"), "wb")
+            """).encode("utf-8"), "wb")
+        old_mode = sub.stat().mode
         sub.chmod(320)
-        assert testdir.runpytest().ret == 0
+        try:
+            assert testdir.runpytest().ret == 0
+        finally:
+            sub.chmod(old_mode)
 
     def test_dont_write_bytecode(self, testdir, monkeypatch):
         testdir.makepyfile("""
-import os
-def test_no_bytecode():
-    assert "__pycache__" in __cached__
-    assert not os.path.exists(__cached__)
-    assert not os.path.exists(os.path.dirname(__cached__))""")
+            import os
+            def test_no_bytecode():
+                assert "__pycache__" in __cached__
+                assert not os.path.exists(__cached__)
+                assert not os.path.exists(os.path.dirname(__cached__))""")
         monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
         assert testdir.runpytest().ret == 0

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list