[Piglit] [PATCH 2/2] framework: small refactor of test_result page generation

Ilia Mirkin imirkin at alum.mit.edu
Fri Apr 18 07:22:28 PDT 2014


On Fri, Apr 18, 2014 at 9:54 AM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> Previously each value of a dictionary was pulled out and passed one by
> one to mako, that results in a lot of values being passed. With this
> patch the dictionary is passed and the keys are pulled out in the mako.
> This is much cleaner and easier to read.

This will break dmesg for some old results files... you still need to
pass it in explicitly, or move the computation to the template. (i.e.
if it's an array, dmesg="\n".join(dmesg), or any other way of
achieving that result.)

>
> Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> ---
>  framework/summary.py       | 15 +--------------
>  templates/test_result.mako | 28 +++++++++++++++-------------
>  2 files changed, 16 insertions(+), 27 deletions(-)
>
> diff --git a/framework/summary.py b/framework/summary.py
> index 41e0774..e5cd70c 100644
> --- a/framework/summary.py
> +++ b/framework/summary.py
> @@ -408,20 +408,7 @@ class Summary:
>                                'w') as out:
>                          out.write(testfile.render(
>                              testname=key,
> -                            status=value.get('result', 'None'),
> -                            # Returning a NoneType (instaed of 'None') prevents
> -                            # this field from being generated.setting the
> -                            # environment to run tests is ugly, and should
> -                            # disapear at somepoint
> -                            env=value.get('environment', None),
> -                            returncode=value.get('returncode', 'None'),
> -                            time=value.get('time', 'None'),
> -                            info=value.get('info', None), # deprecated
> -                            out=value.get('out', 'None'),
> -                            err=value.get('err', 'None'),
> -                            traceback=value.get('traceback', 'None'),
> -                            command=value.get('command', 'None'),
> -                            dmesg=dmesg,
> +                            value=value,
>                              css=path.relpath(result_css, temp_path),
>                              index=path.relpath(index, temp_path)))
>
> diff --git a/templates/test_result.mako b/templates/test_result.mako
> index 49e6fd2..70b9f91 100644
> --- a/templates/test_result.mako
> +++ b/templates/test_result.mako
> @@ -11,7 +11,7 @@
>      <h1>Results for ${testname}</h1>
>      <h2>Overview</h2>
>      <div>
> -      <p><b>Result:</b> ${status}</p>
> +      <p><b>Result:</b> ${value.get('status', 'None')}</p>
>      </div>
>      <p><a href="${index}">Back to summary</a></p>
>      <h2>Details</h2>
> @@ -22,57 +22,59 @@
>        </tr>
>        <tr>
>          <td>Returncode</td>
> -        <td>${returncode}</td>
> +        <td>${value.get('returncode', 'None')}</td>
>        </tr>
>        <tr>
>          <td>Time</td>
> -        <td>${time}</b>
> +        <td>${value.get('time', 'None')}</b>
>        </tr>
>      ## Info is deprecated and may disapear someday
> -    % if info is not None:
> +    % if value.get('info') is not None:
>        <tr>
>          <td>Info</td>
>          <td>
> -          <pre>${info | h}</pre>
> +          <pre>${value.get('info') | h}</pre>
>          </td>
>        </tr>
>      % endif
>        <tr>
>          <td>Stdout</td>
>          <td>
> -          <pre>${out | h}</pre>
> +          <pre>${value.get('out', 'None') | h}</pre>
>          </td>
>        </tr>
>        <tr>
>          <td>Stderr</td>
>          <td>
> -          <pre>${err | h}</pre>
> +          <pre>${value.get('err', 'None') | h}</pre>
>          </td>
>        </tr>
> -      % if env:
> +    % if value.get('env') is not None:
>        <tr>
>          <td>Environment</td>
>          <td>
> -          <pre>${env | h}</pre>
> +          <pre>${value.get('env') | h}</pre>
>          </td>
>        </tr>
> -      % endif
> +    % endif
>        <tr>
>          <td>Command</td>
>          <td>
> -          </pre>${command}</pre>
> +          </pre>${value.get('command', 'None')}</pre>
>          </td>
>        </tr>
> +    % if value.get('traceback') is not None:
>        <tr>
>          <td>Traceback</td>
>          <td>
> -          <pre>${traceback | h}</pre>
> +          <pre>${value.get('traceback') | h}</pre>
>          </td>
>        </tr>
> +    % endif
>        <tr>
>          <td>dmesg</td>
>          <td>
> -          <pre>${dmesg | h}</pre>
> +          <pre>${value.get('dmesg', 'None') | h}</pre>
>          </td>
>        </tr>
>      </table>
> --
> 1.9.2
>


More information about the Piglit mailing list