def test_installed(self, tmpdir, cask, debug, verbose, random_prefix, bootstrap): cider = Cider(cask, debug, verbose, cider_dir=str(tmpdir)) cider.read_bootstrap = MagicMock(return_value=bootstrap) key = "casks" if cask else "formulas" installed = bootstrap.get(key, []) random_choice = random.choice(installed) if installed else None for prefix in [None, random_choice, random_prefix]: assert cider.installed(prefix) == [ x for x in installed if not prefix or x.startswith(prefix) ]
def test_missing(self, tmpdir, cask, debug, verbose, installed, brewed): orphans = [] def generate_uses(): uses = {} for formula in brewed: subset = [x for x in installed if x != formula] if subset and random.choice([True, False]): uses[formula] = random.sample( subset, random.randint(1, len(subset))) else: orphans.append(formula) return lambda x: uses.get(x, []) cider = Cider(cask, debug, verbose, cider_dir=str(tmpdir)) cider.brew = MagicMock() cider.brew.ls = MagicMock(return_value=brewed) cider.brew.uses = MagicMock(side_effect=generate_uses()) cider.installed = MagicMock(return_value=installed) assert cider.missing() == sorted(orphans)
def test_missing(self, tmpdir, cask, debug, verbose, installed, brewed): orphans = [] def generate_uses(): uses = {} for formula in brewed: subset = [x for x in installed if x != formula] if subset and random.choice([True, False]): uses[formula] = random.sample(subset, random.randint( 1, len(subset) )) else: orphans.append(formula) return lambda x: uses.get(x, []) cider = Cider(cask, debug, verbose, cider_dir=str(tmpdir)) cider.brew = MagicMock() cider.brew.ls = MagicMock(return_value=brewed) cider.brew.uses = MagicMock(side_effect=generate_uses()) cider.installed = MagicMock(return_value=installed) assert cider.missing() == sorted(orphans)