/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Aaron Bentley
  • Date: 2006-06-17 18:44:05 UTC
  • mfrom: (1786 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1788.
  • Revision ID: aaron.bentley@utoronto.ca-20060617184405-ba00b55631c7da57
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
266
266
        self.assertEqual(expected_dirblocks[1:],
267
267
            [[line[0:3] for line in block] for block in result])
268
268
 
 
269
    def assertPathCompare(self, path_less, path_greater):
 
270
        """check that path_less and path_greater compare correctly."""
 
271
        self.assertEqual(0, osutils.compare_paths_prefix_order(
 
272
            path_less, path_less))
 
273
        self.assertEqual(0, osutils.compare_paths_prefix_order(
 
274
            path_greater, path_greater))
 
275
        self.assertEqual(-1, osutils.compare_paths_prefix_order(
 
276
            path_less, path_greater))
 
277
        self.assertEqual(1, osutils.compare_paths_prefix_order(
 
278
            path_greater, path_less))
 
279
 
 
280
    def test_compare_paths_prefix_order(self):
 
281
        # root before all else
 
282
        self.assertPathCompare("/", "/a")
 
283
        # alpha within a dir
 
284
        self.assertPathCompare("/a", "/b")
 
285
        self.assertPathCompare("/b", "/z")
 
286
        # high dirs before lower.
 
287
        self.assertPathCompare("/z", "/a/a")
 
288
        # except if the deeper dir should be output first
 
289
        self.assertPathCompare("/a/b/c", "/d/g")
 
290
        # lexical betwen dirs of the same height
 
291
        self.assertPathCompare("/a/z", "/z/z")
 
292
        self.assertPathCompare("/a/c/z", "/a/d/e")
 
293
 
 
294
        # this should also be consistent for no leading / paths
 
295
        # root before all else
 
296
        self.assertPathCompare("", "a")
 
297
        # alpha within a dir
 
298
        self.assertPathCompare("a", "b")
 
299
        self.assertPathCompare("b", "z")
 
300
        # high dirs before lower.
 
301
        self.assertPathCompare("z", "a/a")
 
302
        # except if the deeper dir should be output first
 
303
        self.assertPathCompare("a/b/c", "d/g")
 
304
        # lexical betwen dirs of the same height
 
305
        self.assertPathCompare("a/z", "z/z")
 
306
        self.assertPathCompare("a/c/z", "a/d/e")
 
307
 
 
308
    def test_path_prefix_sorting(self):
 
309
        """Doing a sort on path prefix should match our sample data."""
 
310
        original_paths = [
 
311
            'a',
 
312
            'a/b',
 
313
            'a/b/c',
 
314
            'b',
 
315
            'b/c',
 
316
            'd',
 
317
            'd/e',
 
318
            'd/e/f',
 
319
            'd/f',
 
320
            'd/g',
 
321
            'g',
 
322
            ]
 
323
 
 
324
        dir_sorted_paths = [
 
325
            'a',
 
326
            'b',
 
327
            'd',
 
328
            'g',
 
329
            'a/b',
 
330
            'a/b/c',
 
331
            'b/c',
 
332
            'd/e',
 
333
            'd/f',
 
334
            'd/g',
 
335
            'd/e/f',
 
336
            ]
 
337
 
 
338
        self.assertEqual(
 
339
            dir_sorted_paths,
 
340
            sorted(original_paths, key=osutils.path_prefix_key))
 
341
        # using the comparison routine shoudl work too:
 
342
        self.assertEqual(
 
343
            dir_sorted_paths,
 
344
            sorted(original_paths, cmp=osutils.compare_paths_prefix_order))