def test_package_hash_cache(mock_package): filesize, filehash = mock_package path = Path('/tmp/abc123/foo-0.1-cp34-noabi-any.whl') pkg = builder.PiWheelsPackage(path) assert pkg.filehash == filehash # Second retrieval is cached assert pkg.filehash == filehash
def test_package_transfer(mock_archive, mock_package, transfer_thread): filesize, filehash = mock_package path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert transfer_thread.recv_multipart() == [b'HELLO', b'1'] transfer_thread.send_multipart([b'FETCH', b'0', str(filesize).encode('ascii')]) assert transfer_thread.recv_multipart() == [b'CHUNK', b'0', mock_archive] transfer_thread.send_multipart([b'DONE'])
def test_package_open(mock_package): path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) with pkg.open() as f: with zipfile.ZipFile(f) as arc: assert len(arc.namelist()) == 4 assert 'foo-0.1.dist-info/METADATA' in arc.namelist() assert 'foo/foo.cpython-34m-linux_armv7l-linux-gnu.so' in arc.namelist() assert 'foo/__init__.py' in arc.namelist()
def test_package_dependencies_failed(mock_package, tmpdir): with mock.patch('tempfile.TemporaryDirectory') as tmpdir_mock, \ mock.patch('piwheels.slave.builder.Popen') as popen_mock, \ mock.patch('piwheels.slave.builder.apt') as apt_mock: tmpdir_mock().__enter__.return_value = str(tmpdir) popen_mock().communicate.side_effect = [ TimeoutExpired('ldd', 10), (b"", b"")] path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert pkg.dependencies == {}
def test_package_dependencies_missing(mock_package, tmpdir): with mock.patch('tempfile.TemporaryDirectory') as tmpdir_mock, \ mock.patch('piwheels.slave.builder.Popen') as popen_mock, \ mock.patch('piwheels.slave.builder.Path.resolve', side_effect=FileNotFoundError()), \ mock.patch('piwheels.slave.builder.apt') as apt_mock: tmpdir_mock().__enter__.return_value = str(tmpdir) popen_mock().communicate.return_value = ( b"libopenblas.so.0 => /usr/lib/libopenblas.so.0 (0x00007f7117fd4000)", b"") popen_mock().returncode = 0 path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert pkg.dependencies == {}
def transfer_thread(request, zmq_context, mock_systemd, mock_package): with zmq_context.socket(transport.DEALER) as server_sock, \ zmq_context.socket(transport.DEALER) as client_sock: server_sock.bind('inproc://test-transfer') client_sock.connect('inproc://test-transfer') filesize, filehash = mock_package path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) client_thread = Thread(target=pkg.transfer, args=(client_sock, 1)) client_thread.start() yield server_sock client_thread.join(10) assert not client_thread.is_alive()
def test_package_noabi(mock_package): filesize, filehash = mock_package path = Path('/tmp/abc123/foo-0.1-cp34-noabi-any.whl') pkg = builder.PiWheelsPackage(path) assert pkg.filename == 'foo-0.1-cp34-noabi-any.whl' assert pkg.filesize == filesize assert pkg.filehash == filehash assert pkg.package_tag == 'foo' assert pkg.package_version_tag == '0.1' assert pkg.platform_tag == 'any' assert pkg.abi_tag == 'none' assert pkg.py_version_tag == 'cp34' assert pkg.build_tag is None
def test_package_init(mock_package): filesize, filehash = mock_package path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert pkg.filename == 'foo-0.1-cp34-cp34m-linux_armv7l.whl' assert pkg.filesize == filesize assert pkg.filehash == filehash assert pkg.package_tag == 'foo' assert pkg.package_version_tag == '0.1' assert pkg.platform_tag == 'linux_armv7l' assert pkg.abi_tag == 'cp34m' assert pkg.py_version_tag == 'cp34' assert pkg.build_tag is None
def test_package_transfer_nonsense(mock_archive, mock_package, transfer_thread): filesize, filehash = mock_package path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert transfer_thread.recv_multipart() == [b'HELLO', b'1'] transfer_thread.send_multipart([b'FOO', b'BAR']) # Continue with the transfer normally; the anomalous message should be # ignored and the protocol should continue transfer_thread.send_multipart([b'FETCH', b'0', b'4096']) transfer_thread.send_multipart([b'FETCH', b'4096', str(filesize - 4096).encode('ascii')]) chunk1 = transfer_thread.recv_multipart() chunk2 = transfer_thread.recv_multipart() assert chunk1 == [b'CHUNK', b'0', mock_archive[:4096]] assert chunk2 == [b'CHUNK', b'4096', mock_archive[4096:]] transfer_thread.send_multipart([b'DONE'])
def test_package_dependencies(mock_package, tmpdir): with mock.patch('tempfile.TemporaryDirectory') as tmpdir_mock, \ mock.patch('piwheels.slave.builder.Popen') as popen_mock, \ mock.patch('piwheels.slave.builder.Path.resolve', lambda self: self), \ mock.patch('piwheels.slave.builder.apt') as apt_mock: tmpdir_mock().__enter__.return_value = str(tmpdir) popen_mock().communicate.return_value = (b"""\ linux-vdso.so.1 => (0x00007ffd48669000) libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f711a958000) libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x00007f711a64f000) libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x00007f711a432000) libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x00007f711a068000) /lib64/ld-linux-x86-64.so.2 (0x00007f711af48000) libopenblas.so.0 => /usr/lib/libopenblas.so.0 (0x00007f7117fd4000) libgfortran.so.3 => /usr/lib/arm-linux-gnueabihf/libgfortran.so.3 (0x00007f7117ca9000) libquadmath.so.0 => /usr/lib/arm-linux-gnueabihf/libquadmath.so.0 (0x00007f7117a6a000) libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x00007f7117854000) """, b"") popen_mock().returncode = 0 def pkg(name, files): m = mock.Mock() m.name = name m.installed = True m.installed_files = files return m apt_mock.cache.Cache.return_value = [ pkg('libc6', [ '/lib/arm-linux-gnueabihf/libc.so.6', '/lib/arm-linux-gnueabihf/libm.so.6', '/lib/arm-linux-gnueabihf/libpthread.so.0', ]), pkg('libopenblas-base', [ '/usr/lib/libblas.so.3', '/usr/lib/libopenblas.so.0', ]), pkg('libgcc1', ['/lib/arm-linux-gnueabihf/libgcc_s.so.1']), pkg('libgfortran3', ['/usr/lib/arm-linux-gnueabihf/libgfortran.so.3']), ] path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert pkg.dependencies == { ('apt', 'libc6'), ('apt', 'libopenblas-base'), ('apt', 'libgcc1'), ('apt', 'libgfortran3'), ('', '/usr/lib/arm-linux-gnueabihf/libquadmath.so.0'), }
def test_package_metadata(mock_package): path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl') pkg = builder.PiWheelsPackage(path) assert pkg.metadata['Metadata-Version'] == '2.0' assert pkg.metadata['Name'] == 'foo' assert pkg.metadata['Version'] == '0.1'