48
48
class TestGetUserIgnores(TestCaseInTempDir):
50
def create_ignores(self, patterns):
51
"""Fill out the ignore file with the given patterns"""
52
ignore_path = config.user_ignore_config_filename()
53
config.ensure_config_dir_exists()
55
# Create an empty file
56
f = open(ignore_path, 'wb')
58
for pattern in patterns:
59
f.write(pattern.encode('utf8') + '\n')
50
63
def test_create_if_missing(self):
51
64
# $HOME should be set to '.'
52
65
ignore_path = config.user_ignore_config_filename()
63
76
self.assertEqual(ignores.USER_DEFAULTS, user_ignores)
65
78
def test_use_existing(self):
66
ignore_path = config.user_ignore_config_filename()
67
config.ensure_config_dir_exists()
68
f = open(ignore_path, 'wb')
69
79
patterns = ['*.o', '*.py[co]', u'\xe5*']
71
for pattern in patterns:
72
f.write(pattern.encode('utf8') + '\n')
80
self.create_ignores(patterns)
76
82
user_ignores = ignores.get_user_ignores()
77
83
self.assertEqual(patterns, user_ignores)
85
def test_use_empty(self):
86
ignore_path = config.user_ignore_config_filename()
87
config.ensure_config_dir_exists()
88
f = open(ignore_path, 'wb')
91
self.assertEqual([], ignores.get_user_ignores())
94
"""Test that adding will not duplicate ignores"""
95
# Create an empty file
96
self.create_ignores([])
98
patterns = ['foo', './bar', u'b\xe5z']
99
added = ignores.add_unique_user_ignores(patterns)
100
self.assertEqual(patterns, added)
101
self.assertEqual(patterns, ignores.get_user_ignores())
103
def test_add_unique(self):
104
"""Test that adding will not duplicate ignores"""
105
self.create_ignores(['foo', './bar', u'b\xe5z'])
107
added = ignores.add_unique_user_ignores(['xxx', './bar', 'xxx'])
108
self.assertEqual(['xxx'], added)
109
self.assertEqual(['foo', './bar', u'b\xe5z', 'xxx'],
110
ignores.get_user_ignores())