changeset 38989:01966d45b45e

tests: start moving test-parseindex2.py to a unittest Using 2-space indents in this revision to make the code motion easier to review. I'll fix it in the next commit. Differential Revision: https://phab.mercurial-scm.org/D4176
author Augie Fackler <augie@google.com>
date Thu, 09 Aug 2018 12:58:25 -0400
parents 1aab0007a7c0
children 087a755310c3
files tests/test-parseindex2.py
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-parseindex2.py	Thu Aug 09 12:10:34 2018 -0400
+++ b/tests/test-parseindex2.py	Thu Aug 09 12:58:25 2018 -0400
@@ -8,6 +8,7 @@
 import struct
 import subprocess
 import sys
+import unittest
 
 from mercurial.node import (
     nullid,
@@ -155,8 +156,14 @@
 def makehex(major, minor, micro):
     return int("%x%02x%02x00" % (major, minor, micro), 16)
 
-def runversiontests():
+class parseindex2tests(unittest.TestCase):
+  def testversiondetection(self):
     """Check the version-detection logic when importing parsers."""
+    # Only test the version-detection logic if it is present.
+    try:
+        parsers.versionerrortext
+    except AttributeError:
+        return
     info = sys.version_info
     major, minor, micro = info[0], info[1], info[2]
     # Test same major-minor versions.
@@ -167,15 +174,7 @@
     testversionfail(4, makehex(major, minor + 1, micro))
     testversionfail(5, "'foo'")
 
-def runtest() :
-    # Only test the version-detection logic if it is present.
-    try:
-        parsers.versionerrortext
-    except AttributeError:
-        pass
-    else:
-        runversiontests()
-
+  def testbadargs(self):
     # Check that parse_index2() raises TypeError on bad arguments.
     try:
         parse_index2(0, True)
@@ -184,6 +183,7 @@
     else:
         print("Expected to get TypeError.")
 
+  def testparseindexfile(self):
    # Check parsers.parse_index2() on an index file against the original
    # Python implementation of parseindex, both with and without inlined data.
 
@@ -211,6 +211,7 @@
             # pure version doesn't support this
             break
 
+if __name__ == '__main__':
+    import silenttestrunner
+    silenttestrunner.main(__name__)
     print("done")
-
-runtest()