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
import bzrlib.osutils as osutils
25
from bzrlib.tests import TestCaseInTempDir
28
class TestOSUtils(TestCaseInTempDir):
30
def test_fancy_rename(self):
31
# This should work everywhere
33
osutils.fancy_rename(a, b,
34
rename_func=os.rename,
35
unlink_func=os.unlink)
37
open('a', 'wb').write('something in a\n')
39
self.failIfExists('a')
40
self.failUnlessExists('b')
41
self.check_file_contents('b', 'something in a\n')
43
open('a', 'wb').write('new something in a\n')
46
self.check_file_contents('a', 'something in a\n')
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')
56
open('a', 'wb').write('new something in a\n')
57
osutils.rename('b', 'a')
59
self.check_file_contents('a', 'something in a\n')
62
# TODO: test fancy_rename using a MemoryTransport