[Piglit] [PATCH 9/9] summary.py: Use with open(...) as syntax

Paul Berry stereotype441 at gmail.com
Tue Oct 22 02:16:43 CEST 2013


On 15 October 2013 03:13, Dylan Baker <baker.dylan.c at gmail.com> wrote:

> This is the commonly excepted "right way" in python.
>
> Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
>

Something in this series regressed the "changes", "problems", and
"regressions" links in the piglit HTML output.  As of commit aaae592
(summary.py: Fix regression in Summary class) those pages show up empty,
even if there really are changes, problems, or regressions.  In commit
ad97d8b (summary.py: Replace ``import from'' syntax with import), the links
work fine.  I can't bisect further because of the regression fixed in
commit aaae592.

I don't know whether the "skipped" and "fixes" links work properly or not.


> ---
>  framework/summary.py | 77
> ++++++++++++++++++++++++----------------------------
>  1 file changed, 36 insertions(+), 41 deletions(-)
>
> diff --git a/framework/summary.py b/framework/summary.py
> index 3ab71f3..359d078 100644
> --- a/framework/summary.py
> +++ b/framework/summary.py
> @@ -428,13 +428,12 @@ class Summary:
>          for each in self.results:
>              os.mkdir(path.join(destination, each.name))
>
> -            file = open(path.join(destination, each.name, "index.html"),
> 'w')
> -            file.write(testindex.render(name=each.name,
> -                                        time=each.time_elapsed,
> -                                        options=each.options,
> -                                        glxinfo=each.glxinfo,
> -                                        lspci=each.lspci))
> -            file.close()
> +            with open(path.join(destination, each.name, "index.html"),
> 'w') as out:
> +                out.write(testindex.render(name=each.name,
> +                                           time=each.time_elapsed,
> +                                           options=each.options,
> +                                           glxinfo=each.glxinfo,
> +                                           lspci=each.lspci))
>
>              # Then build the individual test results
>              for key, value in each.tests.iteritems():
> @@ -447,21 +446,19 @@ class Summary:
>                      if not path.exists(temp_path):
>                          os.makedirs(temp_path)
>
> -                    file = open(path.join(destination,
> -                                          each.name,
> -                                          key + ".html"), 'w')
> -                    file.write(testfile.render(
> -                        testname=key,
> -                        status=value.get('result', 'None'),
> -                        returncode=value.get('returncode', 'None'),
> -                        time=value.get('time', 'None'),
> -                        info=value.get('info', 'None'),
> -                        traceback=value.get('traceback', 'None'),
> -                        command=value.get('command', 'None'),
> -                        dmesg=value.get('dmesg', 'None'),
> -                        css=path.relpath(result_css, temp_path),
> -                        index=path.relpath(index, temp_path)))
> -                    file.close()
> +                    with open(path.join(destination, each.name, key +
> ".html"),
> +                              'w') as out:
> +                        out.write(testfile.render(
> +                            testname=key,
> +                            status=value.get('result', 'None'),
> +                            returncode=value.get('returncode', 'None'),
> +                            time=value.get('time', 'None'),
> +                            info=value.get('info', 'None'),
> +                            traceback=value.get('traceback', 'None'),
> +                            command=value.get('command', 'None'),
> +                            dmesg=value.get('dmesg', 'None'),
> +                            css=path.relpath(result_css, temp_path),
> +                            index=path.relpath(index, temp_path)))
>
>          # Finally build the root html files: index, regressions, etc
>          index = Template(filename="templates/index.mako",
> @@ -477,30 +474,28 @@ class Summary:
>          # Index.html is a bit of a special case since there is index,
> all, and
>          # alltests, where the other pages all use the same name. ie,
>          # changes.html, self.changes, and page=changes.
> -        file = open(path.join(destination, "index.html"), 'w')
> -        file.write(index.render(results=HTMLIndex(self,
> self.tests['all']),
> -                                page='all',
> -                                pages=pages,
> -                                colnum=len(self.results),
> -                                exclude=exclude))
> -        file.close()
> +        with open(path.join(destination, "index.html"), 'w') as out:
> +            out.write(index.render(results=HTMLIndex(self,
> self.tests['all']),
> +                                   page='all',
> +                                   pages=pages,
> +                                   colnum=len(self.results),
> +                                   exclude=exclude))
>
>          # Generate the rest of the pages
>          for page in pages:
> -            file = open(path.join(destination, page + '.html'), 'w')
> +            with open(path.join(destination, page + '.html'), 'w') as out:
>              # If there is information to display display it
> -            if self.tests[page]:
> -                file.write(index.render(results=HTMLIndex(self,
> -
>  self.tests[page]),
> -                                        pages=pages,
> -                                        page=page,
> -                                        colnum=len(self.results),
> -                                        exclude=exclude))
> -            # otherwise provide an empty page
> -            else:
> -                file.write(empty_status.render(page=page, pages=pages))
> +                if self.tests[page]:
> +                    out.write(index.render(results=HTMLIndex(self,
> +
> self.tests[page]),
> +                                           pages=pages,
> +                                           page=page,
> +                                           colnum=len(self.results),
> +                                           exclude=exclude))
> +                # otherwise provide an empty page
> +                else:
> +                    out.write(empty_status.render(page=page, pages=pages))
>
> -            file.close()
>
>      def generate_text(self, diff, summary):
>          """ Write summary information to the console """
> --
> 1.8.1.5
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20131021/7e4bd14b/attachment-0001.html>


More information about the Piglit mailing list