/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

  • Committer: Martin
  • Date: 2017-06-05 20:48:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6658.
  • Revision ID: gzlist@googlemail.com-20170605204831-20accykspjcrx0a8
Apply 2to3 dict fixer and clean up resulting mess using view helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
"""Tests for handling of ignore files"""
18
18
 
19
 
from cStringIO import StringIO
20
 
 
21
 
from bzrlib import config, errors, ignores
22
 
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
 
19
from .. import (
 
20
    config,
 
21
    ignores,
 
22
    )
 
23
from ..sixish import (
 
24
    BytesIO,
 
25
    )
 
26
from . import (
 
27
    TestCase,
 
28
    TestCaseInTempDir,
 
29
    TestCaseWithTransport,
 
30
    )
23
31
 
24
32
 
25
33
class TestParseIgnoreFile(TestCase):
26
34
 
27
35
    def test_parse_fancy(self):
28
 
        ignored = ignores.parse_ignore_file(StringIO(
 
36
        ignored = ignores.parse_ignore_file(BytesIO(
29
37
                './rootdir\n'
30
38
                'randomfile*\n'
31
39
                'path/from/ro?t\n'
37
45
                '!RE:^\.z.*\n'
38
46
                '!!./.zcompdump\n'
39
47
                ))
40
 
        self.assertEqual(set(['./rootdir',
 
48
        self.assertEqual({'./rootdir',
41
49
                          'randomfile*',
42
50
                          'path/from/ro?t',
43
51
                          u'unicode\xb5',
45
53
                          ' xx ',
46
54
                          '!RE:^\.z.*',
47
55
                          '!!./.zcompdump',
48
 
                         ]), ignored)
 
56
                         }, ignored)
49
57
 
50
58
    def test_parse_empty(self):
51
 
        ignored = ignores.parse_ignore_file(StringIO(''))
 
59
        ignored = ignores.parse_ignore_file(BytesIO(b''))
52
60
        self.assertEqual(set([]), ignored)
53
61
        
54
62
    def test_parse_non_utf8(self):
55
63
        """Lines with non utf 8 characters should be discarded."""
56
 
        ignored = ignores.parse_ignore_file(StringIO(
 
64
        ignored = ignores.parse_ignore_file(BytesIO(
57
65
                'utf8filename_a\n'
58
66
                'invalid utf8\x80\n'
59
67
                'utf8filename_b\n'
60
68
                ))
61
 
        self.assertEqual(set([
 
69
        self.assertEqual({
62
70
                        'utf8filename_a',
63
71
                        'utf8filename_b',
64
 
                       ]), ignored)
 
72
                       }, ignored)
65
73
 
66
74
 
67
75
class TestUserIgnores(TestCaseInTempDir):
69
77
    def test_create_if_missing(self):
70
78
        # $HOME should be set to '.'
71
79
        ignore_path = config.user_ignore_config_filename()
72
 
        self.failIfExists(ignore_path)
 
80
        self.assertPathDoesNotExist(ignore_path)
73
81
        user_ignores = ignores.get_user_ignores()
74
82
        self.assertEqual(set(ignores.USER_DEFAULTS), user_ignores)
75
83
 
76
 
        self.failUnlessExists(ignore_path)
 
84
        self.assertPathExists(ignore_path)
77
85
        f = open(ignore_path, 'rb')
78
86
        try:
79
87
            entries = ignores.parse_ignore_file(f)
134
142
        added = ignores.add_unique_user_ignores(
135
143
            ['xxx', './bar', 'xxx', 'dir1/', 'dir2/', 'dir3\\'])
136
144
        self.assertEqual(['xxx', 'dir2'], added)
137
 
        self.assertEqual(set(['foo', './bar', u'b\xe5z',
138
 
                              'xxx', 'dir1', 'dir2', 'dir3']),
 
145
        self.assertEqual({'foo', './bar', u'b\xe5z',
 
146
                              'xxx', 'dir1', 'dir2', 'dir3'},
139
147
                         ignores.get_user_ignores())
140
148
 
141
149
 
142
150
class TestRuntimeIgnores(TestCase):
143
151
 
144
152
    def setUp(self):
145
 
        TestCase.setUp(self)
 
153
        super(TestRuntimeIgnores, self).setUp()
146
154
 
147
155
        # For the purposes of these tests, we must have no
148
156
        # runtime ignores
153
161
        self.assertEqual(set(), ignores.get_runtime_ignores())
154
162
 
155
163
        ignores.add_runtime_ignores(['foo'])
156
 
        self.assertEqual(set(['foo']), ignores.get_runtime_ignores())
 
164
        self.assertEqual({'foo'}, ignores.get_runtime_ignores())
157
165
 
158
166
    def test_add_duplicate(self):
159
167
        """Adding the same ignore twice shouldn't add a new entry."""
160
168
        ignores.add_runtime_ignores(['foo', 'bar'])
161
 
        self.assertEqual(set(['foo', 'bar']), ignores.get_runtime_ignores())
 
169
        self.assertEqual({'foo', 'bar'}, ignores.get_runtime_ignores())
162
170
 
163
171
        ignores.add_runtime_ignores(['bar'])
164
 
        self.assertEqual(set(['foo', 'bar']), ignores.get_runtime_ignores())
 
172
        self.assertEqual({'foo', 'bar'}, ignores.get_runtime_ignores())
165
173
 
166
174
 
167
175
class TestTreeIgnores(TestCaseWithTransport):
168
176
    
169
177
    def assertPatternsEquals(self, patterns):
170
178
        contents = open(".bzrignore", 'rU').read().strip().split('\n')
171
 
        self.assertEquals(sorted(patterns), sorted(contents))
 
179
        self.assertEqual(sorted(patterns), sorted(contents))
172
180
 
173
181
    def test_new_file(self):
174
182
        tree = self.make_branch_and_tree(".")
215
223
        self.build_tree_contents([('.bzrignore', "myentry1\r\n")])
216
224
        tree.add([".bzrignore"])
217
225
        ignores.tree_ignores_add_patterns(tree, ["myentry2", "foo"])
218
 
        self.assertEquals(open('.bzrignore', 'rb').read(), 'myentry1\r\nmyentry2\r\nfoo\r\n')
 
226
        self.assertEqual(open('.bzrignore', 'rb').read(), 'myentry1\r\nmyentry2\r\nfoo\r\n')
219
227
        self.assertPatternsEquals(["myentry1", "myentry2", "foo"])