From 990c32b02e2f9e9836a4c3748d09171d9de1ca62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Sun, 22 May 2022 14:12:23 +0200 Subject: [PATCH] test loading a PythonScript created on Products.PythonScript 2 Integration test for how scripts are automatically recompiled if needed when loaded pickles. --- MANIFEST.in | 1 + .../PythonScripts/tests/testPythonScript.py | 47 ++++++++++++++++++ .../tests/tscripts/ps_2.13.2.pkl | Bin 0 -> 1159 bytes 3 files changed, 48 insertions(+) create mode 100644 src/Products/PythonScripts/tests/tscripts/ps_2.13.2.pkl diff --git a/MANIFEST.in b/MANIFEST.in index f560c8a..57ad428 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -9,6 +9,7 @@ include tox.ini recursive-include src *.py include buildout4.cfg include src/Products/PythonScripts/www/default_content +recursive-include src *.pkl recursive-include src *.ps recursive-include src *.dtml recursive-include src *.zcml diff --git a/src/Products/PythonScripts/tests/testPythonScript.py b/src/Products/PythonScripts/tests/testPythonScript.py index fba648a..6962aec 100644 --- a/src/Products/PythonScripts/tests/testPythonScript.py +++ b/src/Products/PythonScripts/tests/testPythonScript.py @@ -14,6 +14,7 @@ import contextlib import io import os +import pickle import sys import unittest import warnings @@ -606,3 +607,49 @@ def test_PythonScript_proxyroles_nonmanager(self): # Cleanup noSecurityManager() + + +class PythonScriptPickle(unittest.TestCase): + + @unittest.skipIf( + six.PY3, + 'Pickles from python2 can not be loaded on python3') + def test_load_old_zope_2_pickle_recompiles(self): + with open(os.path.join(HERE, 'tscripts', 'ps_2.13.2.pkl'), 'rb') as f: + script = pickle.load(f) + self.assertIsInstance(script, PythonScript) + + self.assertEqual( + script.document_src(), + '## Script (Python) "test"\n' + '##bind container=container\n' + '##bind context=context\n' + '##bind namespace=\n' + '##bind script=script\n' + '##bind subpath=traverse_subpath\n' + '##parameters=Products_PythonScripts_version=\'2.13.2\'\n' + '##title=\n' + '##\n' + 'return """This is an old script created with\n' + 'Products.PythonScripts version %s\n' + 'and Zope version 2.13.30 (on python 2.7)\n' + '""" % Products_PythonScripts_version\n') + + self.assertEqual(script.__code__.co_argcount, 1) + self.assertEqual( + script.__code__.co_varnames, + ('Products_PythonScripts_version',)) + self.assertEqual(script.func_code.co_argcount, 1) + self.assertEqual( + script.func_code.co_varnames, + ('Products_PythonScripts_version',)) + self.assertEqual(script.__defaults__, ('2.13.2',)) + self.assertEqual(script.func_defaults, ('2.13.2',)) + + container = makerequest(DummyFolder('container')) + container.REQUEST.form = {} + self.assertEqual( + script.__of__(container)(), + 'This is an old script created with\n' + 'Products.PythonScripts version 2.13.2\n' + 'and Zope version 2.13.30 (on python 2.7)\n') diff --git a/src/Products/PythonScripts/tests/tscripts/ps_2.13.2.pkl b/src/Products/PythonScripts/tests/tscripts/ps_2.13.2.pkl new file mode 100644 index 0000000000000000000000000000000000000000..339ad850c31fed6f37296eb1b739ea3b6bf7f668 GIT binary patch literal 1159 zcmcgr%We}f6rDVpwoclHS9uo`D4DQ`pk1&5Bq(B2sj8ZK(~afvxXGZz&b2))l?W?- zgRkTVxSmO>3RPV)nz?g*A7`$Q&q!&e7u>2L;asb8lYHZxKorYEYtmeL*FU`QBclh> zX48LGK@9W3|Q%DJ#Q(?bUlpLO`GD)fu4=WiHw3PDxGJHpLvbsZ zeLq2sj@8Fv!cY!tZ0$7HlBeoaN_$7(wt+h{xXT(`xS@7%Zw8wv^?-#E&|ZD_aGxzN+z0cN z%af__BY4Q#-ija`#TT(htXZ^AxKra(c+485sNo4)zr+=pRu-PJ)qq?swsM!SYL>z? zRu5bPWy^djte7}>&bl|B)Q4`#NEbS6wV