Skip to content
This repository
Browse code

Fix test failure on webob.static on Pypy

  • Loading branch information...
commit 7491657ad3f6a70c2e27a049e5826ffdbd0cce76 1 parent b282e82
Jonathan Ballet multani authored

Showing 2 changed files with 7 additions and 9 deletions. Show diff stats Hide diff stats

  1. +4 8 tests/test_static.py
  2. +3 1 webob/static.py
12 tests/test_static.py
@@ -79,16 +79,12 @@ def open_oserror(*args, **kwargs):
79 79 raise OSError()
80 80
81 81 app = static.FileApp(self.tempfile)
82   - old_open = __builtins__['open']
83 82
84   - try:
85   - __builtins__['open'] = open_ioerror
86   - self.assertEqual(403, get_response(app).status_int)
  83 + app._open = open_ioerror
  84 + self.assertEqual(403, get_response(app).status_int)
87 85
88   - __builtins__['open'] = open_oserror
89   - self.assertEqual(403, get_response(app).status_int)
90   - finally:
91   - __builtins__['open'] = old_open
  86 + app._open = open_oserror
  87 + self.assertEqual(403, get_response(app).status_int)
92 88
93 89
94 90 class TestFileIter(unittest.TestCase):
4 webob/static.py
@@ -27,6 +27,8 @@ def __init__(self, filename, **kw):
27 27 kw.setdefault('content_encoding', content_encoding)
28 28 kw.setdefault('accept_ranges', 'bytes')
29 29 self.kw = kw
  30 + # Used for testing purpose
  31 + self._open = open
30 32
31 33 @wsgify
32 34 def __call__(self, req):
@@ -40,7 +42,7 @@ def __call__(self, req):
40 42 return exc.HTTPNotFound(comment=msg)
41 43
42 44 try:
43   - file = open(self.filename, 'rb')
  45 + file = self._open(self.filename, 'rb')
44 46 except (IOError, OSError) as e:
45 47 msg = "You are not permitted to view this file (%s)" % e
46 48 return exc.HTTPForbidden(msg)

0 comments on commit 7491657

Please sign in to comment.
Something went wrong with that request. Please try again.