~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ignores.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-12 17:36:57 UTC
  • mto: This revision was merged to the branch mainline in revision 1871.
  • Revision ID: john@arbash-meinel.com-20060712173657-c79f05be9d74095b
Adding a helper function that will only add patterns if they are missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
class TestGetUserIgnores(TestCaseInTempDir):
49
49
    
 
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()
 
54
 
 
55
        # Create an empty file
 
56
        f = open(ignore_path, 'wb')
 
57
        try:
 
58
            for pattern in patterns:
 
59
                f.write(pattern.encode('utf8') + '\n')
 
60
        finally:
 
61
            f.close()
 
62
 
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)
64
77
 
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*']
70
 
        try:
71
 
            for pattern in patterns:
72
 
                f.write(pattern.encode('utf8') + '\n')
73
 
        finally:
74
 
            f.close()
 
80
        self.create_ignores(patterns)
75
81
 
76
82
        user_ignores = ignores.get_user_ignores()
77
83
        self.assertEqual(patterns, user_ignores)
 
84
 
 
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')
 
89
        f.close()
 
90
 
 
91
        self.assertEqual([], ignores.get_user_ignores())
 
92
 
 
93
    def test_add(self):
 
94
        """Test that adding will not duplicate ignores"""
 
95
        # Create an empty file
 
96
        self.create_ignores([])
 
97
 
 
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())
 
102
 
 
103
    def test_add_unique(self):
 
104
        """Test that adding will not duplicate ignores"""
 
105
        self.create_ignores(['foo', './bar', u'b\xe5z'])
 
106
 
 
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())