~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
from cStringIO import StringIO
18
18
 
19
 
from bzrlib import osutils
20
 
from bzrlib.add import (
21
 
    AddAction,
22
 
    AddFromBaseAction,
 
19
from bzrlib import (
 
20
    add,
 
21
    inventory,
 
22
    osutils,
 
23
    tests,
23
24
    )
24
 
from bzrlib.tests import TestCase, TestCaseWithTransport
25
 
from bzrlib.inventory import Inventory
26
 
 
27
 
 
28
 
class AddCustomIDAction(AddAction):
 
25
 
 
26
 
 
27
class AddCustomIDAction(add.AddAction):
29
28
 
30
29
    def __call__(self, inv, parent_ie, path, kind):
31
30
        # The first part just logs if appropriate
32
31
        # Now generate a custom id
33
32
        file_id = osutils.safe_file_id(kind + '-'
34
 
                                       + path.raw_path.replace('/', '%'),
 
33
                                       + path.replace('/', '%'),
35
34
                                       warn=False)
36
35
        if self.should_print:
37
36
            self._to_file.write('added %s with id %s\n'
38
 
                                % (path.raw_path, file_id))
 
37
                                % (path, file_id))
39
38
        return file_id
40
39
 
41
40
 
42
 
class TestAddFrom(TestCaseWithTransport):
 
41
class TestAddFrom(tests.TestCaseWithTransport):
43
42
    """Tests for AddFromBaseAction"""
44
43
 
45
44
    def make_base_tree(self):
60
59
        try:
61
60
            new_tree.lock_write()
62
61
            try:
63
 
                action = AddFromBaseAction(base_tree, base_path,
64
 
                                           to_file=to_file,
65
 
                                           should_print=should_print)
 
62
                action = add.AddFromBaseAction(base_tree, base_path,
 
63
                                               to_file=to_file,
 
64
                                               should_print=should_print)
66
65
                new_tree.smart_add(file_list, action=action)
67
66
            finally:
68
67
                new_tree.unlock()
116
115
        self.assertNotEqual(None, c_id)
117
116
        self.base_tree.lock_read()
118
117
        self.addCleanup(self.base_tree.unlock)
119
 
        self.failIf(c_id in self.base_tree)
 
118
        self.assertFalse(self.base_tree.has_id(c_id))
120
119
 
121
120
        d_id = new_tree.path2id('subdir/d')
122
121
        self.assertNotEqual(None, d_id)
123
 
        self.failIf(d_id in self.base_tree)
 
122
        self.assertFalse(self.base_tree.has_id(d_id))
124
123
 
125
124
    def test_copy_existing_dir(self):
126
125
        self.make_base_tree()
141
140
        self.assertNotEqual(None, a_id)
142
141
        self.base_tree.lock_read()
143
142
        self.addCleanup(self.base_tree.unlock)
144
 
        self.failIf(a_id in self.base_tree)
145
 
 
146
 
 
147
 
class TestAddActions(TestCase):
 
143
        self.assertFalse(self.base_tree.has_id(a_id))
 
144
 
 
145
 
 
146
class TestAddActions(tests.TestCase):
148
147
 
149
148
    def test_quiet(self):
150
149
        self.run_action("")
153
152
        self.run_action("adding path\n")
154
153
 
155
154
    def run_action(self, output):
156
 
        from bzrlib.add import AddAction
157
 
        from bzrlib.mutabletree import _FastPath
158
 
        inv = Inventory()
 
155
        inv = inventory.Inventory()
159
156
        stdout = StringIO()
160
 
        action = AddAction(to_file=stdout, should_print=bool(output))
 
157
        action = add.AddAction(to_file=stdout, should_print=bool(output))
161
158
 
162
159
        self.apply_redirected(None, stdout, None, action, inv, None,
163
 
            _FastPath('path'), 'file')
 
160
            'path', 'file')
164
161
        self.assertEqual(stdout.getvalue(), output)