/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_ignores.py

Merge test-run support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for handling of ignore files"""
18
18
 
19
 
import os
20
 
 
21
19
from .. import (
22
 
    bedding,
 
20
    config,
23
21
    ignores,
24
22
    )
25
23
from ..sixish import (
36
34
 
37
35
    def test_parse_fancy(self):
38
36
        ignored = ignores.parse_ignore_file(BytesIO(
39
 
            b'./rootdir\n'
40
 
            b'randomfile*\n'
41
 
            b'path/from/ro?t\n'
42
 
            b'unicode\xc2\xb5\n'  # u'\xb5'.encode('utf8')
43
 
            b'dos\r\n'
44
 
            b'\n'  # empty line
45
 
            b'#comment\n'
46
 
            b' xx \n'  # whitespace
47
 
            b'!RE:^\\.z.*\n'
48
 
            b'!!./.zcompdump\n'
49
 
            ))
 
37
                b'./rootdir\n'
 
38
                b'randomfile*\n'
 
39
                b'path/from/ro?t\n'
 
40
                b'unicode\xc2\xb5\n' # u'\xb5'.encode('utf8')
 
41
                b'dos\r\n'
 
42
                b'\n' # empty line
 
43
                b'#comment\n'
 
44
                b' xx \n' # whitespace
 
45
                b'!RE:^\\.z.*\n'
 
46
                b'!!./.zcompdump\n'
 
47
                ))
50
48
        self.assertEqual({u'./rootdir',
51
49
                          u'randomfile*',
52
50
                          u'path/from/ro?t',
55
53
                          u' xx ',
56
54
                          u'!RE:^\\.z.*',
57
55
                          u'!!./.zcompdump',
58
 
                          }, ignored)
 
56
                         }, ignored)
59
57
 
60
58
    def test_parse_empty(self):
61
59
        ignored = ignores.parse_ignore_file(BytesIO(b''))
62
60
        self.assertEqual(set([]), ignored)
63
 
 
 
61
        
64
62
    def test_parse_non_utf8(self):
65
63
        """Lines with non utf 8 characters should be discarded."""
66
64
        ignored = ignores.parse_ignore_file(BytesIO(
67
 
            b'utf8filename_a\n'
68
 
            b'invalid utf8\x80\n'
69
 
            b'utf8filename_b\n'
70
 
            ))
 
65
                b'utf8filename_a\n'
 
66
                b'invalid utf8\x80\n'
 
67
                b'utf8filename_b\n'
 
68
                ))
71
69
        self.assertEqual({
72
 
            u'utf8filename_a',
73
 
            u'utf8filename_b',
74
 
            }, ignored)
 
70
                        u'utf8filename_a',
 
71
                        u'utf8filename_b',
 
72
                       }, ignored)
75
73
 
76
74
 
77
75
class TestUserIgnores(TestCaseInTempDir):
78
76
 
79
77
    def test_create_if_missing(self):
80
78
        # $HOME should be set to '.'
81
 
        ignore_path = bedding.user_ignore_config_path()
 
79
        ignore_path = config.user_ignore_config_filename()
82
80
        self.assertPathDoesNotExist(ignore_path)
83
81
        user_ignores = ignores.get_user_ignores()
84
82
        self.assertEqual(set(ignores.USER_DEFAULTS), user_ignores)
88
86
            entries = ignores.parse_ignore_file(f)
89
87
        self.assertEqual(set(ignores.USER_DEFAULTS), entries)
90
88
 
91
 
    def test_create_with_intermediate_missing(self):
92
 
        # $HOME should be set to '.'
93
 
        ignore_path = bedding.user_ignore_config_path()
94
 
        self.assertPathDoesNotExist(ignore_path)
95
 
        os.mkdir('empty-home')
96
 
 
97
 
        config_path = os.path.join(self.test_dir, 'empty-home', '.config')
98
 
        self.overrideEnv('BRZ_HOME', config_path)
99
 
        self.assertPathDoesNotExist(config_path)
100
 
 
101
 
        user_ignores = ignores.get_user_ignores()
102
 
        self.assertEqual(set(ignores.USER_DEFAULTS), user_ignores)
103
 
 
104
 
        ignore_path = bedding.user_ignore_config_path()
105
 
        self.assertPathDoesNotExist(ignore_path)
106
 
 
107
89
    def test_use_existing(self):
108
90
        patterns = [u'*.o', u'*.py[co]', u'\xe5*']
109
91
        ignores._set_user_ignores(patterns)
113
95
 
114
96
    def test_use_empty(self):
115
97
        ignores._set_user_ignores([])
116
 
        ignore_path = bedding.user_ignore_config_path()
 
98
        ignore_path = config.user_ignore_config_filename()
117
99
        self.check_file_contents(ignore_path, b'')
118
100
 
119
101
        self.assertEqual(set([]), ignores.get_user_ignores())
145
127
 
146
128
        in_patterns = ['foo/', 'bar/', 'baz\\']
147
129
        added = ignores.add_unique_user_ignores(in_patterns)
148
 
        out_patterns = [x.rstrip('/\\') for x in in_patterns]
 
130
        out_patterns = [ x.rstrip('/\\') for x in in_patterns ]
149
131
        self.assertEqual(out_patterns, added)
150
132
        self.assertEqual(set(out_patterns), ignores.get_user_ignores())
151
133
 
158
140
            ['xxx', './bar', 'xxx', 'dir1/', 'dir2/', 'dir3\\'])
159
141
        self.assertEqual(['xxx', 'dir2'], added)
160
142
        self.assertEqual({'foo', './bar', u'b\xe5z',
161
 
                          'xxx', 'dir1', 'dir2', 'dir3'},
 
143
                              'xxx', 'dir1', 'dir2', 'dir3'},
162
144
                         ignores.get_user_ignores())
163
145
 
164
146
 
237
219
        self.build_tree_contents([('.bzrignore', b"myentry1\r\n")])
238
220
        tree.add([".bzrignore"])
239
221
        ignores.tree_ignores_add_patterns(tree, ["myentry2", "foo"])
240
 
        with open('.bzrignore', 'rb') as f:
241
 
            self.assertEqual(f.read(), b'myentry1\r\nmyentry2\r\nfoo\r\n')
 
222
        with open('.bzrignore') as f:
 
223
            self.assertEqual(f.read(), 'myentry1\r\nmyentry2\r\nfoo\r\n')
242
224
        self.assertPatternsEquals(["myentry1", "myentry2", "foo"])