##// END OF EJS Templates
tests: port remaining bits of test-parseindex2 to unittest asserts...
Augie Fackler -
r39080:88b04bd2 default
parent child Browse files
Show More
@@ -130,33 +130,35 b' def importparsers(hexversion):'
130 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
130 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
131 return p.communicate() # returns stdout, stderr
131 return p.communicate() # returns stdout, stderr
132
132
133 def printhexfail(testnumber, hexversion, stdout, expected):
133 def hexfailmsg(testnumber, hexversion, stdout, expected):
134 try:
134 try:
135 hexstring = hex(hexversion)
135 hexstring = hex(hexversion)
136 except TypeError:
136 except TypeError:
137 hexstring = None
137 hexstring = None
138 print("FAILED: version test #%s with Python %s and patched "
138 return ("FAILED: version test #%s with Python %s and patched "
139 "sys.hexversion %r (%r):\n Expected %s but got:\n-->'%s'\n" %
139 "sys.hexversion %r (%r):\n Expected %s but got:\n-->'%s'\n" %
140 (testnumber, sys.version_info, hexversion, hexstring, expected,
140 (testnumber, sys.version_info, hexversion, hexstring, expected,
141 stdout))
141 stdout))
142
143 def testversionokay(testnumber, hexversion):
144 stdout, stderr = importparsers(hexversion)
145 if stdout:
146 printhexfail(testnumber, hexversion, stdout, expected="no stdout")
147
148 def testversionfail(testnumber, hexversion):
149 stdout, stderr = importparsers(hexversion)
150 # We include versionerrortext to distinguish from other ImportErrors.
151 errtext = b"ImportError: %s" % pycompat.sysbytes(parsers.versionerrortext)
152 if errtext not in stdout:
153 printhexfail(testnumber, hexversion, stdout,
154 expected="stdout to contain %r" % errtext)
155
142
156 def makehex(major, minor, micro):
143 def makehex(major, minor, micro):
157 return int("%x%02x%02x00" % (major, minor, micro), 16)
144 return int("%x%02x%02x00" % (major, minor, micro), 16)
158
145
159 class parseindex2tests(unittest.TestCase):
146 class parseindex2tests(unittest.TestCase):
147
148 def assertversionokay(self, testnumber, hexversion):
149 stdout, stderr = importparsers(hexversion)
150 self.assertFalse(
151 stdout, hexfailmsg(testnumber, hexversion, stdout, 'no stdout'))
152
153 def assertversionfail(self, testnumber, hexversion):
154 stdout, stderr = importparsers(hexversion)
155 # We include versionerrortext to distinguish from other ImportErrors.
156 errtext = b"ImportError: %s" % pycompat.sysbytes(
157 parsers.versionerrortext)
158 self.assertIn(errtext, stdout,
159 hexfailmsg(testnumber, hexversion, stdout,
160 expected="stdout to contain %r" % errtext))
161
160 def testversiondetection(self):
162 def testversiondetection(self):
161 """Check the version-detection logic when importing parsers."""
163 """Check the version-detection logic when importing parsers."""
162 # Only test the version-detection logic if it is present.
164 # Only test the version-detection logic if it is present.
@@ -167,12 +169,12 b' class parseindex2tests(unittest.TestCase'
167 info = sys.version_info
169 info = sys.version_info
168 major, minor, micro = info[0], info[1], info[2]
170 major, minor, micro = info[0], info[1], info[2]
169 # Test same major-minor versions.
171 # Test same major-minor versions.
170 testversionokay(1, makehex(major, minor, micro))
172 self.assertversionokay(1, makehex(major, minor, micro))
171 testversionokay(2, makehex(major, minor, micro + 1))
173 self.assertversionokay(2, makehex(major, minor, micro + 1))
172 # Test different major-minor versions.
174 # Test different major-minor versions.
173 testversionfail(3, makehex(major + 1, minor, micro))
175 self.assertversionfail(3, makehex(major + 1, minor, micro))
174 testversionfail(4, makehex(major, minor + 1, micro))
176 self.assertversionfail(4, makehex(major, minor + 1, micro))
175 testversionfail(5, "'foo'")
177 self.assertversionfail(5, "'foo'")
176
178
177 def testbadargs(self):
179 def testbadargs(self):
178 # Check that parse_index2() raises TypeError on bad arguments.
180 # Check that parse_index2() raises TypeError on bad arguments.
General Comments 0
You need to be logged in to leave comments. Login now