forked from ctb/pony-build
/
test_hg_client.py
204 lines (152 loc) · 7.06 KB
/
test_hg_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import sys
import os, os.path
import shutil
import tempfile
import pprint
import urlparse
import pony_client
from pony_client import HgClone, TempDirectoryContext, _run_command
_cwd = None
def setup():
global _cwd
_cwd = os.getcwd()
def teardown():
os.chdir(_cwd)
class Test_MercurialNonCachingCheckout(object):
repository_url = 'http://bitbucket.org/cherkf/pony-build-hg-test/'
def setup(self):
# create a context within which to run the HgClone command
self.context = TempDirectoryContext()
self.context.initialize()
def teardown(self):
self.context.finish()
def test_basic(self):
"Run the HgClone command w/o caching and verify it."
command = HgClone(self.repository_url, use_cache=False)
command.verbose = True
command.run(self.context)
pprint.pprint(command.get_results()) # debugging output
os.chdir(self.context.tempdir)
assert os.path.exists(os.path.join('pony-build-hg-test', 'test1'))
assert os.path.exists(os.path.join('pony-build-hg-test', 'test2'))
def create_cache_location(repository_url):
# use os.environ to specify a new place for VCS cache stuff
temp_cache_parent = tempfile.mkdtemp()
temp_cache_location = os.path.join(temp_cache_parent, "the_cache")
os.environ['PONY_BUILD_CACHE'] = temp_cache_location
# figure out what the end checkout result should be
repository_path = urlparse.urlparse(repository_url)[2]
repository_dirname = repository_path.rstrip('/').split('/')[-1]
print 'calculated repository dirname as:', repository_dirname
(_, repository_cache) = pony_client.guess_cache_dir(repository_dirname)
assert repository_cache.startswith(temp_cache_location)
# this will create 'the_cache' directory that contains individual
# pkg caches.
pony_client.create_cache_dir(repository_cache, repository_dirname)
assert os.path.isdir(temp_cache_location)
return (temp_cache_parent, temp_cache_location)
class Test_MercurialCachingCheckout(object):
repository_url = 'http://bitbucket.org/cherkf/pony-build-hg-test/'
def setup(self):
# create a context within which to run the HgClone command
self.context = TempDirectoryContext()
self.context.initialize()
(cache_parent, cache_dir) = create_cache_location(self.repository_url)
self.cache_parent = cache_parent
def teardown(self):
self.context.finish()
del os.environ['PONY_BUILD_CACHE']
shutil.rmtree(self.cache_parent)
def test_basic(self):
"Run the HgClone command and verify that it produces the right repo."
command = HgClone(self.repository_url)
command.verbose = True
command.run(self.context)
pprint.pprint(command.get_results()) # debugging output
os.chdir(self.context.tempdir)
assert os.path.exists(os.path.join('pony-build-hg-test', 'test1'))
assert os.path.exists(os.path.join('pony-build-hg-test', 'test2'))
def test_other_branch(self):
"Run the HgClone command for another branch."
command = HgClone('http://bitbucket.org/cherkf/pony-build-hg-test/')
command.run(self.context)
#commands.getoutput('hg', 'update', 'extrabranch')
#pprint.pprint(cmdlist.get_results()) #debugging output
# check version info
results_info = command.get_results()
pprint.pprint(results_info) # debugging output
assert results_info['version_info'] == '949a4d660f2e 2 default'
assert results_info['version_type'] == 'hg'
# check files
cwd = os.getcwd()
os.chdir(self.context.tempdir)
try:
assert os.path.exists(os.path.join('pony-build-hg-test', 'test1'))
assert os.path.exists(os.path.join('pony-build-hg-test',
'test2'))
# assert os.path.exists(os.path.join('pony-build-hg-test', 'test4'))
finally:
os.chdir(cwd)
class Test_MercurialCachingUpdate(object):
repository_url = 'http://bitbucket.org/cherkf/pony-build-hg-test/'
def setup(self):
# create a context within which to run the HgClone command
self.context = TempDirectoryContext()
self.context.initialize()
(cache_parent, cache_dir) = create_cache_location(self.repository_url)
self.cache_parent = cache_parent
cwd = os.getcwd() # save current directory
#
# next, we want to set up the cached repository so that it contains an
# old checkout.
#
os.chdir(cache_dir)
# now, check out the test hg repository.
(ret, out, err) = _run_command(['hg', 'clone', self.repository_url])
assert ret == 0, (out, err)
# forcibly check out revision 7 instead of revision 1.
(ret, out, err) = _run_command(['hg', 'checkout', '7'],
cwd='pony-build-hg-test')
assert ret == 0, (out, err)
assert os.path.exists(os.path.join('pony-build-hg-test', 'test1'))
assert os.path.exists(os.path.join('pony-build-hg-test', 'test4.py'))
os.chdir(cwd) # return to working dir.
def teardown(self):
self.context.finish()
del os.environ['PONY_BUILD_CACHE']
shutil.rmtree(self.cache_parent)
def test_basic(self):
"Run the HgClone command and verify that it produces an updated repo."
command = HgClone(self.repository_url)
command.verbose = True
command.run(self.context)
pprint.pprint(command.get_results()) # debugging output
os.chdir(self.context.tempdir)
assert os.path.exists(os.path.join('pony-build-hg-test', 'test1'))
assert os.path.exists(os.path.join('pony-build-hg-test', 'test2'))
def test_other_branch(self):
"Run the HgClone command for another branch."
command = HgClone(self.repository_url)
command.run(self.context)
# forcibly check out revision 7 instead of revision 1.
(ret, out, err) = _run_command(['hg', 'checkout', '7'],
cwd='pony-build-hg-test')
(ret, out, err) = _run_command(['hg', 'identify'],
cwd='pony-build-hg-test')
#os.chdir(cwd) # return to working dir.
# check version info
results_info = command.get_results()
pprint.pprint(results_info) # debugging output
assert results_info['version_info'] == '949a4d660f2e 2 default'
assert results_info['version_type'] == 'hg'
# check files
cwd = os.getcwd()
os.chdir(self.context.tempdir)
try:
assert ret == 0, (out, err)
assert os.path.exists(os.path.join('pony-build-hg-test', 'test1'))
assert os.path.exists(os.path.join('pony-build-hg-test',
'test2'))
assert os.path.exists(os.path.join('pony-build-hg-test', 'test4.py'))
finally:
os.chdir(cwd)