/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/plugins/grep/test_grep.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010, 2011, 2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2010 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
20
20
import re
21
21
import unicodedata as ud
22
22
 
23
 
from ... import tests, osutils
24
 
from ..._termcolor import color_string, FG
 
23
from bzrlib import tests, osutils
 
24
from bzrlib._termcolor import color_string, FG
25
25
 
26
 
from ...tests.features import (
 
26
from bzrlib.tests.features import (
27
27
    ColorFeature,
28
28
    UnicodeFilenameFeature,
29
29
    )
91
91
        self.assertContainsRe(out, "file0.txt:line1", flags=TestGrep._reflags)
92
92
        self.assertEqual(len(out.splitlines()), 2) # finds line1 and line10
93
93
 
94
 
        out, err = self.run_bzr(['grep', 'line\\d+', 'file0.txt'])
 
94
        out, err = self.run_bzr(['grep', 'line\d+', 'file0.txt'])
95
95
        self.assertContainsRe(out, "file0.txt:line1", flags=TestGrep._reflags)
96
96
        self.assertEqual(len(out.splitlines()), 10)
97
97
 
2143
2143
        self.assertEqual(len(out.splitlines()), 1)
2144
2144
 
2145
2145
 
2146
 
# copied from breezy.tests.blackbox.test_diff
 
2146
# copied from bzrlib.tests.blackbox.test_diff
2147
2147
def subst_dates(string):
2148
2148
    """Replace date strings with constant values."""
2149
2149
    return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
2155
2155
    def make_example_branch(self):
2156
2156
        tree = self.make_branch_and_tree('.')
2157
2157
        self.build_tree_contents([
2158
 
            ('hello', b'foo\n'),
2159
 
            ('goodbye', b'baz\n')])
 
2158
            ('hello', 'foo\n'),
 
2159
            ('goodbye', 'baz\n')])
2160
2160
        tree.add(['hello'])
2161
2161
        tree.commit('setup')
2162
2162
        tree.add(['goodbye'])
2166
2166
    def test_grep_diff_basic(self):
2167
2167
        """grep -p basic test."""
2168
2168
        tree = self.make_example_branch()
2169
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
2169
        self.build_tree_contents([('hello', 'hello world!\n')])
2170
2170
        tree.commit('updated hello')
2171
2171
        out, err = self.run_bzr(['grep', '-p', 'hello'])
2172
 
        self.assertEqual(err, '')
 
2172
        self.assertEquals(err, '')
2173
2173
        self.assertEqualDiff(subst_dates(out), '''\
2174
2174
=== revno:3 ===
2175
2175
  === modified file 'hello'
2185
2185
    def test_grep_diff_revision(self):
2186
2186
        """grep -p specific revision."""
2187
2187
        tree = self.make_example_branch()
2188
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
2188
        self.build_tree_contents([('hello', 'hello world!\n')])
2189
2189
        tree.commit('updated hello')
2190
2190
        out, err = self.run_bzr(['grep', '-p', '-r', '3', 'hello'])
2191
 
        self.assertEqual(err, '')
 
2191
        self.assertEquals(err, '')
2192
2192
        self.assertEqualDiff(subst_dates(out), '''\
2193
2193
=== revno:3 ===
2194
2194
  === modified file 'hello'
2200
2200
    def test_grep_diff_revision_range(self):
2201
2201
        """grep -p revision range."""
2202
2202
        tree = self.make_example_branch()
2203
 
        self.build_tree_contents([('hello', b'hello world!1\n')]) # rev 3
 
2203
        self.build_tree_contents([('hello', 'hello world!1\n')]) # rev 3
2204
2204
        tree.commit('rev3')
2205
 
        self.build_tree_contents([('blah', b'hello world!2\n')]) # rev 4
 
2205
        self.build_tree_contents([('blah', 'hello world!2\n')]) # rev 4
2206
2206
        tree.add('blah')
2207
2207
        tree.commit('rev4')
2208
2208
        open('hello', 'a').write('hello world!3\n')
2209
2209
        #self.build_tree_contents([('hello', 'hello world!3\n')]) # rev 5
2210
2210
        tree.commit('rev5')
2211
2211
        out, err = self.run_bzr(['grep', '-p', '-r', '2..5', 'hello'])
2212
 
        self.assertEqual(err, '')
 
2212
        self.assertEquals(err, '')
2213
2213
        self.assertEqualDiff(subst_dates(out), '''\
2214
2214
=== revno:5 ===
2215
2215
  === modified file 'hello'
2229
2229
    def test_grep_diff_color(self):
2230
2230
        """grep -p color test."""
2231
2231
        tree = self.make_example_branch()
2232
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
2232
        self.build_tree_contents([('hello', 'hello world!\n')])
2233
2233
        tree.commit('updated hello')
2234
2234
        out, err = self.run_bzr(['grep', '--diff', '-r', '3',
2235
2235
            '--color', 'always', 'hello'])
2236
 
        self.assertEqual(err, '')
 
2236
        self.assertEquals(err, '')
2237
2237
        revno = color_string('=== revno:3 ===', fg=FG.BOLD_BLUE) + '\n'
2238
2238
        filename = color_string("  === modified file 'hello'", fg=FG.BOLD_MAGENTA) + '\n'
2239
2239
        redhello = color_string('hello', fg=FG.BOLD_RED)
2249
2249
        """grep -p with zero revisions."""
2250
2250
        out, err = self.run_bzr(['init'])
2251
2251
        out, err = self.run_bzr(['grep', '--diff', 'foo'], 3)
2252
 
        self.assertEqual(out, '')
 
2252
        self.assertEquals(out, '')
2253
2253
        self.assertContainsRe(err, "ERROR:.*revision.* does not exist in branch")
2254
2254