Example #1
0
def test_pack_to_bytes(tmpdir):
    info = {
        'files': {
            'agents': ['special/agent_test']
        },
        'title': 'Test package',
    }
    tmpdir.join('agents', 'special', 'agent_test').write_binary(b'hello',
                                                                ensure=True)

    data = mkp.pack_to_bytes(info, str(tmpdir))

    bytes_io = io.BytesIO(data)
    archive = tarfile.open(fileobj=bytes_io)

    info_file = archive.extractfile('info').read()
    extracted_info = ast.literal_eval(info_file.decode())
    assert extracted_info['files'] == info['files']
    assert extracted_info['title'] == info['title']
    assert extracted_info['version.packaged'] == 'python-mkp'

    agents_archive_file = archive.extractfile('agents.tar')
    agents_archive = tarfile.open(fileobj=agents_archive_file, mode='r:')
    agent_file = agents_archive.extractfile('special/agent_test')
    assert agent_file.read() == b'hello'
Example #2
0
def test_pack_and_unpack_covers_all_known_directories(tmpdir):
    info = {
        'files': {key: ['test'] for key in DIRECTORIES},
    }
    source = tmpdir.join('source').mkdir()
    dest = tmpdir.join('dest').mkdir()

    for directory in DIRECTORIES:
        source.join(directory, 'test').write_binary(b'Foo', ensure=True)

    package_bytes = mkp.pack_to_bytes(info, str(source))
    package = mkp.load_bytes(package_bytes)
    package.extract_files(str(dest))

    for directory in DIRECTORIES:
        assert dest.join(directory, 'test').exists()
Example #3
0
def test_pack_and_unpack_covers_all_known_directories(tmpdir):
    info = {
        'files': {key: ['test']
                  for key in DIRECTORIES},
    }
    source = tmpdir.join('source').mkdir()
    dest = tmpdir.join('dest').mkdir()

    for directory in DIRECTORIES:
        source.join(directory, 'test').write_binary(b'Foo', ensure=True)

    package_bytes = mkp.pack_to_bytes(info, str(source))
    package = mkp.load_bytes(package_bytes)
    package.extract_files(str(dest))

    for directory in DIRECTORIES:
        assert dest.join(directory, 'test').exists()
Example #4
0
def test_pack_to_bytes(tmpdir):
    info = {
        'files': {'agents': ['special/agent_test']},
        'title': 'Test package',
    }
    tmpdir.join('agents', 'special', 'agent_test').write_binary(b'hello', ensure=True)

    data = mkp.pack_to_bytes(info, str(tmpdir))

    bytes_io = io.BytesIO(data)
    archive = tarfile.open(fileobj=bytes_io)

    info_file = archive.extractfile('info').read()
    extracted_info = ast.literal_eval(info_file.decode())
    assert extracted_info['files'] == info['files']
    assert extracted_info['title'] == info['title']
    assert extracted_info['version.packaged'] == 'python-mkp'

    agents_archive_file = archive.extractfile('agents.tar')
    agents_archive = tarfile.open(fileobj=agents_archive_file, mode='r:')
    agent_file = agents_archive.extractfile('special/agent_test')
    assert agent_file.read() == b'hello'