Commits

Ronald Oussoren committed f17dcf5

Ensure py2applet works in 3.x, with minimal testcase.

Comments (0)

Files changed (3)

doc/changelog.rst

 
 Bug fixes:
 
+- py2applet didn't work in python 3.x.
+
 - The ``--alias`` option didn't work when building a plugin
   bundle (issue #10, fix by Virgil Dupras)
 

py2app/script_py2applet.py

         if res == 'n':
             print 'aborted!'
             return
-    f = open('setup.py', 'wb')
+    f = open('setup.py', 'w')
     tvars = tuple(map(pprint.pformat, (scripts, data_files, options)))
     f.write(SETUP_TEMPLATE % tvars)
     f.flush()

py2app_tests/test_py2applet.py

+import unittest
+import subprocess
+import os, shutil, sys
+from py2app import script_py2applet
+
+
+class TestPy2Applet (unittest.TestCase):
+    def setUp(self):
+        self.testdir = 'test.dir'
+        os.mkdir(self.testdir)
+
+    def tearDown(self):
+        shutil.rmtree(self.testdir)
+
+    def run_py2applet(self, *args):
+        scriptfn = script_py2applet.__file__
+        if scriptfn.endswith('.pyc'):
+            scriptfn = fn[:-1]
+            
+        p = subprocess.Popen([
+            sys.executable, scriptfn ] + list(args),
+            cwd = self.testdir,
+            stdout = subprocess.PIPE,
+            stderr = subprocess.STDOUT,
+            stdin = subprocess.PIPE)
+        p.stdin.write('y\n'.encode('ascii'))
+        data = p.communicate()[0]
+
+        xit = p.wait()
+        if xit != 0:
+            sys.stdout.write(data)
+            self.fail("Running py2applet %s failed"%(" ".join(args),))
+
+
+    def test_generate_setup(self):
+        self.run_py2applet('--make-setup', 'foo.py')
+
+        setupfn = os.path.join(self.testdir, 'setup.py')
+        self.assertTrue(os.path.exists(setupfn))
+        fp = open(setupfn, 'r')
+        contents = fp.read()
+        fp.close()
+
+        self.assertTrue("APP = ['foo.py']" in contents)
+
+
+if __name__ == "__main__":
+    unittest.main()
+
+
+