Mercurial > hg
comparison tests/test-trusted.py @ 8144:fca54469480e
ui: introduce new config parser
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 23 Apr 2009 15:40:10 -0500 |
parents | 912bfef12ba6 |
children | 9b8ac5fb7760 |
comparison
equal
deleted
inserted
replaced
8143:507c49e297e1 | 8144:fca54469480e |
---|---|
1 # Since it's not easy to write a test that portably deals | 1 # Since it's not easy to write a test that portably deals |
2 # with files from different users/groups, we cheat a bit by | 2 # with files from different users/groups, we cheat a bit by |
3 # monkey-patching some functions in the util module | 3 # monkey-patching some functions in the util module |
4 | 4 |
5 import os | 5 import os |
6 from mercurial import ui, util | 6 from mercurial import ui, util, error |
7 | 7 |
8 hgrc = os.environ['HGRCPATH'] | 8 hgrc = os.environ['HGRCPATH'] |
9 f = open(hgrc) | 9 f = open(hgrc) |
10 basehgrc = f.read() | 10 basehgrc = f.read() |
11 f.close() | 11 f.close() |
83 os.chdir('repo') | 83 os.chdir('repo') |
84 os.mkdir('.hg') | 84 os.mkdir('.hg') |
85 f = open('.hg/hgrc', 'w') | 85 f = open('.hg/hgrc', 'w') |
86 f.write('[paths]\n') | 86 f.write('[paths]\n') |
87 f.write('local = /another/path\n\n') | 87 f.write('local = /another/path\n\n') |
88 f.write('interpolated = %(global)s%(local)s\n\n') | |
89 f.close() | 88 f.close() |
90 | 89 |
91 #print '# Everything is run by user foo, group bar\n' | 90 #print '# Everything is run by user foo, group bar\n' |
92 | 91 |
93 # same user, same group | 92 # same user, same group |
152 return 'foo' | 151 return 'foo' |
153 util.username = username | 152 util.username = username |
154 u2.readconfig('.hg/hgrc') | 153 u2.readconfig('.hg/hgrc') |
155 print 'trusted:' | 154 print 'trusted:' |
156 print u2.config('foobar', 'baz') | 155 print u2.config('foobar', 'baz') |
157 print u2.config('paths', 'interpolated') | |
158 print 'untrusted:' | 156 print 'untrusted:' |
159 print u2.config('foobar', 'baz', untrusted=True) | 157 print u2.config('foobar', 'baz', untrusted=True) |
160 print u2.config('paths', 'interpolated', untrusted=True) | |
161 | 158 |
162 print | 159 print |
163 print "# error handling" | 160 print "# error handling" |
164 | 161 |
165 def assertraises(f, exc=util.Abort): | 162 def assertraises(f, exc=util.Abort): |
177 testui(user='abc', group='def', debug=True, silent=True) | 174 testui(user='abc', group='def', debug=True, silent=True) |
178 | 175 |
179 print | 176 print |
180 print "# parse error" | 177 print "# parse error" |
181 f = open('.hg/hgrc', 'w') | 178 f = open('.hg/hgrc', 'w') |
182 f.write('foo = bar') | 179 f.write('foo') |
183 f.close() | 180 f.close() |
184 testui(user='abc', group='def', silent=True) | |
185 assertraises(lambda: testui(debug=True, silent=True)) | |
186 | 181 |
187 print | 182 try: |
188 print "# interpolation error" | 183 testui(user='abc', group='def', silent=True) |
189 f = open('.hg/hgrc', 'w') | 184 except error.ConfigError, inst: |
190 f.write('[foo]\n') | 185 print inst |
191 f.write('bar = %(') | |
192 f.close() | |
193 u = testui(debug=True, silent=True) | |
194 print '# regular config:' | |
195 print ' trusted', | |
196 assertraises(lambda: u.config('foo', 'bar')) | |
197 print 'untrusted', | |
198 assertraises(lambda: u.config('foo', 'bar', untrusted=True)) | |
199 | 186 |
200 u = testui(user='abc', group='def', debug=True, silent=True) | 187 try: |
201 print ' trusted ', | 188 testui(debug=True, silent=True) |
202 print u.config('foo', 'bar') | 189 except error.ConfigError, inst: |
203 print 'untrusted', | 190 print inst |
204 assertraises(lambda: u.config('foo', 'bar', untrusted=True)) | |
205 | |
206 print '# configitems:' | |
207 print ' trusted ', | |
208 print u.configitems('foo') | |
209 print 'untrusted', | |
210 assertraises(lambda: u.configitems('foo', untrusted=True)) | |
211 |