Skip to content

Commit

Permalink
Oops, add test to make sure python requires don't work by default
Browse files Browse the repository at this point in the history
  • Loading branch information
lukegb committed Jan 15, 2016
1 parent d24b1bd commit 5cd0ecb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dukpy/evaljs.py
Expand Up @@ -37,7 +37,7 @@ def __init__(self, search_paths, enable_python=False):
super(RequirableContext, self).__init__()
self.search_paths = search_paths
self.evaljs("Duktape.modSearch = dukpy.modSearch;", modSearch=self.require)
self.enable_python = True
self.enable_python = enable_python

def require(self, id_, require, exports, module):
# does the module ID begin with 'python/'
Expand All @@ -57,7 +57,7 @@ def require(self, id_, require, exports, module):
# assume this was probably No such file
continue

raise Exception("Unable to load {}".format(id_))
raise ImportError("Unable to load {}".format(id_))

def require_python(self, pyid, require, exports, module):
try:
Expand Down
13 changes: 13 additions & 0 deletions tests/tests_evaljs.py
Expand Up @@ -233,6 +233,19 @@ def test_python_require(self):
c = dukpy.RequirableContext([], enable_python=True)
assert c.evaljs("require('python/testpy').call()") == "Hello from Python!"

def test_python_require_doesnt_work_by_default(self):
import sys, imp
testpy = imp.new_module('testpy')
testpy.call = lambda: 'Hello from Python!'
testpy.__all__ = ['call']
sys.modules['testpy'] = testpy
c = dukpy.RequirableContext([])
try:
c.evaljs("require('python/testpy').call()") == "Hello from Python!"
assert False
except ImportError:
pass


class TestRegressions(object):
def test_pyargs_segfault(self):
Expand Down

0 comments on commit 5cd0ecb

Please sign in to comment.