Example #1
0
def _test_mirror_eggs(dirs, target_pkgs=None):
    pypi = CluePyPIAPI('http://example.com')
    src_root = "/src"
    target_root = '/path/to/dest'
    target_host = "dlonfoobar"

    eggs_by_pkg = dict((p, ['%s-%0.1f.egg' % (p, v) for v in [1.0, 2.0, 3.0]])
                       for d in dirs for p in dirs[d])

    eggs_by_path = dict((os.path.join(src_root,
                                      [d for d in dirs
                                       if p in dirs[d]][0], p), egg)
                        for p, egg in eggs_by_pkg.items())

    # Disable the egg unpack stage for this test
    pypi.unpack_eggs = lambda _i, _j, _k: None

    def walk_mock(_):
        data = [(src_root, dirs.keys(), [])]
        for d in dirs:
            data.append((os.path.join(src_root, d), dirs[d], []))
        return data

    def is_file_mock(f):
        return os.path.basename(f) in eggs_by_path.get(os.path.dirname(f), {})

    @patch_subprocess(get_subprocess_mock('', '', 0))
    def run():
        pypi.mirror_eggs(src_root, target_host, target_root, target_pkgs, 1)
        return subprocess.Popen

    with ExitStack() as stack:
        ec = stack.enter_context
        ec(patch("os.walk", side_effect=walk_mock))
        ec(patch("os.path.isdir", return_value=True))
        ec(patch("os.listdir", side_effect=lambda d: eggs_by_path[d]))
        ec(patch("os.path.isfile", side_effect=is_file_mock))

        return run(), src_root, target_root, target_host, eggs_by_pkg
Example #2
0
def _test_mirror_eggs(dirs, target_pkgs=None):
    pypi = CluePyPIAPI('http://example.com')
    src_root = "/src"
    target_root = '/path/to/dest'
    target_host = "dlonfoobar"

    eggs_by_pkg = dict((p, ['%s-%0.1f.egg' % (p, v) for v in [1.0, 2.0, 3.0]])
                       for d in dirs for p in dirs[d])

    eggs_by_path = dict(
        (os.path.join(src_root, [d for d in dirs if p in dirs[d]][0], p), egg)
        for p, egg in eggs_by_pkg.items())

    # Disable the egg unpack stage for this test
    pypi.unpack_eggs = lambda _i, _j, _k: None

    def walk_mock(_):
        data = [(src_root, dirs.keys(), [])]
        for d in dirs:
            data.append((os.path.join(src_root, d), dirs[d], []))
        return data

    def is_file_mock(f):
        return os.path.basename(f) in eggs_by_path.get(os.path.dirname(f), {})

    @patch_subprocess(get_subprocess_mock('', '', 0))
    def run():
        pypi.mirror_eggs(src_root, target_host, target_root, target_pkgs, 1)
        return subprocess.Popen

    with ExitStack() as stack:
        ec = stack.enter_context
        ec(patch("os.walk", side_effect=walk_mock))
        ec(patch("os.path.isdir", return_value=True))
        ec(patch("os.listdir", side_effect=lambda d: eggs_by_path[d]))
        ec(patch("os.path.isfile", side_effect=is_file_mock))

        return run(), src_root, target_root, target_host, eggs_by_pkg
Example #3
0
def test_cleanup_filter_open_file():
    dist = Distribution()
    cmd = clean.clean(dist)
    cmd.open_files = [('1234', '/path/to/foo.egg')]
    assert not cmd.filter_open_files('foo.egg')



LSOF_OUT = """
12345   foo
67890   bar
"""


@patch_subprocess(get_subprocess_mock(LSOF_OUT, '', 0))
def test_get_open_files():
    dist = Distribution()
    cmd = clean.clean(dist)
    assert cmd.get_open_files() == [['12345', 'foo'], ['67890', 'bar']]


def test_find_victims():
    my_working_set = [
       Pkg('acme.foo', [], location='site-packages/acme.foo.egg'),
       Pkg('acme.bar', [], location='site-packages/acme.bar.egg'),
    ]

    def get_site_packages():
        return ['site-packages/acme.foo.egg',
                'site-packages/acme.bar.egg',
Example #4
0

def test_cleanup_filter_open_file():
    dist = Distribution()
    cmd = clean.clean(dist)
    cmd.open_files = [('1234', '/path/to/foo.egg')]
    assert not cmd.filter_open_files('foo.egg')


LSOF_OUT = """
12345   foo
67890   bar
"""


@patch_subprocess(get_subprocess_mock(LSOF_OUT, '', 0))
def test_get_open_files():
    dist = Distribution()
    cmd = clean.clean(dist)
    assert cmd.get_open_files() == [['12345', 'foo'], ['67890', 'bar']]


def test_find_victims():
    my_working_set = [
        Pkg('acme.foo', [], location='site-packages/acme.foo.egg'),
        Pkg('acme.bar', [], location='site-packages/acme.bar.egg'),
    ]

    def get_site_packages():
        return [
            'site-packages/acme.foo.egg', 'site-packages/acme.bar.egg',