~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_is_ignored.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
from bzrlib import config, ignores
19
 
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
 
18
import bzrlib
 
19
from bzrlib import config, ignores, osutils
 
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
20
21
 
21
22
 
22
23
class TestIsIgnored(TestCaseWithWorkingTree):
23
24
 
24
 
    def _set_user_ignore_content(self, ignores):
25
 
        """Create user ignore file and set its content to ignores."""
26
 
        config.ensure_config_dir_exists()
27
 
        user_ignore_file = config.user_ignore_config_filename()
28
 
        f = open(user_ignore_file, 'wb')
29
 
        try:
30
 
            f.write(ignores)
31
 
        finally:
32
 
            f.close()
33
 
 
34
25
    def test_is_ignored(self):
35
26
        tree = self.make_branch_and_tree('.')
36
27
        # this will break if a tree changes the ignored format. That is fine
40
31
            ('.bzrignore', './rootdir\n'
41
32
                           'randomfile*\n'
42
33
                           '*bar\n'
43
 
                           '!bazbar\n'
44
34
                           '?foo\n'
45
35
                           '*.~*\n'
46
36
                           'dir1/*f1\n'
47
37
                           'dir1/?f2\n'
48
 
                           'RE:dir2/.*\.wombat\n'
49
38
                           'path/from/ro?t\n'
50
 
                           '**/piffle.py\n'
51
 
                           '!b/piffle.py\n'
52
39
                           'unicode\xc2\xb5\n' # u'\xb5'.encode('utf8')
53
40
                           'dos\r\n'
54
41
                           '\n' # empty line
55
42
                           '#comment\n'
56
43
                           ' xx \n' # whitespace
57
44
            )])
58
 
        # We set user ignore file to contain '' to avoid patterns from
59
 
        # user ignore being used instead of bzrignore. For .e.g. If we
60
 
        # don't do this 'foo.~1~' will match '*~' default user ignore
61
 
        # pattern instead of '*.~*' from bzr ignore as we expect below.
62
 
        self._set_user_ignore_content('')
63
45
        # is_ignored returns the matching ignore regex when a path is ignored.
64
46
        # we check some expected matches for each rule, and one or more
65
47
        # relevant not-matches that look plausible as cases for bugs.
76
58
        self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/root'))
77
59
        self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/roat'))
78
60
        self.assertEqual(None, tree.is_ignored('roat'))
79
 
        
80
 
        self.assertEqual('**/piffle.py', tree.is_ignored('piffle.py'))
81
 
        self.assertEqual('**/piffle.py', tree.is_ignored('a/piffle.py'))
82
 
        self.assertEqual(None, tree.is_ignored('b/piffle.py')) # exclusion
83
 
        self.assertEqual('**/piffle.py', tree.is_ignored('foo/bar/piffle.py'))
84
 
        self.assertEqual(None, tree.is_ignored('p/iffle.py'))
85
61
 
86
62
        self.assertEqual(u'unicode\xb5', tree.is_ignored(u'unicode\xb5'))
87
63
        self.assertEqual(u'unicode\xb5', tree.is_ignored(u'subdir/unicode\xb5'))
96
72
        self.assertEqual('*bar', tree.is_ignored(r'foo\nbar'))
97
73
        self.assertEqual('*bar', tree.is_ignored('bar'))
98
74
        self.assertEqual('*bar', tree.is_ignored('.bar'))
99
 
        
100
 
        self.assertEqual(None, tree.is_ignored('bazbar')) # exclusion
101
75
 
102
76
        self.assertEqual('?foo', tree.is_ignored('afoo'))
103
77
        self.assertEqual('?foo', tree.is_ignored('.foo'))
110
84
 
111
85
        self.assertEqual('dir1/?f2', tree.is_ignored('dir1/ff2'))
112
86
        self.assertEqual('dir1/?f2', tree.is_ignored('dir1/.f2'))
113
 
        
114
 
        self.assertEqual('RE:dir2/.*\.wombat', tree.is_ignored('dir2/foo.wombat'))
115
 
        self.assertEqual(None, tree.is_ignored('dir2/foo'))
116
87
 
117
88
        # Blank lines and comments should be ignored
118
89
        self.assertEqual(None, tree.is_ignored(''))
133
104
 
134
105
        config.ensure_config_dir_exists()
135
106
        user_ignore_file = config.user_ignore_config_filename()
136
 
        self._set_user_ignore_content(
137
 
            '*.py[co]\n'
138
 
            './.shelf\n'
139
 
            '# comment line\n'
140
 
            '\n' #Blank line
141
 
            '\r\n' #Blank dos line
142
 
            ' * \n' #Trailing and suffix spaces
143
 
            'crlf\r\n' # dos style line
144
 
            '*\xc3\xa5*\n' # u'\xe5'.encode('utf8')
145
 
            )
 
107
        f = open(user_ignore_file, 'wb')
 
108
        try:
 
109
            f.write('*.py[co]\n'
 
110
                    './.shelf\n'
 
111
                    '# comment line\n'
 
112
                    '\n' #Blank line
 
113
                    '\r\n' #Blank dos line
 
114
                    ' * \n' #Trailing and suffix spaces
 
115
                    'crlf\r\n' # dos style line
 
116
                    '*\xc3\xa5*\n' # u'\xe5'.encode('utf8')
 
117
                    )
 
118
        finally:
 
119
            f.close()
146
120
 
147
121
        # Rooted
148
122
        self.assertEqual('./.shelf', tree.is_ignored('.shelf'))