class TestHistory(unittest.TestCase): def setUp(self): self.history = History('<dummy prefix>') self.history._log_path = PATH self.package_sets = [ set([ 'appinst-2.1.0-1.egg', 'basemap-1.0.1-1.egg', 'biopython-1.57-2.egg' ]), set([ 'basemap-1.0.2-1.egg', 'biopython-1.57-2.egg', 'numpy-1.6.1-2.egg' ]), set([ 'basemap-1.0.2-1.egg', 'biopython-1.57-2.egg', 'numpy-1.7.0-1.egg' ]) ] # Write the history file self.history._write_egg_names(self.package_sets[0]) for i, state in enumerate(self.package_sets[:-1]): self.history._write_changes(state, self.package_sets[i + 1]) def tearDown(self): if isfile(self.history._log_path): unlink(self.history._log_path) def test_get_state(self): self.assertEqual(self.history.get_state(0), self.package_sets[0]) self.assertEqual(self.history.get_state(), self.package_sets[-1]) def test_parse(self): package_edits = [packages for (date, packages) in self.history.parse()] self.assertEqual(self.package_sets[0], package_edits[0]) self.assertEqual( package_changes(self.package_sets[0], self.package_sets[1]), package_edits[1]) self.history.print_log() # When history file is not present unlink(self.history._log_path) self.assertEqual(self.history.parse(), []) self.history.print_log() def test_update(self): self.history.update() self.assertEqual(self.history.get_state(), set()) self.assertEqual(self.history.parse()[-1][1], package_changes(self.package_sets[-1], set()))
class TestHistory(unittest.TestCase): def setUp(self): self.history = History('<dummy prefix>') self.history._log_path = PATH self.package_sets = [set(['appinst-2.1.0-1.egg', 'basemap-1.0.1-1.egg', 'biopython-1.57-2.egg']), set(['basemap-1.0.2-1.egg', 'biopython-1.57-2.egg', 'numpy-1.6.1-2.egg']), set(['basemap-1.0.2-1.egg', 'biopython-1.57-2.egg', 'numpy-1.7.0-1.egg'])] # Write the history file self.history._write_egg_names(self.package_sets[0]) for i, state in enumerate(self.package_sets[:-1]): self.history._write_changes(state, self.package_sets[i+1]) def tearDown(self): if isfile(self.history._log_path): unlink(self.history._log_path) def test_get_state(self): self.assertEqual(self.history.get_state(0), self.package_sets[0]) self.assertEqual(self.history.get_state(), self.package_sets[-1]) def test_parse(self): package_edits = [packages for (date, packages) in self.history.parse()] self.assertEqual(self.package_sets[0], package_edits[0]) self.assertEqual(package_changes(self.package_sets[0], self.package_sets[1]), package_edits[1]) self.history.print_log() # When history file is not present unlink(self.history._log_path) self.assertEqual(self.history.parse(), []) self.history.print_log() def test_update(self): self.history.update() self.assertEqual(self.history.get_state(), set()) self.assertEqual(self.history.parse()[-1][1], package_changes(self.package_sets[-1], set()))
def revert_actions(self, arg): """ Calculate the actions necessary to revert to a given state, the argument may be one of: * complete set of eggs, i.e. a set of egg file names * revision number (negative numbers allowed) """ h = History(self.top_prefix) h.update() if isinstance(arg, set): state = arg else: try: rev = int(arg) except (TypeError, ValueError): raise EnpkgError("Invalid argument: integer expected, " "got: {0!r}".format(arg)) try: state = h.get_state(rev) except IndexError: raise EnpkgError("Error: no such revision: %r" % arg) curr = h.get_state() if state == curr: return [] res = [] for egg in curr - state: if egg.startswith('enstaller'): continue res.append(('remove', egg)) for egg in state - curr: if egg.startswith('enstaller'): continue if not isfile(join(self._downloader.cache_directory, egg)): eggname, version = egg_name_to_name_version(egg) try: self._remote_repository.find_package(eggname, version) res.append(('fetch_0', egg)) except NoSuchPackage: raise EnpkgError("cannot revert -- missing %r" % egg) res.append(('install', egg)) return res
def revert_actions(self, arg): """ Calculate the actions necessary to revert to a given state, the argument may be one of: * complete set of eggs, i.e. a set of egg file names * revision number (negative numbers allowed) """ h = History(self.top_prefix) h.update() if isinstance(arg, set): state = arg else: try: rev = int(arg) except (TypeError, ValueError): raise EnpkgError("Invalid argument: integer expected, " "got: {0!r}".format(arg)) try: state = h.get_state(rev) except IndexError: raise EnpkgError("Error: no such revision: %r" % arg) curr = h.get_state() if state == curr: return [] res = [] for egg in curr - state: if egg.startswith('enstaller'): continue res.append(('remove', egg)) for egg in state - curr: if egg.startswith('enstaller'): continue if not isfile(join(self._downloader.cache_directory, egg)): eggname, version = egg_name_to_name_version(egg) try: self._remote_repository.find_package(eggname, version) res.append(('fetch_0', egg)) except NoSuchPackage: raise EnpkgError("cannot revert -- missing %r" % egg) res.append(('install', egg)) return res
def print_history(prefix): h = History(prefix) h.update() h.print_log()
def print_history(prefix): h = History(prefix) h.update() h.print_log()