1
# Copyright (C) 2005 by Canonical Ltd
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.
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.
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
17
"""Tests for the osutils wrapper.
24
from bzrlib.tests import TestCaseInTempDir
25
import bzrlib.osutils as osutils
27
class TestOSUtils(TestCaseInTempDir):
29
def test_fancy_rename(self):
30
# This should work everywhere
32
osutils.fancy_rename(a, b,
33
rename_func=os.rename,
34
unlink_func=os.unlink)
36
open('a', 'wb').write('something in a\n')
38
self.failIfExists('a')
39
self.failUnlessExists('b')
40
self.check_file_contents('b', 'something in a\n')
42
open('a', 'wb').write('new something in a\n')
45
self.check_file_contents('a', 'something in a\n')
47
def test_rename(self):
48
# Rename should be semi-atomic on all platforms
49
open('a', 'wb').write('something in a\n')
50
osutils.rename('a', 'b')
51
self.failIfExists('a')
52
self.failUnlessExists('b')
53
self.check_file_contents('b', 'something in a\n')
55
open('a', 'wb').write('new something in a\n')
56
osutils.rename('b', 'a')
58
self.check_file_contents('a', 'something in a\n')
61
# TODO: test fancy_rename using a MemoryTransport