~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)
 
37
                            parse_patches,
 
38
                            NO_NL)
38
39
 
39
40
 
40
41
class PatchesTester(TestCase):
41
42
 
42
43
    def datafile(self, filename):
43
 
        data_path = os.path.join(os.path.dirname(__file__), 
 
44
        data_path = os.path.join(os.path.dirname(__file__),
44
45
                                 "test_patches_data", filename)
45
46
        return file(data_path, "rb")
46
47
 
112
113
        self.lineThing(" hello\n", ContextLine)
113
114
        self.lineThing("+hello\n", InsertLine)
114
115
        self.lineThing("-hello\n", RemoveLine)
115
 
    
 
116
 
116
117
    def testMalformedLine(self):
117
118
        """Parse invalid valid hunk lines"""
118
119
        self.makeMalformedLine("hello\n")
119
 
    
 
120
 
 
121
    def testMalformedLineNO_NL(self):
 
122
        """Parse invalid '\ No newline at end of file' in hunk lines"""
 
123
        self.makeMalformedLine(NO_NL)
 
124
 
120
125
    def compare_parsed(self, patchtext):
121
126
        lines = patchtext.splitlines(True)
122
127
        patch = parse_patch(lines.__iter__())
174
179
            ('diff-4', 'orig-4', 'mod-4'),
175
180
            ('diff-5', 'orig-5', 'mod-5'),
176
181
            ('diff-6', 'orig-6', 'mod-6'),
 
182
            ('diff-7', 'orig-7', 'mod-7'),
177
183
        ]
178
184
        for diff, orig, mod in files:
179
185
            patch = self.datafile(diff)
196
202
            ('diff-4', 'orig-4', 'mod-4'),
197
203
            ('diff-5', 'orig-5', 'mod-5'),
198
204
            ('diff-6', 'orig-6', 'mod-6'),
 
205
            ('diff-7', 'orig-7', 'mod-7'),
199
206
        ]
200
207
        for diff, orig, mod in files:
201
208
            parsed = parse_patch(self.datafile(diff))