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