Permalink
Browse files

More tests, test refactoring, more mode fixes

  • Loading branch information...
bitprophet committed Mar 22, 2013
1 parent ab8c91f commit 67b0efe667d526e979089ba389f61595a0e79a53
Showing with 27 additions and 10 deletions.
  1. +8 −2 fabric/sftp.py
  2. +19 −8 integration/test_operations.py
View
@@ -230,8 +230,14 @@ def put(self, local_path, remote_path, use_sudo, mirror_local_mode, mode,
# Handle modes if necessary
if (local_is_path and mirror_local_mode) or (mode is not None):
lmode = os.stat(local_path).st_mode if mirror_local_mode else mode
- lmode = int(lmode, 8) & 07777
- rmode = rattrs.st_mode & 07777
+ # Cast to octal integer in case of string
+ if isinstance(lmode, basestring):
+ lmode = int(lmode, 8)
+ lmode = lmode & 07777
+ rmode = rattrs.st_mode
+ # Only bitshift if we actually got an rmode
+ if rmode is not None:
+ rmode = (rmode & 07777)
if lmode != rmode:
if use_sudo:
with hide('everything'):
@@ -12,14 +12,25 @@ def assert_mode(path, mode):
class TestOperations(Integration):
+ filepath = "/tmp/whocares"
+ dirpath = "/tmp/whatever/bin"
+
+ def setup(self):
+ super(TestOperations, self).setup()
+ # Nuke to prevent bleed
+ run("rm -rf %s %s" % (self.dirpath, self.filepath))
+ # Setup just for kicks
+ run("mkdir -p %s" % self.dirpath)
+
def test_no_trailing_space_in_shell_path_in_run(self):
- from fabric.api import show
- with show('debug'):
- run("mkdir -p /tmp/whatever/bin")
- put(StringIO("#!/bin/bash\necho hi"), "/tmp/whatever/bin/myapp", mode="0755")
- with path('/tmp/whatever/bin'):
- assert run('myapp').stdout == 'hi'
+ put(StringIO("#!/bin/bash\necho hi"), "%s/myapp" % self.dirpath, mode="0755")
+ with path(self.dirpath):
+ assert run('myapp').stdout == 'hi'
def test_string_put_mode_arg_doesnt_error(self):
- put(StringIO("#!/bin/bash\necho hi"), "/tmp/whocares", mode="0755")
- assert_mode('/tmp/whocares', "755")
+ put(StringIO("#!/bin/bash\necho hi"), self.filepath, mode="0755")
+ assert_mode(self.filepath, "755")
+
+ def test_int_put_mode_works_ok_too(self):
+ put(StringIO("#!/bin/bash\necho hi"), self.filepath, mode=0755)
+ assert_mode(self.filepath, "755")

0 comments on commit 67b0efe

Please sign in to comment.