[Piglit] [PATCH v2 2/2] framework/backends/json.py: preserve 'tests' order

Dylan Baker dylan at pnwbakers.com
Thu Feb 9 22:51:46 UTC 2017


Thanks for making those changes for me.

I still have one tiny nit. Otherwise both patches are:
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>

I think I've asked before, but do you have commit access, or would you like me
to commit? If you need me to push for you I'll fix my nit before I push.

Dylan

Quoting Tomi Sarvela (2017-02-09 10:22:19)
> Use OrderedDict when reading tests data in.
> ---
>  framework/backends/json.py | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/framework/backends/json.py b/framework/backends/json.py
> index 174c0ca..e687df7 100644
> --- a/framework/backends/json.py
> +++ b/framework/backends/json.py
> @@ -125,6 +125,10 @@ class JSONBackend(FileBackend):
>          containers that are still open and closes the file
>  
>          """
> +        tests_dir = os.path.join(self._dest, 'tests')
> +        file_list = sorted(os.listdir(tests_dir),key=
> +                           lambda p: int(os.path.splitext(p)[0]))

This should be:

           file_list = sorted(os.listdir(tests_dir),
                              key=lambda p: int(os.path.splitext(p)[0]))

And there's another instance at the bottom of this patch.

> +
>          # If jsonstreams is not present then build a complete tree of all of
>          # the data and write it with json.dump
>          if not _STREAMS:
> @@ -143,9 +147,8 @@ class JSONBackend(FileBackend):
>              # Add the tests to the dictionary
>              data['tests'] = collections.OrderedDict()
>  
> -            test_dir = os.path.join(self._dest, 'tests')
> -            for test in os.listdir(test_dir):
> -                test = os.path.join(test_dir, test)
> +            for test in file_list:
> +                test = os.path.join(tests_dir, test)
>                  if os.path.isfile(test):
>                      # Try to open the json snippets. If we fail to open a test
>                      # then throw the whole thing out. This gives us atomic
> @@ -177,15 +180,14 @@ class JSONBackend(FileBackend):
>                      s.write('__type__', 'TestrunResult')
>                      with open(os.path.join(self._dest, 'metadata.json'),
>                                'r') as n:
> -                        s.iterwrite(six.iteritems(json.load(n)))
> +                        s.iterwrite(six.iteritems(json.load(n, object_pairs_hook=collections.OrderedDict)))
>  
>                      if metadata:
>                          s.iterwrite(six.iteritems(metadata))
>  
> -                    test_dir = os.path.join(self._dest, 'tests')
>                      with s.subobject('tests') as t:
> -                        for test in os.listdir(test_dir):
> -                            test = os.path.join(test_dir, test)
> +                        for test in file_list:
> +                            test = os.path.join(tests_dir, test)
>                              if os.path.isfile(test):
>                                  try:
>                                      with open(test, 'r') as f:
> @@ -259,7 +261,7 @@ def _load(results_file):
>  
>      """
>      try:
> -        result = json.load(results_file)
> +        result = json.load(results_file, object_pairs_hook=collections.OrderedDict)
>      except ValueError as e:
>          raise exceptions.PiglitFatalError(
>              'While loading json results file: "{}",\n'
> @@ -283,11 +285,15 @@ def _resume(results_dir):
>      assert meta['results_version'] == CURRENT_JSON_VERSION, \
>          "Old results version, resume impossible"
>  
> -    meta['tests'] = {}
> +    meta['tests'] = collections.OrderedDict()
>  
>      # Load all of the test names and added them to the test list
> -    for file_ in os.listdir(os.path.join(results_dir, 'tests')):
> -        with open(os.path.join(results_dir, 'tests', file_), 'r') as f:
> +    tests_dir = os.path.join(results_dir, 'tests')
> +    file_list = sorted(os.listdir(tests_dir),key=
> +                       lambda p: int(os.path.splitext(p)[0]))
> +
> +    for file_ in file_list:
> +        with open(os.path.join(tests_dir, file_), 'r') as f:
>              try:
>                  meta['tests'].update(json.load(f))
>              except ValueError:
> -- 
> 2.9.3
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20170209/fd0b96d9/attachment.sig>


More information about the Piglit mailing list