def test_cleanup_filter_open_file(): dist = Distribution() cmd = cleanup.cleanup(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 = cleanup.cleanup(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"), ] class DummySite(object): def listdir(self): return [
def test_mirror_eggs(workspace): pypi = CluePyPIAPI('http://foo') dirs = [ path('a') / 'acme.foo', path('a') / 'acme.bar', path('b') / 'baz', path('q') / 'qux', ] file_root = path(workspace.workspace) target_root = path('/path/to/dest') target_host = "blackmesa" [(file_root / d).makedirs() for d in dirs] for d in dirs: for v in [1.0, 2.0, 3.0]: egg = path(file_root / d / '%s-%0.1f.egg' % (d.basename(), v)) egg.touch() # Disable the egg unpack stage for this test pypi.unpack_eggs = lambda i, j, k: None ssh_start = ['/usr/bin/ssh', 'blackmesa'] rsync_start = ['/usr/bin/rsync', '-av', '--ignore-existing'] @patch_subprocess(get_subprocess_mock('', '', 0)) def do_test_one_pkg(): pypi.mirror_eggs(file_root, target_host, target_root, ['acme.foo'], 1) call_args = [i[0][0] for i in subprocess.Popen.call_args_list] print call_args assert call_args[0] == ssh_start + ['mkdir -p /path/to/dest/af'] assert call_args[1][0:3] == rsync_start assert set(call_args[1][3:6]) == set( [file_root / 'a' / 'acme.foo' / 'acme.foo-1.0.egg', file_root / 'a' / 'acme.foo' / 'acme.foo-2.0.egg', file_root / 'a' / 'acme.foo' / 'acme.foo-3.0.egg']) assert call_args[1][6] == "blackmesa:/path/to/dest/af" @patch_subprocess(get_subprocess_mock('', '', 0)) def do_test_two_pkg(): pypi.mirror_eggs(file_root, target_host, target_root, ['acme.foo', 'qux'], 1) call_args = [i[0][0] for i in subprocess.Popen.call_args_list] # not sure which order they turn up in, it doesnt matter so much assert call_args[0][:2] == ssh_start assert call_args[0][2].split()[:2] == ['mkdir', '-p'] assert set(call_args[0][2].split()[-2:]) == set(['/path/to/dest/q', '/path/to/dest/af']) for call in call_args[1:]: assert call[0:3] == rsync_start letter = call[3].split(file_root + "/")[1][0] assert letter in ('a', 'q') if letter == 'q': assert set(call[3:6]) == set([ file_root / 'q' / 'qux' / 'qux-1.0.egg', file_root / 'q' / 'qux' / 'qux-2.0.egg', file_root / 'q' / 'qux' / 'qux-3.0.egg']) assert call[6] == "blackmesa:/path/to/dest/q" else: assert set(call[3:6]) == set([ file_root / 'a' / 'acme.foo' / 'acme.foo-1.0.egg', file_root / 'a' / 'acme.foo' / 'acme.foo-2.0.egg', file_root / 'a' / 'acme.foo' / 'acme.foo-3.0.egg']) assert call[6] == "blackmesa:/path/to/dest/af" do_test_one_pkg() do_test_two_pkg()