| 1 |
import os |
| 2 |
import py |
| 3 |
from pypy import pypydir |
| 4 |
from pypy.tool.release import package |
| 5 |
from pypy.module.sys.version import CPYTHON_VERSION |
| 6 |
from rpython.tool.udir import udir |
| 7 |
import tarfile, zipfile, sys |
| 8 |
|
| 9 |
class TestPackaging: |
| 10 |
def setup_class(cls): |
| 11 |
|
| 12 |
if sys.platform == 'win32': |
| 13 |
basename = 'pypy3.11-c.exe' |
| 14 |
cls.rename_pypy_c = 'pypy3.11-c' |
| 15 |
cls.exe_name_in_archive = 'pypy3.11-c.exe' |
| 16 |
else: |
| 17 |
basename = 'pypy3.11-c' |
| 18 |
cls.rename_pypy_c = package.POSIX_EXE |
| 19 |
cls.exe_name_in_archive = os.path.join('bin', package.POSIX_EXE) |
| 20 |
cls.pypy_c = py.path.local(pypydir).join('goal', basename) |
| 21 |
|
| 22 |
def test_dir_structure(self, test='test'): |
| 23 |
retval, builddir = package.package( |
| 24 |
'--without-cffi', |
| 25 |
'--archive-name', test, |
| 26 |
'--rename_pypy_c', self.rename_pypy_c, |
| 27 |
_fake=True) |
| 28 |
assert retval == 0 |
| 29 |
prefix = builddir.join(test) |
| 30 |
assert prefix.join(self.exe_name_in_archive).check() |
| 31 |
cpyver = 'pypy%d.%d' % CPYTHON_VERSION[:2] |
| 32 |
if sys.platform == 'win32': |
| 33 |
stdlib = prefix.join('lib',) |
| 34 |
stdpath = 'Lib' |
| 35 |
else: |
| 36 |
stdlib = prefix.join('lib', cpyver) |
| 37 |
stdpath = 'lib/%s' % cpyver |
| 38 |
assert stdlib.join('test').check() |
| 39 |
assert stdlib.join('syslog.py').check() |
| 40 |
assert not stdlib.join('py').check() |
| 41 |
assert not stdlib.join('ctypes_configure').check() |
| 42 |
assert prefix.join('LICENSE').check() |
| 43 |
assert prefix.join('README.rst').check() |
| 44 |
if package.USE_ZIPFILE_MODULE: |
| 45 |
zh = zipfile.ZipFile(str(builddir.join('%s.zip' % test))) |
| 46 |
assert zh.open('%s/%s/syslog.py' % (test, stdpath)) |
| 47 |
else: |
| 48 |
th = tarfile.open(str(builddir.join('%s.tar.bz2' % test))) |
| 49 |
syslog = th.getmember('%s/%s/syslog.py' % (test, stdpath)) |
| 50 |
exe = th.getmember('%s/%s' % (test, self.exe_name_in_archive)) |
| 51 |
assert syslog.mode == 0644 |
| 52 |
assert exe.mode == 0755 |
| 53 |
assert exe.uname == '' |
| 54 |
assert exe.gname == '' |
| 55 |
|
| 56 |
|
| 57 |
if not(sys.platform == 'darwin' or sys.platform.startswith('freebsd')): |
| 58 |
assert exe.uid == 0 |
| 59 |
assert exe.gid == 0 |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
if sys.platform == 'win32': |
| 64 |
includedir = py.path.local(pypydir).dirpath().join('include') |
| 65 |
else: |
| 66 |
includedir = py.path.local(pypydir).dirpath().join('include', cpyver) |
| 67 |
def check_include(name): |
| 68 |
if includedir.join(name).check(file=True): |
| 69 |
if sys.platform == 'win32': |
| 70 |
member = '%s/include/%s' % (test, name) |
| 71 |
else: |
| 72 |
member = '%s/include/%s/%s' % (test, cpyver, name) |
| 73 |
if package.USE_ZIPFILE_MODULE: |
| 74 |
assert zh.open(member) |
| 75 |
else: |
| 76 |
assert th.getmember(member) |
| 77 |
else: |
| 78 |
print 'include file "%s" not found, are we translated?' % includedir.join(name) |
| 79 |
check_include('Python.h') |
| 80 |
check_include('modsupport.h') |
| 81 |
check_include('pypy_decl.h') |
| 82 |
check_include('numpy/arrayobject.h') |
| 83 |
|
| 84 |
def test_options(self, test='testoptions'): |
| 85 |
builddir = udir.ensure("build", dir=True) |
| 86 |
retval, builddir = package.package( |
| 87 |
'--without-cffi', '--builddir', str(builddir), |
| 88 |
'--archive-name', test, |
| 89 |
'--rename_pypy_c', self.rename_pypy_c, |
| 90 |
_fake=True) |
| 91 |
|
| 92 |
def test_with_zipfile_module(self): |
| 93 |
prev = package.USE_ZIPFILE_MODULE |
| 94 |
try: |
| 95 |
package.USE_ZIPFILE_MODULE = True |
| 96 |
self.test_dir_structure(test='testzipfile') |
| 97 |
finally: |
| 98 |
package.USE_ZIPFILE_MODULE = prev |
| 99 |
|
| 100 |
|
| 101 |
def test_fix_permissions(tmpdir): |
| 102 |
if sys.platform == 'win32': |
| 103 |
py.test.skip('needs to be more general for windows') |
| 104 |
def check(f, mode): |
| 105 |
assert f.stat().mode & 0777 == mode |
| 106 |
|
| 107 |
mydir = tmpdir.join('mydir').ensure(dir=True) |
| 108 |
bin = tmpdir.join('bin') .ensure(dir=True) |
| 109 |
file1 = tmpdir.join('file1').ensure(file=True) |
| 110 |
file2 = mydir .join('file2').ensure(file=True) |
| 111 |
pypy = bin .join('pypy3').ensure(file=True) |
| 112 |
|
| 113 |
mydir.chmod(0700) |
| 114 |
bin.chmod(0700) |
| 115 |
file1.chmod(0600) |
| 116 |
file2.chmod(0640) |
| 117 |
pypy.chmod(0700) |
| 118 |
|
| 119 |
package.fix_permissions(tmpdir) |
| 120 |
check(mydir, 0755) |
| 121 |
check(bin, 0755) |
| 122 |
check(file1, 0644) |
| 123 |
check(file2, 0644) |
| 124 |
check(pypy, 0755) |
| 125 |
|
| 126 |
def test_generate_license(): |
| 127 |
py.test.skip('generation of license from platform documentation is disabled') |
| 128 |
from os.path import dirname, abspath, join, exists |
| 129 |
class Options(object): |
| 130 |
pass |
| 131 |
options = Options() |
| 132 |
basedir = dirname(dirname(dirname(dirname(dirname(abspath(__file__)))))) |
| 133 |
options.no_tk = False |
| 134 |
if sys.platform == 'win32': |
| 135 |
for p in [join(basedir, r'..\..\..\local'), |
| 136 |
join(basedir, r'..\local')]: |
| 137 |
if exists(p): |
| 138 |
license_base = p |
| 139 |
break |
| 140 |
else: |
| 141 |
license_base = 'unkown' |
| 142 |
options.license_base = license_base |
| 143 |
else: |
| 144 |
options.license_base = '/usr/share/doc' |
| 145 |
license = package.generate_license(py.path.local(basedir), options) |
| 146 |
assert 'bzip2' in license |
| 147 |
assert 'openssl' in license |
| 148 |
assert 'Tcl' in license |
| 149 |
|