changeset 37939:6eca47f6319d

tests: port test-simplekeyvaluefile.py to Python 3 # skip-blame just b prefixes Differential Revision: https://phab.mercurial-scm.org/D3528
author Augie Fackler <augie@google.com>
date Fri, 27 Apr 2018 13:43:59 -0400
parents ac865f020b99
children 31c37e703cee
files contrib/python3-whitelist tests/test-simplekeyvaluefile.py
diffstat 2 files changed, 19 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/python3-whitelist	Fri Apr 27 13:39:45 2018 -0400
+++ b/contrib/python3-whitelist	Fri Apr 27 13:43:59 2018 -0400
@@ -426,6 +426,7 @@
 test-show-work.t
 test-show.t
 test-simple-update.t
+test-simplekeyvaluefile.py
 test-simplemerge.py
 test-single-head.t
 test-sparse-clear.t
--- a/tests/test-simplekeyvaluefile.py	Fri Apr 27 13:39:45 2018 -0400
+++ b/tests/test-simplekeyvaluefile.py	Fri Apr 27 13:43:59 2018 -0400
@@ -44,11 +44,11 @@
         self.vfs = mockvfs()
 
     def testbasicwritingiandreading(self):
-        dw = {'key1': 'value1', 'Key2': 'value2'}
-        scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(dw)
-        self.assertEqual(sorted(self.vfs.read('kvfile').split('\n')),
-                         ['', 'Key2=value2', 'key1=value1'])
-        dr = scmutil.simplekeyvaluefile(self.vfs, 'kvfile').read()
+        dw = {b'key1': b'value1', b'Key2': b'value2'}
+        scmutil.simplekeyvaluefile(self.vfs, b'kvfile').write(dw)
+        self.assertEqual(sorted(self.vfs.read(b'kvfile').split(b'\n')),
+                         [b'', b'Key2=value2', b'key1=value1'])
+        dr = scmutil.simplekeyvaluefile(self.vfs, b'kvfile').read()
         self.assertEqual(dr, dw)
 
     if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
@@ -58,33 +58,33 @@
             unittest.TestCase.assertRaisesRegexp)
 
     def testinvalidkeys(self):
-        d = {'0key1': 'value1', 'Key2': 'value2'}
+        d = {b'0key1': b'value1', b'Key2': b'value2'}
         with self.assertRaisesRegex(error.ProgrammingError,
                                      'keys must start with a letter.*'):
-            scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
+            scmutil.simplekeyvaluefile(self.vfs, b'kvfile').write(d)
 
-        d = {'key1@': 'value1', 'Key2': 'value2'}
+        d = {b'key1@': b'value1', b'Key2': b'value2'}
         with self.assertRaisesRegex(error.ProgrammingError, 'invalid key.*'):
-            scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
+            scmutil.simplekeyvaluefile(self.vfs, b'kvfile').write(d)
 
     def testinvalidvalues(self):
-        d = {'key1': 'value1', 'Key2': 'value2\n'}
+        d = {b'key1': b'value1', b'Key2': b'value2\n'}
         with self.assertRaisesRegex(error.ProgrammingError,  'invalid val.*'):
-            scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
+            scmutil.simplekeyvaluefile(self.vfs, b'kvfile').write(d)
 
     def testcorruptedfile(self):
-        self.vfs.contents['badfile'] = 'ababagalamaga\n'
+        self.vfs.contents[b'badfile'] = b'ababagalamaga\n'
         with self.assertRaisesRegex(error.CorruptedState,
                                      'dictionary.*element.*'):
-            scmutil.simplekeyvaluefile(self.vfs, 'badfile').read()
+            scmutil.simplekeyvaluefile(self.vfs, b'badfile').read()
 
     def testfirstline(self):
-        dw = {'key1': 'value1'}
-        scmutil.simplekeyvaluefile(self.vfs, 'fl').write(dw, firstline='1.0')
-        self.assertEqual(self.vfs.read('fl'), '1.0\nkey1=value1\n')
-        dr = scmutil.simplekeyvaluefile(self.vfs, 'fl')\
+        dw = {b'key1': b'value1'}
+        scmutil.simplekeyvaluefile(self.vfs, b'fl').write(dw, firstline=b'1.0')
+        self.assertEqual(self.vfs.read(b'fl'), b'1.0\nkey1=value1\n')
+        dr = scmutil.simplekeyvaluefile(self.vfs, b'fl')\
                     .read(firstlinenonkeyval=True)
-        self.assertEqual(dr, {'__firstline': '1.0', 'key1': 'value1'})
+        self.assertEqual(dr, {b'__firstline': b'1.0', b'key1': b'value1'})
 
 if __name__ == "__main__":
     silenttestrunner.main(__name__)