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

Side by Side Diff: recipe_engine/third_party/setuptools/tests/test_svn.py

Issue 1344583003: Recipe package system. (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Recompiled proto Created 5 years, 3 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
(Empty)
1 # -*- coding: utf-8 -*-
2 """svn tests"""
3
4 import io
5 import os
6 import subprocess
7 import sys
8 import unittest
9 from setuptools.tests import environment
10 from setuptools.compat import unicode, unichr
11
12 from setuptools import svn_utils
13 from setuptools.tests.py26compat import skipIf
14
15
16 def _do_svn_check():
17 try:
18 subprocess.check_call(["svn", "--version"],
19 shell=(sys.platform == 'win32'))
20 return True
21 except (OSError, subprocess.CalledProcessError):
22 return False
23 _svn_check = _do_svn_check()
24
25
26 class TestSvnVersion(unittest.TestCase):
27
28 def test_no_svn_found(self):
29 path_variable = None
30 for env in os.environ:
31 if env.lower() == 'path':
32 path_variable = env
33
34 if path_variable is None:
35 try:
36 self.skipTest('Cannot figure out how to modify path')
37 except AttributeError: # PY26 doesn't have this
38 return
39
40 old_path = os.environ[path_variable]
41 os.environ[path_variable] = ''
42 try:
43 version = svn_utils.SvnInfo.get_svn_version()
44 self.assertEqual(version, '')
45 finally:
46 os.environ[path_variable] = old_path
47
48 @skipIf(not _svn_check, "No SVN to text, in the first place")
49 def test_svn_should_exist(self):
50 version = svn_utils.SvnInfo.get_svn_version()
51 self.assertNotEqual(version, '')
52
53 def _read_utf8_file(path):
54 fileobj = None
55 try:
56 fileobj = io.open(path, 'r', encoding='utf-8')
57 data = fileobj.read()
58 return data
59 finally:
60 if fileobj:
61 fileobj.close()
62
63
64 class ParserInfoXML(unittest.TestCase):
65
66 def parse_tester(self, svn_name, ext_spaces):
67 path = os.path.join('setuptools', 'tests',
68 'svn_data', svn_name + '_info.xml')
69 #Remember these are pre-generated to test XML parsing
70 # so these paths might not valid on your system
71 example_base = "%s_example" % svn_name
72
73 data = _read_utf8_file(path)
74
75 expected = set([
76 ("\\".join((example_base, 'a file')), 'file'),
77 ("\\".join((example_base, 'folder')), 'dir'),
78 ("\\".join((example_base, 'folder', 'lalala.txt')), 'file'),
79 ("\\".join((example_base, 'folder', 'quest.txt')), 'file'),
80 ])
81 self.assertEqual(set(x for x in svn_utils.parse_dir_entries(data)),
82 expected)
83
84 def test_svn13(self):
85 self.parse_tester('svn13', False)
86
87 def test_svn14(self):
88 self.parse_tester('svn14', False)
89
90 def test_svn15(self):
91 self.parse_tester('svn15', False)
92
93 def test_svn16(self):
94 self.parse_tester('svn16', True)
95
96 def test_svn17(self):
97 self.parse_tester('svn17', True)
98
99 def test_svn18(self):
100 self.parse_tester('svn18', True)
101
102 class ParserExternalXML(unittest.TestCase):
103
104 def parse_tester(self, svn_name, ext_spaces):
105 path = os.path.join('setuptools', 'tests',
106 'svn_data', svn_name + '_ext_list.xml')
107 example_base = svn_name + '_example'
108 data = _read_utf8_file(path)
109
110 if ext_spaces:
111 folder2 = 'third party2'
112 folder3 = 'third party3'
113 else:
114 folder2 = 'third_party2'
115 folder3 = 'third_party3'
116
117 expected = set([
118 os.sep.join((example_base, folder2)),
119 os.sep.join((example_base, folder3)),
120 # folder is third_party大介
121 os.sep.join((example_base,
122 unicode('third_party') +
123 unichr(0x5927) + unichr(0x4ecb))),
124 os.sep.join((example_base, 'folder', folder2)),
125 os.sep.join((example_base, 'folder', folder3)),
126 os.sep.join((example_base, 'folder',
127 unicode('third_party') +
128 unichr(0x5927) + unichr(0x4ecb))),
129 ])
130
131 expected = set(os.path.normpath(x) for x in expected)
132 dir_base = os.sep.join(('C:', 'development', 'svn_example'))
133 self.assertEqual(set(x for x
134 in svn_utils.parse_externals_xml(data, dir_base)), expected)
135
136 def test_svn15(self):
137 self.parse_tester('svn15', False)
138
139 def test_svn16(self):
140 self.parse_tester('svn16', True)
141
142 def test_svn17(self):
143 self.parse_tester('svn17', True)
144
145 def test_svn18(self):
146 self.parse_tester('svn18', True)
147
148
149 class ParseExternal(unittest.TestCase):
150
151 def parse_tester(self, svn_name, ext_spaces):
152 path = os.path.join('setuptools', 'tests',
153 'svn_data', svn_name + '_ext_list.txt')
154 data = _read_utf8_file(path)
155
156 if ext_spaces:
157 expected = set(['third party2', 'third party3',
158 'third party3b', 'third_party'])
159 else:
160 expected = set(['third_party2', 'third_party3', 'third_party'])
161
162 self.assertEqual(set(x for x in svn_utils.parse_external_prop(data)),
163 expected)
164
165 def test_svn13(self):
166 self.parse_tester('svn13', False)
167
168 def test_svn14(self):
169 self.parse_tester('svn14', False)
170
171 def test_svn15(self):
172 self.parse_tester('svn15', False)
173
174 def test_svn16(self):
175 self.parse_tester('svn16', True)
176
177 def test_svn17(self):
178 self.parse_tester('svn17', True)
179
180 def test_svn18(self):
181 self.parse_tester('svn18', True)
182
183
184 class TestSvn(environment.ZippedEnvironment):
185
186 def setUp(self):
187 version = svn_utils.SvnInfo.get_svn_version()
188 if not version: # empty or null
189 self.dataname = None
190 self.datafile = None
191 return
192
193 self.base_version = tuple([int(x) for x in version.split('.')[:2]])
194
195 if self.base_version < (1,3):
196 raise ValueError('Insufficient SVN Version %s' % version)
197 elif self.base_version >= (1,9):
198 #trying the latest version
199 self.base_version = (1,8)
200
201 self.dataname = "svn%i%i_example" % self.base_version
202 self.datafile = os.path.join('setuptools', 'tests',
203 'svn_data', self.dataname + ".zip")
204 super(TestSvn, self).setUp()
205
206 @skipIf(not _svn_check, "No SVN to text, in the first place")
207 def test_revision(self):
208 rev = svn_utils.SvnInfo.load('.').get_revision()
209 self.assertEqual(rev, 6)
210
211 @skipIf(not _svn_check, "No SVN to text, in the first place")
212 def test_entries(self):
213 expected = set([
214 (os.path.join('a file'), 'file'),
215 (os.path.join('folder'), 'dir'),
216 (os.path.join('folder', 'lalala.txt'), 'file'),
217 (os.path.join('folder', 'quest.txt'), 'file'),
218 #The example will have a deleted file (or should)
219 #but shouldn't return it
220 ])
221 info = svn_utils.SvnInfo.load('.')
222 self.assertEqual(set(x for x in info.entries), expected)
223
224 @skipIf(not _svn_check, "No SVN to text, in the first place")
225 def test_externals(self):
226 if self.base_version >= (1,6):
227 folder2 = 'third party2'
228 folder3 = 'third party3'
229 else:
230 folder2 = 'third_party2'
231 folder3 = 'third_party3'
232
233 expected = set([
234 os.path.join(folder2),
235 os.path.join(folder3),
236 os.path.join('third_party'),
237 os.path.join('folder', folder2),
238 os.path.join('folder', folder3),
239 os.path.join('folder', 'third_party'),
240 ])
241 info = svn_utils.SvnInfo.load('.')
242 self.assertEqual(set([x for x in info.externals]), expected)
243
244 def test_suite():
245 return unittest.defaultTestLoader.loadTestsFromName(__name__)
OLDNEW
« no previous file with comments | « recipe_engine/third_party/setuptools/tests/test_sdist.py ('k') | recipe_engine/third_party/setuptools/tests/test_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698