[PATCH 1 of 4 shelve-ext v4] scmutil: add simplekeyvaluefile reading test

Yuya Nishihara yuya at tcha.org
Thu May 11 09:26:01 EDT 2017


On Sun, 7 May 2017 06:07:03 -0700, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia at fb.com>
> # Date 1494157223 25200
> #      Sun May 07 04:40:23 2017 -0700
> # Node ID e9b77b6f16c04efced06169735a813d5db82dddf
> # Parent  31f42e683321f225eb9c306f8d4b3a9e8d82a1da
> scmutil: add simplekeyvaluefile reading test
> 
> Before this patch, mockvfs did not emulate readlines correctly
> and there was no test for simplekeyvaluefile reading.
> 
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -925,7 +925,10 @@ class simplekeyvaluefile(object):
>      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 --git a/tests/test-simplekeyvaluefile.py b/tests/test-simplekeyvaluefile.py
> --- a/tests/test-simplekeyvaluefile.py
> +++ b/tests/test-simplekeyvaluefile.py
> @@ -33,7 +33,8 @@ class mockvfs(object):
>          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 + '\n' for l in mockfile(path, self).read().split('\n')]

Just a nit. this could be .splitlines(keepends=True)


More information about the Mercurial-devel mailing list