# HG changeset patch # User Kostia Balytskyi # Date 1494517184 25200 # Node ID ed2c44741190dd8518cf92a844c9b6a0aa100bfc # Parent 24f55686a63d02965291079bf33da8a7269cadff scmutil: add simplekeyvaluefile reading test Before this patch, mockvfs did not emulate readlines correctly and there was no test for simplekeyvaluefile reading. diff -r 24f55686a63d -r ed2c44741190 mercurial/scmutil.py --- a/mercurial/scmutil.py Tue May 02 18:57:52 2017 +0200 +++ b/mercurial/scmutil.py Thu May 11 08:39:44 2017 -0700 @@ -925,7 +925,10 @@ def read(self): lines = self.vfs.readlines(self.path) try: - d = dict(line[:-1].split('=', 1) for line in lines if line) + # the 'if line.strip()' part prevents us from failing on empty + # lines which only contain '\n' therefore are not skipped + # by 'if line' + d = dict(line[:-1].split('=', 1) for line in lines if line.strip()) except ValueError as e: raise error.CorruptedState(str(e)) return d diff -r 24f55686a63d -r ed2c44741190 tests/test-simplekeyvaluefile.py --- a/tests/test-simplekeyvaluefile.py Tue May 02 18:57:52 2017 +0200 +++ b/tests/test-simplekeyvaluefile.py Thu May 11 08:39:44 2017 -0700 @@ -33,7 +33,8 @@ return mockfile(path, self).read() def readlines(self, path): - return mockfile(path, self).read().split('\n') + # lines need to contain the trailing '\n' to mock the real readlines + return [l for l in mockfile(path, self).read().splitlines(True)] def __call__(self, path, mode, atomictemp): return mockfile(path, self) @@ -42,11 +43,13 @@ def setUp(self): self.vfs = mockvfs() - def testbasicwriting(self): - d = {'key1': 'value1', 'Key2': 'value2'} - scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d) + 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() + self.assertEqual(dr, dw) def testinvalidkeys(self): d = {'0key1': 'value1', 'Key2': 'value2'}