/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.31.47 by John Arbash Meinel
Added a fancy footwork rename to osutils, made SftpTransport use it.
1
# Copyright (C) 2005 by Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for the osutils wrapper.
18
"""
19
20
import os
21
import sys
22
23
import bzrlib
1532 by Robert Collins
Merge in John Meinels integration branch.
24
import bzrlib.osutils as osutils
1185.31.47 by John Arbash Meinel
Added a fancy footwork rename to osutils, made SftpTransport use it.
25
from bzrlib.tests import TestCaseInTempDir
1532 by Robert Collins
Merge in John Meinels integration branch.
26
1185.31.47 by John Arbash Meinel
Added a fancy footwork rename to osutils, made SftpTransport use it.
27
28
class TestOSUtils(TestCaseInTempDir):
29
30
    def test_fancy_rename(self):
31
        # This should work everywhere
32
        def rename(a, b):
33
            osutils.fancy_rename(a, b,
34
                    rename_func=os.rename,
35
                    unlink_func=os.unlink)
36
37
        open('a', 'wb').write('something in a\n')
38
        rename('a', 'b')
39
        self.failIfExists('a')
40
        self.failUnlessExists('b')
41
        self.check_file_contents('b', 'something in a\n')
42
43
        open('a', 'wb').write('new something in a\n')
44
        rename('b', 'a')
45
46
        self.check_file_contents('a', 'something in a\n')
47
48
    def test_rename(self):
49
        # Rename should be semi-atomic on all platforms
50
        open('a', 'wb').write('something in a\n')
51
        osutils.rename('a', 'b')
52
        self.failIfExists('a')
53
        self.failUnlessExists('b')
54
        self.check_file_contents('b', 'something in a\n')
55
56
        open('a', 'wb').write('new something in a\n')
57
        osutils.rename('b', 'a')
58
59
        self.check_file_contents('a', 'something in a\n')
60
61
62
    # TODO: test fancy_rename using a MemoryTransport
63