예제 #1
0
def test_package_hash_cache(mock_package):
    filesize, filehash = mock_package
    path = Path('/tmp/abc123/foo-0.1-cp34-noabi-any.whl')
    pkg = builder.Wheel(path)
    assert pkg.filehash == filehash
    # Second retrieval is cached
    assert pkg.filehash == filehash
예제 #2
0
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.Wheel(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'])
예제 #3
0
def test_package_open(mock_package):
    path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl')
    pkg = builder.Wheel(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()
예제 #4
0
def test_package_noabi(mock_package):
    filesize, filehash = mock_package
    path = Path('/tmp/abc123/foo-0.1-cp34-noabi-any.whl')
    pkg = builder.Wheel(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
예제 #5
0
def test_package_init(mock_package):
    filesize, filehash = mock_package
    path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl')
    pkg = builder.Wheel(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
예제 #6
0
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.Wheel(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()
예제 #7
0
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.Wheel(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'])
예제 #8
0
def test_package_bad_metadata(bad_package):
    path = Path('/tmp/abc123/foo-0.1-cp34-cp34m-linux_armv7l.whl')
    with pytest.raises(builder.BadWheel):
        builder.Wheel(path)
예제 #9
0
def test_package_metadata_canon(mock_package):
    path = Path('/tmp/abc123/Foo-0.1-cp34-cp34m-linux_armv7l.whl')
    pkg = builder.Wheel(path)
    assert pkg.metadata['Metadata-Version'] == '2.0'
    assert pkg.metadata['Name'] == 'foo'
    assert pkg.metadata['Version'] == '0.1'
예제 #10
0
def test_package_metadata_wrong_name(mock_package):
    path = Path('/tmp/abc123/Foo_Bar-0.1-cp34-cp34m-linux_armv7l.whl')
    pkg = builder.Wheel(path)
    with pytest.raises(RuntimeError):
        pkg.metadata