/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: John Arbash Meinel
  • Date: 2008-12-11 03:08:03 UTC
  • mto: This revision was merged to the branch mainline in revision 3895.
  • Revision ID: john@arbash-meinel.com-20081211030803-gctunob7zsten3qg
Move everything into properly parameterized tests.

Also add tests that we preserve the object when it is already lines.

The compiled form takes 450us on a 7.6k line file (NEWS).
So for common cases, we should have virtually no overhead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
758
758
 
759
759
class TestChunksToLines(TestCase):
760
760
 
761
 
    def assertChunksToLines(self, lines, chunks):
762
 
        self.assertEqual(lines, osutils.chunks_to_lines(chunks))
763
 
 
764
 
    def test_fulltext_chunk_to_lines(self):
765
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
766
 
                                 ['foo\nbar\r\nba\rz\n'])
767
 
 
768
 
    def test_lines_to_lines(self):
769
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
770
 
                                 ['foo\n', 'bar\r\n', 'ba\rz\n'])
771
 
 
772
 
    def test_no_final_newline(self):
773
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
774
 
                                 ['foo\nbar\r\nba\rz'])
775
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
776
 
                                 ['foo\n', 'bar\r\n', 'ba\rz'])
777
 
 
778
 
    def test_mixed(self):
779
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
780
 
                                 ['foo\n', 'bar\r\nba\r', 'z'])
781
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
782
 
                                 ['foo\nb', 'a', 'r\r\nba\r', 'z'])
783
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
784
 
                                 ['foo\nbar\r\nba', '\r', 'z'])
785
 
 
786
 
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
787
 
                                 ['foo\n', '', 'bar\r\nba', '\r', 'z'])
 
761
    def test_smoketest(self):
 
762
        self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
 
763
                         osutils.chunks_to_lines(['foo\nbar', '\nbaz\n']))
 
764
        self.assertEqual(['foo\n', 'bar\n', 'baz\n'],
 
765
                         osutils.chunks_to_lines(['foo\n', 'bar\n', 'baz\n']))
 
766
 
 
767
    def test_is_compiled(self):
 
768
        from bzrlib.tests.test__chunks_to_lines import CompiledChunksToLinesFeature
 
769
        if CompiledChunksToLinesFeature:
 
770
            from bzrlib._chunks_to_lines_pyx import chunks_to_lines
 
771
        else:
 
772
            from bzrlib._chunks_to_lines_py import chunks_to_lines
 
773
        self.assertIs(chunks_to_lines, osutils.chunks_to_lines)
788
774
 
789
775
 
790
776
class TestSplitLines(TestCase):