def test_stack_settings(self): """test settings aggregation""" kv1 = KeyValueStoreModifier({'one': {'one': 1, 'two': 2}, 'two': 2}) stack = ContextStack() ctx = Context('first') ctx.set_settings(kv1) stack.push(ctx) kv2 = KeyValueStoreModifier({'one': {'one': '1', 'three': 3}, 'two': {'one': 1, 'foo': 2}, 'three': 3}) assert stack.settings().data().to_dict() == kv1.data() ctx = Context('second') ctx.set_settings(kv2) stack.push(ctx) kvd = stack.settings().data() assert kvd.one.one == '1' assert kvd.one.three == 3 assert kvd.one.two == 2 assert kvd.three == 3 assert kvd.two.one == 1 # popping the previous context should bring the original one back stack.pop() kvd = stack.settings().data() assert kvd.to_dict() == kv1.data()
def test_copy(self, base_dir): """Verify copy action works, also in case of failed copies""" source = (base_dir / "source_file").write_bytes(bytes(b"hello there")) dest_file = base_dir / "subdir" / "subsubdir" / "destination_file.ext" dk = CopyAction.data_key('foo') assert dk == 'package-actions.copy.foo' kvstore = KeyValueStoreModifier(dict()) kvstore.set_value(dk, 'foo') # make sure the key exists to get values based on our schema data = CopyAction.data(dk, kvstore) data.source.append(source) data.destination = dest_file for dry_run in range(2): t = Transaction(logging.root, dry_run=dry_run) # package_data is currently unused, so None works fco = CopyAction(t, 'doesntmatter', data, 'package', None) # apply assert not dest_file.isfile() assert t.apply().succeeded() assert dest_file.isfile() != dry_run assert source.isfile() # just to be sure :) # rollback t.rollback() assert not dest_file.exists() assert not dest_file.dirname().exists() assert not dest_file.dirname().dirname().exists()
class TestPackageTracker(PackageMetaDataChangeTracker): def _initial_settings_value(self): """copy of initial context""" if not hasattr(self, 'kvstore'): self.kvstore = KeyValueStoreModifier(super(TestPackageTracker, self)._initial_settings_value()) # end initialize our cache return self.kvstore._data() def _settings_path(self): return rw_dir / 'package-settings.json'
def prepare_context(self, executable, env, args, cwd): """We will parse paths from the given commandline and use them in the context we build. Additionaly, we will provide a per-arg handler with the opportunity to inject kvstore overrides """ # Will be a kvstore if there have been overrides kvstore_overrides = KeyValueStoreModifier(dict()) for arg in args: # by default, we use paths as as context provider (configurable) path = self._extract_path(arg) if path: # ignore args that are not paths path = Path(path) if path.dirname().isdir(): self._app.context().push(self.StackAwareHierarchicalContextType(path.dirname())) # end handle valid directory # end handle path self.handle_argument(arg, kvstore_overrides) # end for each arg to check # set overrides if list(kvstore_overrides.keys()): self._app.context().push(Context('delegate overrides', kvstore_overrides)) # end handle overrides return super(ProcessControllerDelegate, self).prepare_context(executable, env, args, cwd)
def _initial_settings_value(self): """copy of initial context""" if not hasattr(self, 'kvstore'): self.kvstore = KeyValueStoreModifier(super(TestPackageTracker, self)._initial_settings_value()) # end initialize our cache return self.kvstore._data()