Commit Graph

5 Commits

Author SHA1 Message Date
Gregory Szorc
551a30c1a7 tests: use context manager form of assertRaises
Support for using unittest.TestCase.assertRaises as a context
manager was added in Python 2.7. This form is more readable,
especially for complex tests.

While I was here, I also restored the use of assertRaisesRegexp,
which was removed in 6620b26511eb for Python 2.6 compatibility.
2017-05-13 11:52:44 -07:00
Kostia Balytskyi
ff9a0dc5da 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.
2017-05-11 08:49:33 -07:00
Kostia Balytskyi
e4f8ca5106 scmutil: add simplekeyvaluefile reading test
Before this patch, mockvfs did not emulate readlines correctly
and there was no test for simplekeyvaluefile reading.
2017-05-11 08:39:44 -07:00
Kostia Balytskyi
ffc66837df tests: make test-simplekeyvaluefile.py py2.6-compatible
Python 2.6 unittest.TestCase does not have assertRaisesRegexp.
2017-03-22 11:26:23 -07:00
Kostia Balytskyi
0b0228842d scmutil: add a simple key-value file helper
The purpose of the added class is to serve purposes like save files of shelve
or state files of shelve, rebase and histedit. Keys of these files can be
alphanumeric and start with letters, while values must not contain newlines.

In light of Mercurial's reluctancy to use Python's json module, this tries
to provide a reasonable alternative for a non-nested named data.
Comparing to current approach of storing state in plain text files, where
semantic meaning of lines of text is only determined by their oreder,
simple key-value file allows for reordering lines and thus helps handle
optional values.

Initial use-case I see for this is obs-shelve's shelve files. Later we
can possibly migrate state files to this approach.

The test is in a new file beause I did not figure out where to put it
within existing test suite. If you give me a better idea, I will gladly
follow it.
2017-03-10 14:33:42 -08:00