Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: infra/libs/git2/test/config_ref_test.py

Issue 355153002: Refactor infra git libs and testing. (Closed) Base URL: https://chromium.googlesource.com/infra/infra@fake_testing_support
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from infra.services.gnumbd.support import config_ref, git 5 from infra.libs import git2
6 from infra.services.gnumbd.test import git_test
7 6
agable 2014/06/27 18:53:12 nit: no newlines I thought our policy was: * buil
8 class TestConfigRef(git_test.TestBasis): 7 from infra.libs.git2 import config_ref
8
9 from infra.libs.git2.test import git2_test
10
agable 2014/06/27 18:53:12 nit: two newlines Also I'm not gonna comment on e
11 class TestConfigRef(git2_test.TestBasis):
9 def writeConfig(self, config_data): 12 def writeConfig(self, config_data):
10 ref = 'refs/metaconfig' 13 ref = 'refs/metaconfig'
11 def inner(): 14 def inner():
12 g = self.repo.git 15 g = self.repo.git
13 if g('rev-parse', ref).stdout.strip() != ref: 16 if g('rev-parse', ref).stdout.strip() != ref:
14 g('checkout', ref) 17 g('checkout', ref)
15 else: 18 else:
16 g('checkout', '--orphan', 'config') 19 g('checkout', '--orphan', 'config')
17 g('rm', '-rf', '.') 20 g('rm', '-rf', '.')
18 with open('config.json', 'w') as f: 21 with open('config.json', 'w') as f:
19 f.write(config_data) 22 f.write(config_data)
20 g('add', 'config.json') 23 g('add', 'config.json')
21 self.repo.git_commit('a bad config file') 24 self.repo.git_commit('a bad config file')
22 g('update-ref', ref, 'HEAD') 25 g('update-ref', ref, 'HEAD')
23 self.repo.run(inner) 26 self.repo.run(inner)
24 27
25 def testNonExist(self): 28 def testNonExist(self):
26 r = self.mkRepo() 29 r = self.mkRepo()
27 c = config_ref.ConfigRef(git.Ref(r, 'refs/metaconfig')) 30 c = config_ref.ConfigRef(git2.Ref(r, 'refs/metaconfig'))
28 self.assertEqual(c.current, c.DEFAULTS) 31 self.assertEqual(c.current, c.DEFAULTS)
29 self.assertEqual(c['interval'], c.DEFAULTS['interval']) 32 self.assertEqual(c['interval'], c.DEFAULTS['interval'])
30 33
31 def testExistsBad(self): 34 def testExistsBad(self):
32 self.writeConfig("not valid config") 35 self.writeConfig("not valid config")
33 r = self.mkRepo() 36 r = self.mkRepo()
34 c = config_ref.ConfigRef(git.Ref(r, 'refs/metaconfig')) 37 c = config_ref.ConfigRef(git2.Ref(r, 'refs/metaconfig'))
35 c.evaluate() 38 c.evaluate()
36 self.assertEqual(c.current, c.DEFAULTS) 39 self.assertEqual(c.current, c.DEFAULTS)
37 40
38 self.writeConfig("[]") 41 self.writeConfig("[]")
39 self.capture_stdio(r.run, 'fetch') 42 self.capture_stdio(r.run, 'fetch')
40 c.evaluate() 43 c.evaluate()
41 self.assertEqual(c.current, c.DEFAULTS) 44 self.assertEqual(c.current, c.DEFAULTS)
42 45
43 def testExistsGood(self): 46 def testExistsGood(self):
44 self.writeConfig('{"interval": 100}') 47 self.writeConfig('{"interval": 100}')
45 r = self.mkRepo() 48 r = self.mkRepo()
46 c = config_ref.ConfigRef(git.Ref(r, 'refs/metaconfig')) 49 c = config_ref.ConfigRef(git2.Ref(r, 'refs/metaconfig'))
47 self.assertAlmostEqual(c['interval'], 100.0) 50 self.assertAlmostEqual(c['interval'], 100.0)
48 51
49 self.writeConfig('{"interval": "cat"}') 52 self.writeConfig('{"interval": "cat"}')
50 self.capture_stdio(r.run, 'fetch') 53 self.capture_stdio(r.run, 'fetch')
51 c.evaluate() 54 c.evaluate()
52 self.assertAlmostEqual(c['interval'], 100.0) 55 self.assertAlmostEqual(c['interval'], 100.0)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698