Skip to content

Commit

Permalink
Fix tests for mv
Browse files Browse the repository at this point in the history
  • Loading branch information
David Miller authored and David Miller committed Oct 9, 2012
1 parent 457c99b commit bd8781f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
18 changes: 8 additions & 10 deletions ffs/nix.py
Expand Up @@ -309,16 +309,14 @@ def mv(resource, target):
Return: None
Exceptions:None
"""
shutil.move(resource, target)
# try:
# shutil.move(resource, target)
# except shutil.Error:
# if shutil._basename(resource) == target:
# return # Why would you do this?
# if not os.path.exists(target):
# raise
# rm(target, recursive=True)
# shutil.move(resource, target)
try:
shutil.move(resource, target)
except shutil.Error:
if not os.path.exists(target):
rm(target, recursive=True)
shutil.move(resource, target)
if os.path.exists(resource):
rm(resource, recursive=True)


def pwd():
Expand Down
9 changes: 5 additions & 4 deletions test/test_nix.py
Expand Up @@ -431,18 +431,19 @@ def test_mv_target_exists(self):

def test_mv_target_dir_exists(self):
"Should just overwrite"
one = Path(str(self.tpath) + '//one.txt')
two = Path(str(self.tpath) + '//two.txt')
one = Path(str(self.tpath) + '/one.txt')
two = Path(str(self.tpath) + '/two.txt')
one << 'Contentz'
two << 'Contentz Two'

target = str(two)

self.assertTrue(os.path.exists(target))
nix.mv(str(one), str(self.tpath))

self.assertTrue(os.path.exists(target))
self.assertFalse(os.path.exists(str(one)))
self.assertEqual('Contentz', two.contents)
self.assertTrue(os.path.exists(str(one)))
self.assertEqual('Contentz', one.contents)


class RmTestCase(unittest.TestCase):
Expand Down

0 comments on commit bd8781f

Please sign in to comment.