[svn r38174] Flag instead of new method and a test.

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-08 17:01:51 +01:00
parent 27cf3997e3
commit e3dce2c288
2 changed files with 10 additions and 10 deletions

View File

@ -93,19 +93,16 @@ class RSync(object):
if self._verbose: if self._verbose:
print '%s <= %s' % (gateway.remoteaddress, modified_rel_path) print '%s <= %s' % (gateway.remoteaddress, modified_rel_path)
def send_if_targets(self): def send(self, raises=True):
""" Sends only if there are targets, otherwise returns """ Sends a sourcedir to all added targets. Flag indicates
whether to raise an error or return in case of lack of
targets
""" """
if not self._channels: if not self._channels:
if raises:
raise IOError("no targets available, maybe you "
"are trying call send() twice?")
return return
self.send()
def send(self):
""" Sends a sourcedir to all added targets.
"""
if not self._channels:
raise IOError("no targets available, maybe you "
"are trying call send() twice?")
# normalize a trailing '/' away # normalize a trailing '/' away
self._sourcedir = os.path.dirname(os.path.join(self._sourcedir, 'x')) self._sourcedir = os.path.dirname(os.path.join(self._sourcedir, 'x'))
# send directory structure and file timestamps/sizes # send directory structure and file timestamps/sizes

View File

@ -23,6 +23,7 @@ class TestRSync(DirSetup):
def test_notargets(self): def test_notargets(self):
rsync = RSync(self.source) rsync = RSync(self.source)
py.test.raises(IOError, "rsync.send()") py.test.raises(IOError, "rsync.send()")
assert rsync.send(raises=False) is None
def test_dirsync(self): def test_dirsync(self):
dest = self.dest1 dest = self.dest1
@ -64,10 +65,12 @@ class TestRSync(DirSetup):
rsync.send() rsync.send()
assert self.dest1.join('hello').check() assert self.dest1.join('hello').check()
py.test.raises(IOError, "rsync.send()") py.test.raises(IOError, "rsync.send()")
assert rsync.send(raises=False) is None
rsync.add_target(gw, self.dest2) rsync.add_target(gw, self.dest2)
rsync.send() rsync.send()
assert self.dest2.join('hello').check() assert self.dest2.join('hello').check()
py.test.raises(IOError, "rsync.send()") py.test.raises(IOError, "rsync.send()")
assert rsync.send(raises=False) is None
def test_rsync_default_reporting(self): def test_rsync_default_reporting(self):
source = self.source source = self.source