~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Vincent Ladeuil
  • Date: 2007-05-06 06:59:57 UTC
  • mto: (2495.1.1 bzr.ab.integration)
  • mto: This revision was merged to the branch mainline in revision 2496.
  • Revision ID: v.ladeuil+lp@free.fr-20070506065957-4jdlek9i5at2qb36
Fix bug #112719 by using the right range header.

* HTTPTestUtil.py:
(SingleOnlyRangeRequestHandler): Noisily refuses mutliple range
requests.

* test_http.py:
(TestSingleOnlyRangeRequestServer): Test the retry mechanism when
a server refuses to handle a mutiple range request without
silently replying with a single range or full file response.

* _pycurl.py:
(PyCurlTransport._get_ranged): The header have been built taken
into account the range hint, don't rebuilt it *ignoring* that
hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
 
from cStringIO import StringIO
 
18
from StringIO import StringIO
19
19
 
20
20
from bzrlib import (
21
21
    delta as _mod_delta,
22
 
    revision as _mod_revision,
23
22
    tests,
24
23
    )
25
24
 
41
40
                     versioned_change='unchanged', renamed=False,
42
41
                     modified='unchanged', exe_change=False,
43
42
                     kind=('file', 'file'), old_path=None,
44
 
                     unversioned_filter=None, view_info=None):
45
 
        if expected is None:
46
 
            expected_lines = None
47
 
        else:
48
 
            expected_lines = [expected]
49
 
        self.assertReportLines(expected_lines, file_id, path,
50
 
                     versioned_change, renamed,
51
 
                     modified, exe_change,
52
 
                     kind, old_path,
53
 
                     unversioned_filter, view_info)
54
 
 
55
 
    def assertReportLines(self, expected_lines, file_id='fid', path='path',
56
 
                     versioned_change='unchanged', renamed=False,
57
 
                     modified='unchanged', exe_change=False,
58
 
                     kind=('file', 'file'), old_path=None,
59
 
                     unversioned_filter=None, view_info=None):
 
43
                     unversioned_filter=None):
60
44
        result = []
61
45
        def result_line(format, *args):
62
46
            result.append(format % args)
63
47
        reporter = _mod_delta._ChangeReporter(result_line,
64
 
            unversioned_filter=unversioned_filter, view_info=view_info)
 
48
            unversioned_filter=unversioned_filter)
65
49
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
66
50
            modified, exe_change, kind)
67
 
        if expected_lines is not None:
68
 
            for i in range(len(expected_lines)):
69
 
                self.assertEqualDiff(expected_lines[i], result[i])
 
51
        if expected is not None:
 
52
            self.assertEqualDiff(expected, result[0])
70
53
        else:
71
54
            self.assertEqual([], result)
72
55
 
116
99
            old_path=None, versioned_change='unversioned',
117
100
            renamed=False, modified='created', exe_change=False,
118
101
            kind=(None, 'file'))
119
 
        # but we can choose to filter these. Probably that should be done
 
102
        # but we can choose to filter these. Probably that should be done 
120
103
        # close to the tree, but this is a reasonable starting point.
121
104
        self.assertReport(None, file_id=None, path='subdir/foo~',
122
105
            old_path=None, versioned_change='unversioned',
123
106
            renamed=False, modified='created', exe_change=False,
124
107
            kind=(None, 'file'), unversioned_filter=lambda x:True)
125
108
 
126
 
    def test_view_filtering(self):
127
 
        # If a file in within the view, it should appear in the output
128
 
        expected_lines = [
129
 
            "Operating on whole tree but only reporting on 'my' view.",
130
 
            " M  path"]
131
 
        self.assertReportLines(expected_lines, modified='modified',
132
 
            view_info=('my',['path']))
133
 
        # If a file in outside the view, it should not appear in the output
134
 
        expected_lines = [
135
 
            "Operating on whole tree but only reporting on 'my' view."]
136
 
        self.assertReportLines(expected_lines, modified='modified',
137
 
            path="foo", view_info=('my',['path']))
