def testModules(self): self.registry.newModule("foo", foo_src) # quux has a copy of foo.x self.registry.newModule("quux", quux_src) # bar has a reference to foo self.registry.newModule("bar", "import foo") # baz has reference to f and copy of x, # remember the the global x in f is looked up in foo self.registry.newModule("baz", "from foo import *") import foo, bar, baz, quux self.assert_(foo._p_oid is None) transaction.commit() self.assert_(foo._p_oid) self.assert_(bar._p_oid) self.assert_(baz._p_oid) self.assert_(quux._p_oid) self.assertEqual(foo.f(4), 5) self.assertEqual(bar.foo.f(4), 5) self.assertEqual(baz.f(4), 5) self.assertEqual(quux.f(4), 5) self.assert_(foo.f is bar.foo.f) self.assert_(foo.f is baz.f) foo.x = 42 self.assertEqual(quux.f(4), 5) transaction.commit() self.assertEqual(quux.f(4), 5) foo._p_deactivate() # foo is deactivated, which means its dict is empty when f() # is activated, how do we guarantee that foo is also # activated? self.assertEqual(baz.f(4), 46) self.assertEqual(bar.foo.f(4), 46) self.assertEqual(foo.f(4), 46) self.useNewConnection()
def test_upload_file_pyc(c, s, w): with tmpfile() as dirname: os.mkdir(dirname) with open(os.path.join(dirname, "foo.py"), mode="w") as f: f.write("def f():\n return 123") sys.path.append(dirname) try: import foo assert foo.f() == 123 pyc = importlib.util.cache_from_source( os.path.join(dirname, "foo.py")) assert os.path.exists(pyc) yield c.upload_file(pyc) def g(): import foo return foo.x future = c.submit(g) result = yield future assert result == 123 finally: sys.path.remove(dirname)
def test_upload_file_pyc(c, s, w): with tmpfile() as dirname: os.mkdir(dirname) with open(os.path.join(dirname, 'foo.py'), mode='w') as f: f.write('def f():\n return 123') sys.path.append(dirname) try: import foo assert foo.f() == 123 pyc = cache_from_source(os.path.join(dirname, 'foo.py')) assert os.path.exists(pyc) yield c.upload_file(pyc) def g(): import foo return foo.x future = c.submit(g) result = yield future assert result == 123 finally: sys.path.remove(dirname)
# Python 3.6's changes for calling functions. # See https://github.com/rocky/python-decompyle3/issues/58 # CALL_FUNCTION_EX takes 2 to 3 arguments on the stack: # * the function, # * the tuple of positional arguments, and optionally # * the dict of keyword arguments if bit 0 of oparg is 1. from foo import f, dialect, args, kwds, reader f(*[]) # From Python 3.6 csv.py # (f, dialect) are positional arg tuples, *args, is by itself, i.e. # no tuple. x = reader(f, dialect, *args, **kwds) # From 3.6 functools.py # Below there is a load_closure instruction added def cmp_to_key(mycmp): class K(object): def __ge__(): return mycmp() return # In this situation though, there is no load_closure def cmp2_to_key(mycmp): class K2(object): def __ge__():