From: Brian Warner Date: Tue, 13 Oct 2009 05:21:54 +0000 (-0700) Subject: test/common.py: update FakeMutableFileNode to new contents= callable scheme X-Git-Tag: trac-4100~15 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/install.html?a=commitdiff_plain;h=e63f59f50c0efbee5ea84a05d5b370de5c20e16a;p=tahoe-lafs%2Ftahoe-lafs.git test/common.py: update FakeMutableFileNode to new contents= callable scheme --- diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 2be08878..5bc2f141 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -157,13 +157,22 @@ class FakeMutableFileNode: def __init__(self, storage_broker, secret_holder, default_encoding_parameters, history): self.init_from_uri(make_mutable_file_uri()) - def create(self, initial_contents, key_generator=None, keysize=None): + def create(self, contents, key_generator=None, keysize=None): + initial_contents = self._get_initial_contents(contents) if len(initial_contents) > self.MUTABLE_SIZELIMIT: raise FileTooLargeError("SDMF is limited to one segment, and " "%d > %d" % (len(initial_contents), self.MUTABLE_SIZELIMIT)) self.all_contents[self.storage_index] = initial_contents return defer.succeed(self) + def _get_initial_contents(self, contents): + if isinstance(contents, str): + return contents + if contents is None: + return "" + assert callable(contents), "%s should be callable, not %s" % \ + (contents, type(contents)) + return contents(self) def init_from_uri(self, filecap): assert isinstance(filecap, str) if filecap.startswith("URI:SSK:"):