63
63
entries = ignores.parse_ignore_file(f)
66
self.assertEqual(set(ignores.USER_DEFAULTS), entries)
66
self.assertEqual(ignores.USER_DEFAULTS, user_ignores)
68
68
def test_use_existing(self):
69
69
patterns = ['*.o', '*.py[co]', u'\xe5*']
70
ignores._set_user_ignores(patterns)
70
ignores.set_user_ignores(patterns)
72
72
user_ignores = ignores.get_user_ignores()
73
self.assertEqual(set(patterns), user_ignores)
73
self.assertEqual(patterns, user_ignores)
75
75
def test_use_empty(self):
76
ignores._set_user_ignores([])
76
ignores.set_user_ignores([])
77
77
ignore_path = config.user_ignore_config_filename()
78
78
self.check_file_contents(ignore_path, '')
80
self.assertEqual(set([]), ignores.get_user_ignores())
80
self.assertEqual([], ignores.get_user_ignores())
82
82
def test_set(self):
83
83
patterns = ['*.py[co]', '*.py[oc]']
84
ignores._set_user_ignores(patterns)
84
ignores.set_user_ignores(patterns)
86
self.assertEqual(set(patterns), ignores.get_user_ignores())
86
self.assertEqual(patterns, ignores.get_user_ignores())
88
88
patterns = ['vim', '*.swp']
89
ignores._set_user_ignores(patterns)
90
self.assertEqual(set(patterns), ignores.get_user_ignores())
89
ignores.set_user_ignores(patterns)
90
self.assertEqual(patterns, ignores.get_user_ignores())
92
92
def test_add(self):
93
93
"""Test that adding will not duplicate ignores"""
94
94
# Create an empty file
95
ignores._set_user_ignores([])
95
ignores.set_user_ignores([])
97
97
patterns = ['foo', './bar', u'b\xe5z']
98
98
added = ignores.add_unique_user_ignores(patterns)
99
99
self.assertEqual(patterns, added)
100
self.assertEqual(set(patterns), ignores.get_user_ignores())
102
def test_add_directory(self):
103
"""Test that adding a directory will strip any trailing slash"""
104
# Create an empty file
105
ignores._set_user_ignores([])
107
in_patterns = ['foo/', 'bar/']
108
added = ignores.add_unique_user_ignores(in_patterns)
109
out_patterns = [ x.rstrip('/') for x in in_patterns ]
110
self.assertEqual(out_patterns, added)
111
self.assertEqual(set(out_patterns), ignores.get_user_ignores())
100
self.assertEqual(patterns, ignores.get_user_ignores())
113
102
def test_add_unique(self):
114
103
"""Test that adding will not duplicate ignores"""
115
ignores._set_user_ignores(['foo', './bar', u'b\xe5z', 'dir1/'])
104
ignores.set_user_ignores(['foo', './bar', u'b\xe5z'])
117
added = ignores.add_unique_user_ignores(
118
['xxx', './bar', 'xxx', 'dir1/', 'dir2/'])
119
self.assertEqual(['xxx', 'dir2'], added)
120
self.assertEqual(set(['foo', './bar', u'b\xe5z',
121
'xxx', 'dir1', 'dir2']),
106
added = ignores.add_unique_user_ignores(['xxx', './bar', 'xxx'])
107
self.assertEqual(['xxx'], added)
108
self.assertEqual(['foo', './bar', u'b\xe5z', 'xxx'],
122
109
ignores.get_user_ignores())
125
class TestRuntimeIgnores(TestCase):
130
orig = ignores._runtime_ignores
132
ignores._runtime_ignores = orig
133
self.addCleanup(restore)
134
# For the purposes of these tests, we must have no
136
ignores._runtime_ignores = set()
139
"""Test that we can add an entry to the list."""
140
self.assertEqual(set(), ignores.get_runtime_ignores())
142
ignores.add_runtime_ignores(['foo'])
143
self.assertEqual(set(['foo']), ignores.get_runtime_ignores())
145
def test_add_duplicate(self):
146
"""Adding the same ignore twice shouldn't add a new entry."""
147
ignores.add_runtime_ignores(['foo', 'bar'])
148
self.assertEqual(set(['foo', 'bar']), ignores.get_runtime_ignores())
150
ignores.add_runtime_ignores(['bar'])
151
self.assertEqual(set(['foo', 'bar']), ignores.get_runtime_ignores())