1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
1 |
"""Black-box tests for default log_formats/log_formatters
|
2 |
"""
|
|
3 |
||
4 |
import os |
|
5 |
||
6 |
from bzrlib.branch import Branch |
|
7 |
from bzrlib.tests import TestCaseInTempDir |
|
1551.2.48
by abentley
Used ensure_config_dir exists instead of makedirs |
8 |
from bzrlib.config import (ensure_config_dir_exists, config_filename) |
1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
9 |
|
10 |
||
11 |
class TestLogFormats(TestCaseInTempDir): |
|
12 |
||
13 |
def bzr(self, *args, **kwargs): |
|
14 |
return self.run_bzr(*args, **kwargs)[0] |
|
15 |
||
16 |
def test_log_default_format(self): |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
17 |
self.setup_config() |
1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
18 |
|
19 |
self.bzr('init') |
|
20 |
open('a', 'wb').write('foo\n') |
|
21 |
self.bzr('add', 'a') |
|
22 |
||
23 |
self.bzr('commit', '-m', '1') |
|
24 |
open('a', 'wb').write('baz\n') |
|
25 |
||
26 |
self.bzr('commit', '-m', '2') |
|
27 |
||
28 |
# only the lines formatter is this short
|
|
29 |
self.assertEquals(3, len(self.bzr('log').split('\n'))) |
|
30 |
||
31 |
def test_log_format_arg(self): |
|
32 |
self.bzr('init') |
|
33 |
open('a', 'wb').write('foo\n') |
|
34 |
self.bzr('add', 'a') |
|
35 |
||
36 |
self.bzr('commit', '-m', '1') |
|
37 |
open('a', 'wb').write('baz\n') |
|
38 |
||
39 |
self.bzr('commit', '-m', '2') |
|
40 |
||
41 |
# only the lines formatter is this short
|
|
42 |
self.assertEquals(7, len(self.bzr('log', '--log-format', 'short').split('\n'))) |
|
43 |
||
44 |
def test_missing_default_format(self): |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
45 |
self.setup_config() |
1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
46 |
|
47 |
os.mkdir('a') |
|
48 |
os.chdir('a') |
|
49 |
self.bzr('init') |
|
50 |
||
51 |
open('a', 'wb').write('foo\n') |
|
52 |
self.bzr('add', 'a') |
|
53 |
self.bzr('commit', '-m', '1') |
|
54 |
||
55 |
os.chdir('..') |
|
56 |
self.bzr('branch', 'a', 'b') |
|
57 |
os.chdir('a') |
|
58 |
||
59 |
open('a', 'wb').write('bar\n') |
|
60 |
self.bzr('commit', '-m', '2') |
|
61 |
||
62 |
open('a', 'wb').write('baz\n') |
|
63 |
self.bzr('commit', '-m', '3') |
|
64 |
||
65 |
os.chdir('../b') |
|
66 |
||
67 |
self.assertEquals(5, len(self.bzr('missing', retcode=1).split('\n'))) |
|
68 |
||
69 |
os.chdir('..') |
|
70 |
||
71 |
def test_missing_format_arg(self): |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
72 |
self.setup_config() |
1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
73 |
|
74 |
os.mkdir('a') |
|
75 |
os.chdir('a') |
|
76 |
self.bzr('init') |
|
77 |
||
78 |
open('a', 'wb').write('foo\n') |
|
79 |
self.bzr('add', 'a') |
|
80 |
self.bzr('commit', '-m', '1') |
|
81 |
||
82 |
os.chdir('..') |
|
83 |
self.bzr('branch', 'a', 'b') |
|
84 |
os.chdir('a') |
|
85 |
||
86 |
open('a', 'wb').write('bar\n') |
|
87 |
self.bzr('commit', '-m', '2') |
|
88 |
||
89 |
open('a', 'wb').write('baz\n') |
|
90 |
self.bzr('commit', '-m', '3') |
|
91 |
||
92 |
os.chdir('../b') |
|
93 |
||
94 |
self.assertEquals(9, len(self.bzr('missing', '--log-format', 'short', retcode=1).split('\n'))) |
|
95 |
||
96 |
os.chdir('..') |
|
97 |
||
98 |
||
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
99 |
def setup_config(self): |
1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
100 |
if os.path.isfile(config_filename()): |
101 |
# Something is wrong in environment,
|
|
102 |
# we risk overwriting users config
|
|
103 |
self.assert_(config_filename() + "exists, abort") |
|
104 |
||
1551.2.48
by abentley
Used ensure_config_dir exists instead of makedirs |
105 |
ensure_config_dir_exists() |
1553.2.11
by Erik Bågfors
blackbox tests for default log format and log-format arguments |
106 |
CONFIG=("[DEFAULT]\n" |
107 |
"email=Joe Foo <joe@foo.com>\n" |
|
108 |
"log_format=line\n") |
|
109 |
||
110 |
open(config_filename(),'wb').write(CONFIG) |