Mercurial > public > mercurial-scm > hg
diff tests/test-simplekeyvaluefile.py @ 32270:218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
To ease migration from files with version numbers in their first lines,
we want simplekeyvaluefile to support a non-key-value first line. In this
way, old versions of Mercurial will read such files, discover a newer version
than the one they know how to handle and fail gracefully, rather than with
exception. Shelve's shelvestate file is an example.
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Thu, 11 May 2017 08:49:33 -0700 |
parents | ed2c44741190 |
children | 68c43a416585 |
line wrap: on
line diff
--- a/tests/test-simplekeyvaluefile.py Thu May 11 08:39:44 2017 -0700 +++ b/tests/test-simplekeyvaluefile.py Thu May 11 08:49:33 2017 -0700 @@ -72,5 +72,13 @@ self.assertRaises(error.CorruptedState, scmutil.simplekeyvaluefile(self.vfs, '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')\ + .read(firstlinenonkeyval=True) + self.assertEqual(dr, {'__firstline': '1.0', 'key1': 'value1'}) + if __name__ == "__main__": silenttestrunner.main(__name__)