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

Side by Side Diff: tests/gclient_smoketest.py

Issue 2092012: Add basic gclient smoke tests. (Closed)
Patch Set: Rename the file to a better name Created 10 years, 7 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
« no previous file with comments | « tests/fake_repos.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Smoke tests for gclient.py.
7
8 Shell out 'gclient' and run basic conformance tests.
9
10 This test assumes GClientSmokeBase.URL_BASE is valid.
11 """
12
13 import os
14 import shutil
15 import subprocess
16 import sys
17 import unittest
18
19 from fake_repos import rmtree, FakeRepos
20
21 SHOULD_LEAK = False
22 UNITTEST_DIR = os.path.abspath(os.path.dirname(__file__))
23 GCLIENT_PATH = os.path.join(os.path.dirname(UNITTEST_DIR), 'gclient')
24 # all tests outputs goes there.
25 TRIAL_DIR = os.path.join(UNITTEST_DIR, '_trial')
26 # In case you want to use another machine to create the fake repos, e.g.
27 # not on Windows.
28 HOST = '127.0.0.1'
29
30
31 class GClientSmokeBase(unittest.TestCase):
32 # This subversion repository contains a test repository.
33 ROOT_DIR = os.path.join(TRIAL_DIR, 'smoke')
34
35 def setUp(self):
36 # Vaguely inspired by twisted.
37 # Make sure it doesn't try to auto update when testing!
38 self.env = os.environ.copy()
39 self.env['DEPOT_TOOLS_UPDATE'] = '0'
40 # Remove left overs
41 self.root_dir = os.path.join(self.ROOT_DIR, self.id())
42 rmtree(self.root_dir)
43 if not os.path.exists(self.ROOT_DIR):
44 os.mkdir(self.ROOT_DIR)
45 os.mkdir(self.root_dir)
46 self.svn_base = 'svn://%s/svn/' % HOST
47 self.git_base = 'git://%s/git/' % HOST
48
49 def tearDown(self):
50 if not SHOULD_LEAK:
51 rmtree(self.root_dir)
52
53 def gclient(self, cmd, cwd=None):
54 if not cwd:
55 cwd = self.root_dir
56 process = subprocess.Popen([GCLIENT_PATH] + cmd, cwd=cwd, env=self.env,
57 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
58 shell=sys.platform.startswith('win'))
59 (stdout, stderr) = process.communicate()
60 return (stdout, stderr, process.returncode)
61
62 def check(self, expected, results):
63 def checkString(expected, result):
64 if expected != result:
65 while expected and result and expected[0] == result[0]:
66 expected = expected[1:]
67 result = result[1:]
68 self.assertEquals(expected, result)
69 checkString(expected[0], results[0])
70 checkString(expected[1], results[1])
71 self.assertEquals(expected[2], results[2])
72
73
74 class GClientSmoke(GClientSmokeBase):
75 def testCommands(self):
76 """This test is to make sure no new command was added."""
77 result = self.gclient(['help'])
78 self.assertEquals(3189, len(result[0]))
79 self.assertEquals(0, len(result[1]))
80 self.assertEquals(0, result[2])
81
82 def testNotConfigured(self):
83 res = ("", "Error: client not configured; see 'gclient config'\n", 1)
84 self.check(res, self.gclient(['cleanup']))
85 self.check(res, self.gclient(['diff']))
86 self.check(res, self.gclient(['export', 'foo']))
87 self.check(res, self.gclient(['pack']))
88 self.check(res, self.gclient(['revert']))
89 self.check(res, self.gclient(['revinfo']))
90 self.check(res, self.gclient(['runhooks']))
91 self.check(res, self.gclient(['status']))
92 self.check(res, self.gclient(['sync']))
93 self.check(res, self.gclient(['update']))
94
95
96 class GClientSmokeSync(GClientSmokeBase):
97 """sync is the most important command. Hence test it more."""
98 def testSyncSvn(self):
99 """Test pure gclient svn checkout, example of Chromium checkout"""
100 self.gclient(['config', self.svn_base + 'trunk/src/'])
101 results = self.gclient(['sync'])
102 self.assertEquals(0, results[2])
103 results = self.gclient(['sync', '--revision', 'a@32'])
104 self.assertEquals(0, results[2])
105
106 def testSyncGit(self):
107 """Test pure gclient git checkout, example of Chromium OS checkout"""
108 self.gclient(['config', self.git_base + 'repo_1'])
109 results = self.gclient(['sync'])
110 print results[0]
111 print results[1]
112 self.assertEquals(0, results[2])
113
114
115 class GClientSmokeRevert(GClientSmokeBase):
116 """revert is the second most important command. Hence test it more."""
117 def setUp(self):
118 GClientSmokeBase.setUp(self)
119 self.gclient(['config', self.URL_BASE])
120
121
122 class GClientSmokeRevInfo(GClientSmokeBase):
123 """revert is the second most important command. Hence test it more."""
124 def setUp(self):
125 GClientSmokeBase.setUp(self)
126 self.gclient(['config', self.URL_BASE])
127
128
129 if __name__ == '__main__':
130 fake = FakeRepos(TRIAL_DIR, SHOULD_LEAK, True)
131 try:
132 fake.setUp()
133 unittest.main()
134 finally:
135 fake.tearDown()
OLDNEW
« no previous file with comments | « tests/fake_repos.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698