~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Robert Collins
  • Date: 2006-01-02 22:37:32 UTC
  • mfrom: (1185.50.33 bzr-jam-integration)
  • Revision ID: robertc@robertcollins.net-20060102223732-d5221b37ff0f7888
Merge in John Meinels integration branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
24
import bzrlib.osutils as osutils
 
25
from bzrlib.tests import TestCaseInTempDir
 
26
 
 
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