138
 
 
139
109
    def assertChangesEqual(self,
140
110
                           file_id='fid',
141
111
                           paths=('path', 'path'),
217
187
                           exe_change=False)
218
188
 
219
189
 
220
 
class TestChangesFrom(tests.TestCaseWithTransport):
 
190
class TestChangesFrom (tests.TestCaseWithTransport):
221
191
 
222
192
    def show_string(self, delta, *args,  **kwargs):
223
193
        to_file = StringIO()
268
238
                           True, False)], delta.renamed)
269
239
        self.assertTrue(delta.has_changed())
270
240
        self.assertTrue(delta.touches_file_id('file-id'))
271
 
 
272
 
 
273
 
class TestDeltaShow(tests.TestCaseWithTransport):
274
 
 
275
 
    def _get_delta(self):
276
 
        # We build the delta from a real tree to avoid depending on internal
277
 
        # implementation details.
278
 
        wt = self.make_branch_and_tree('branch')
279
 
        self.build_tree_contents([('branch/f1', '1\n'),
280
 
                                  ('branch/f2', '2\n'),
281
 
                                  ('branch/f3', '3\n'),
282
 
                                  ('branch/f4', '4\n'),
283
 
                                  ('branch/dir/',),
284
 
                                 ])
285
 
        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
286
 
               ['f1-id', 'f2-id', 'f3-id', 'f4-id', 'dir-id'])
287
 
        wt.commit('commit one', rev_id='1')
288
 
 
289
 
        long_status = """added:
290
 
  dir/
291
 
  f1
292
 
  f2
293
 
  f3
294
 
  f4
295
 
"""
296
 
        short_status = """A  dir/
297
 
A  f1
298
 
A  f2
299
 
A  f3
300
 
A  f4
301
 
"""
302
 
 
303
 
        repo = wt.branch.repository
304
 
        d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
305
 
        return d, long_status, short_status
306
 
 
307
 
    def test_delta_show_short_status_no_filter(self):
308
 
        d, long_status, short_status = self._get_delta()
309
 
        out = StringIO()
310
 
        d.show(out, short_status=True)
311
 
        self.assertEquals(short_status, out.getvalue())
312
 
 
313
 
    def test_delta_show_long_status_no_filter(self):
314
 
        d, long_status, short_status = self._get_delta()
315
 
        out = StringIO()
316
 
        d.show(out, short_status=False)
317
 
        self.assertEquals(long_status, out.getvalue())
318
 
 
319
 
    def test_delta_show_no_filter(self):
320
 
        d, long_status, short_status = self._get_delta()
321
 
        out = StringIO()
322
 
        def not_a_filter(path, file_id):
323
 
            return True
324
 
        d.show(out, short_status=True, filter=not_a_filter)
325
 
        self.assertEquals(short_status, out.getvalue())
326
 
 
327
 
    def test_delta_show_short_status_single_file_filter(self):
328
 
        d, long_status, short_status = self._get_delta()
329
 
        out = StringIO()
330
 
        def only_f2(path, file_id):
331
 
            return path == 'f2'
332
 
        d.show(out, short_status=True, filter=only_f2)
333
 
        self.assertEquals("A  f2\n", out.getvalue())
334
 
 
335
 
    def test_delta_show_long_status_single_file_filter(self):
336
 
        d, long_status, short_status = self._get_delta()
337
 
        out = StringIO()
338
 
        def only_f2(path, file_id):
339
 
            return path == 'f2'
340
 
        d.show(out, short_status=False, filter=only_f2)
341
 
        self.assertEquals("added:\n  f2\n", out.getvalue())
342
 
 
343
 
    def test_delta_show_short_status_single_file_id_filter(self):
344
 
        d, long_status, short_status = self._get_delta()
345
 
        out = StringIO()
346
 
        def only_f2_id(path, file_id):
347
 
            return file_id == 'f2-id'
348
 
        d.show(out, short_status=True, filter=only_f2_id)
349
 
        self.assertEquals("A  f2\n", out.getvalue())
350