~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Andrew Bennetts
  • Date: 2008-12-12 03:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 3900.
  • Revision ID: andrew.bennetts@canonical.com-20081212035356-uqcu89gy4nqf017x
Fix compilation error in _dirstate_helpers_c on SunOS/Solaris. (Jari Aalto)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
import os.path
21
21
from bzrlib.tests import TestCase
22
22
 
23
23
from bzrlib.iterablefile import IterableFile
24
 
from bzrlib.patches import (MalformedLine,
25
 
                            MalformedHunkHeader,
26
 
                            MalformedPatchHeader,
27
 
                            ContextLine,
 
24
from bzrlib.patches import (MalformedLine, 
 
25
                            MalformedHunkHeader, 
 
26
                            MalformedPatchHeader, 
 
27
                            ContextLine, 
28
28
                            InsertLine,
29
 
                            RemoveLine,
30
 
                            difference_index,
 
29
                            RemoveLine, 
 
30
                            difference_index, 
31
31
                            get_patch_names,
32
 
                            hunk_from_header,
33
 
                            iter_patched,
 
32
                            hunk_from_header, 
 
33
                            iter_patched, 
34
34
                            iter_patched_from_hunks,
35
35
                            parse_line,
36
36
                            parse_patch,
37
 
                            parse_patches,
38
 
                            NO_NL)
 
37
                            parse_patches)
39
38
 
40
39
 
41
40
class PatchesTester(TestCase):
42
41
 
43
42
    def datafile(self, filename):
44
 
        data_path = os.path.join(os.path.dirname(__file__),
 
43
        data_path = os.path.join(os.path.dirname(__file__), 
45
44
                                 "test_patches_data", filename)
46
45
        return file(data_path, "rb")
47
46
 
113
112
        self.lineThing(" hello\n", ContextLine)
114
113
        self.lineThing("+hello\n", InsertLine)
115
114
        self.lineThing("-hello\n", RemoveLine)
116
 
 
 
115
    
117
116
    def testMalformedLine(self):
118
117
        """Parse invalid valid hunk lines"""
119
118
        self.makeMalformedLine("hello\n")
120
 
 
121
 
    def testMalformedLineNO_NL(self):
122
 
        """Parse invalid '\ No newline at end of file' in hunk lines"""
123
 
        self.makeMalformedLine(NO_NL)
124
 
 
 
119
    
125
120
    def compare_parsed(self, patchtext):
126
121
        lines = patchtext.splitlines(True)
127
122
        patch = parse_patch(lines.__iter__())
179
174
            ('diff-4', 'orig-4', 'mod-4'),
180
175
            ('diff-5', 'orig-5', 'mod-5'),
181
176
            ('diff-6', 'orig-6', 'mod-6'),
182
 
            ('diff-7', 'orig-7', 'mod-7'),
183
177
        ]
184
178
        for diff, orig, mod in files:
185
179
            patch = self.datafile(diff)
202
196
            ('diff-4', 'orig-4', 'mod-4'),
203
197
            ('diff-5', 'orig-5', 'mod-5'),
204
198
            ('diff-6', 'orig-6', 'mod-6'),
205
 
            ('diff-7', 'orig-7', 'mod-7'),
206
199
        ]
207
200
        for diff, orig, mod in files:
208
201
            parsed = parse_patch(self.datafile(diff))
257
250
        for patch in patches:
258
251
            patch_files.append((patch.oldname, patch.newname))
259
252
        self.assertEqual(patch_files, filenames)
260
 
 
261
 
    def testStatsValues(self):
262
 
        """Test the added, removed and hunks values for stats_values."""
263
 
        patch = parse_patch(self.datafile("diff"))
264
 
        self.assertEqual((299, 407, 48), patch.stats_values())