~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011, 2016 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
28
28
class TestSyntax(tests.TestCase):
29
29
 
30
30
    def test_comment_is_ignored(self):
31
 
        self.assertEquals([], script._script_to_commands('#comment\n'))
 
31
        self.assertEqual([], script._script_to_commands('#comment\n'))
32
32
 
33
33
    def test_comment_multiple_lines(self):
34
 
        self.assertEquals([
 
34
        self.assertEqual([
35
35
            (['bar'], None, None, None),
36
36
            ],
37
37
            script._script_to_commands("""
50
50
 
51
51
        However we do want to be able to match commands that emit blank lines.
52
52
        """
53
 
        self.assertEquals([
 
53
        self.assertEqual([
54
54
            (['bar'], None, '\n', None),
55
55
            ],
56
56
            script._script_to_commands("""
59
59
            """))
60
60
 
61
61
    def test_simple_command(self):
62
 
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
 
62
        self.assertEqual([(['cd', 'trunk'], None, None, None)],
63
63
                           script._script_to_commands('$ cd trunk'))
64
64
 
65
65
    def test_command_with_single_quoted_param(self):
66
66
        story = """$ bzr commit -m 'two words'"""
67
 
        self.assertEquals([(['bzr', 'commit', '-m', "'two words'"],
 
67
        self.assertEqual([(['bzr', 'commit', '-m', "'two words'"],
68
68
                            None, None, None)],
69
69
                           script._script_to_commands(story))
70
70
 
71
71
    def test_command_with_double_quoted_param(self):
72
72
        story = """$ bzr commit -m "two words" """
73
 
        self.assertEquals([(['bzr', 'commit', '-m', '"two words"'],
 
73
        self.assertEqual([(['bzr', 'commit', '-m', '"two words"'],
74
74
                            None, None, None)],
75
75
                           script._script_to_commands(story))
76
76
 
77
77
    def test_command_with_input(self):
78
 
        self.assertEquals(
 
78
        self.assertEqual(
79
79
            [(['cat', '>file'], 'content\n', None, None)],
80
80
            script._script_to_commands('$ cat >file\n<content\n'))
81
81
 
87
87
            adding file
88
88
            adding file2
89
89
            """
90
 
        self.assertEquals([(['bzr', 'add'], None,
 
90
        self.assertEqual([(['bzr', 'add'], None,
91
91
                            'adding file\nadding file2\n', None)],
92
92
                          script._script_to_commands(story))
93
93
 
97
97
adding file
98
98
adding file2
99
99
"""
100
 
        self.assertEquals([(['bzr', 'add'], None,
 
100
        self.assertEqual([(['bzr', 'add'], None,
101
101
                            'adding file\nadding file2\n', None)],
102
102
                          script._script_to_commands(story))
103
103
 
106
106
$ bzr branch foo
107
107
2>bzr: ERROR: Not a branch: "foo"
108
108
"""
109
 
        self.assertEquals([(['bzr', 'branch', 'foo'],
 
109
        self.assertEqual([(['bzr', 'branch', 'foo'],
110
110
                            None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
111
111
                          script._script_to_commands(story))
112
112
 
120
120
        story = """
121
121
$ foo = `bzr file-id toto`
122
122
"""
123
 
        self.assertEquals([(['foo', '=', '`bzr file-id toto`'],
 
123
        self.assertEqual([(['foo', '=', '`bzr file-id toto`'],
124
124
                            None, None, None)],
125
125
                          script._script_to_commands(story))
126
126
 
172
172
        """
173
173
        e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
174
174
        self.assertContainsRe(e.msg, "not found.*foo")
175
 
        self.assertEquals(e.text, "foo --frob")
 
175
        self.assertEqual(e.text, "foo --frob")
176
176
 
177
177
    def test_blank_output_mismatches_output(self):
178
178
        """If you give output, the output must actually be blank.
299
299
        self.run_script("""
300
300
        $ bzr init --quiet a
301
301
        """)
302
 
        self.assertEquals(trace.is_quiet(), False)
 
302
        self.assertEqual(trace.is_quiet(), False)
303
303
 
304
304
 
305
305
class TestCat(script.TestCaseWithTransportAndScript):
310
310
    def test_cat_input_to_output(self):
311
311
        retcode, out, err = self.run_command(['cat'],
312
312
                                             'content\n', 'content\n', None)
313
 
        self.assertEquals('content\n', out)
314
 
        self.assertEquals(None, err)
 
313
        self.assertEqual('content\n', out)
 
314
        self.assertEqual(None, err)
315
315
 
316
316
    def test_cat_file_to_output(self):
317
317
        self.build_tree_contents([('file', 'content\n')])
318
318
        retcode, out, err = self.run_command(['cat', 'file'],
319
319
                                             None, 'content\n', None)
320
 
        self.assertEquals('content\n', out)
321
 
        self.assertEquals(None, err)
 
320
        self.assertEqual('content\n', out)
 
321
        self.assertEqual(None, err)
322
322
 
323
323
    def test_cat_input_to_file(self):
324
324
        retcode, out, err = self.run_command(['cat', '>file'],
325
325
                                             'content\n', None, None)
326
326
        self.assertFileEqual('content\n', 'file')
327
 
        self.assertEquals(None, out)
328
 
        self.assertEquals(None, err)
 
327
        self.assertEqual(None, out)
 
328
        self.assertEqual(None, err)
329
329
        retcode, out, err = self.run_command(['cat', '>>file'],
330
330
                                             'more\n', None, None)
331
331
        self.assertFileEqual('content\nmore\n', 'file')
332
 
        self.assertEquals(None, out)
333
 
        self.assertEquals(None, err)
 
332
        self.assertEqual(None, out)
 
333
        self.assertEqual(None, err)
334
334
 
335
335
    def test_cat_file_to_file(self):
336
336
        self.build_tree_contents([('file', 'content\n')])
397
397
        self.assertRaises(ValueError, self.run_script, '$ cd ..')
398
398
 
399
399
    def test_cd_dir_and_back_home(self):
400
 
        self.assertEquals(self.test_dir, osutils.getcwd())
 
400
        self.assertEqual(self.test_dir, osutils.getcwd())
401
401
        self.run_script("""
402
402
$ mkdir dir
403
403
$ cd dir
404
404
""")
405
 
        self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'),
 
405
        self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
406
406
                          osutils.getcwd())
407
407
 
408
408
        self.run_script('$ cd')
409
 
        self.assertEquals(self.test_dir, osutils.getcwd())
 
409
        self.assertEqual(self.test_dir, osutils.getcwd())
410
410
 
411
411
 
412
412
class TestBzr(script.TestCaseWithTransportAndScript):
435
435
 
436
436
    def test_echo_to_output(self):
437
437
        retcode, out, err = self.run_command(['echo'], None, '\n', None)
438
 
        self.assertEquals('\n', out)
439
 
        self.assertEquals(None, err)
 
438
        self.assertEqual('\n', out)
 
439
        self.assertEqual(None, err)
440
440
 
441
441
    def test_echo_some_to_output(self):
442
442
        retcode, out, err = self.run_command(['echo', 'hello'],
443
443
                                             None, 'hello\n', None)
444
 
        self.assertEquals('hello\n', out)
445
 
        self.assertEquals(None, err)
 
444
        self.assertEqual('hello\n', out)
 
445
        self.assertEqual(None, err)
446
446
 
447
447
    def test_echo_more_output(self):
448
448
        retcode, out, err = self.run_command(
449
449
            ['echo', 'hello', 'happy', 'world'],
450
450
            None, 'hello happy world\n', None)
451
 
        self.assertEquals('hello happy world\n', out)
452
 
        self.assertEquals(None, err)
 
451
        self.assertEqual('hello happy world\n', out)
 
452
        self.assertEqual(None, err)
453
453
 
454
454
    def test_echo_appended(self):
455
455
        retcode, out, err = self.run_command(['echo', 'hello', '>file'],
456
456
                                             None, None, None)
457
 
        self.assertEquals(None, out)
458
 
        self.assertEquals(None, err)
 
457
        self.assertEqual(None, out)
 
458
        self.assertEqual(None, err)
459
459
        self.assertFileEqual('hello\n', 'file')
460
460
        retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
461
461
                                             None, None, None)
462
 
        self.assertEquals(None, out)
463
 
        self.assertEquals(None, err)
 
462
        self.assertEqual(None, out)
 
463
        self.assertEqual(None, err)
464
464
        self.assertFileEqual('hello\nhappy\n', 'file')
465
465
 
466
466
    def test_empty_line_in_output_is_respected(self):