From aaea65414081c02c5b6c0105390d19ae18d12840 Mon Sep 17 00:00:00 2001 From: ddl-kavya <91882851+ddl-kavya@users.noreply.github.com> Date: Mon, 13 Nov 2023 22:59:39 +0530 Subject: [PATCH] QE-13613 numerical sorting of duration in flat.html report (#369) JIRA - QE-13613 --- CHANGELOG.md | 3 +++ pyproject.toml | 3 +-- src/cucu/reporter/html.py | 16 +++++++++++++--- src/cucu/reporter/templates/feature.html | 6 +++--- src/cucu/reporter/templates/flat.html | 4 ++-- src/cucu/reporter/templates/index.html | 4 ++-- src/cucu/reporter/templates/scenario.html | 4 ++-- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6bea6df..75b1698d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.175.0 +- Change - left pad duration with zeroes for better alphabetical sorting in flat.html report + ## 0.174.0 - Chore - prevent secrets from being merged to main - Chore - stabilize CI by reducing workers diff --git a/pyproject.toml b/pyproject.toml index 29be0553..7cf1fab3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cucu" -version = "0.174.0" +version = "0.175.0" license = "MIT" description = "Easy BDD web testing" authors = ["Domino Data Lab "] @@ -23,7 +23,6 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Testing :: BDD", ] diff --git a/src/cucu/reporter/html.py b/src/cucu/reporter/html.py index 2bd59fc8..13cfdc8b 100644 --- a/src/cucu/reporter/html.py +++ b/src/cucu/reporter/html.py @@ -47,6 +47,14 @@ def process_tags(element): element["tags"] = " ".join(prepared_tags) +# function to left pad duration with '0' for better alphabetical sorting in html reports. +def left_pad_zeroes(elapsed_time): + int_decimal = str(round(elapsed_time, 3)).split(".") + int_decimal[0] = int_decimal[0].zfill(3) + padded_duration = ".".join(int_decimal) + return padded_duration + + def generate(results, basepath, only_failures=False): """ generate an HTML report for the results provided. @@ -285,14 +293,16 @@ def generate(results, basepath, only_failures=False): encoding="utf-8", ) - scenario["duration"] = scenario_duration + scenario["duration"] = left_pad_zeroes(scenario_duration) feature_duration += scenario_duration if feature_started_at is None: feature["started_at"] = "" feature["total_steps"] = sum([x["total_steps"] for x in scenarios]) - feature["duration"] = sum([x["duration"] for x in scenarios]) + feature["duration"] = left_pad_zeroes( + sum([float(x["duration"]) for x in scenarios]) + ) feature["total_scenarios"] = total_scenarios feature["total_scenarios_passed"] = total_scenarios_passed @@ -308,7 +318,7 @@ def generate(results, basepath, only_failures=False): ] grand_totals = {} for k in keys: - grand_totals[k] = sum([x[k] for x in reported_features]) + grand_totals[k] = sum([float(x[k]) for x in reported_features]) package_loader = jinja2.PackageLoader("cucu.reporter", "templates") templates = jinja2.Environment(loader=package_loader) # nosec diff --git a/src/cucu/reporter/templates/feature.html b/src/cucu/reporter/templates/feature.html index c3f2bf91..acbbc7d3 100644 --- a/src/cucu/reporter/templates/feature.html +++ b/src/cucu/reporter/templates/feature.html @@ -10,7 +10,7 @@ Index
  • -
    Started {{ feature['started_at'] }} for {{ '{:.3f}'.format(feature['duration']) }}s
    +
    Started {{ feature['started_at'] }} for {{ feature['duration'] }}s
  • @@ -42,7 +42,7 @@ Scenario Steps Status - Duration + Duration (s) {% for scenario in scenarios %} @@ -60,7 +60,7 @@ {{ scenario['total_steps'] }} {{ scenario['status'] }} - {{ '{:.3f}'.format(scenario['duration']) }}s + {{ scenario['duration'] }} {% endif %} {% endfor %} diff --git a/src/cucu/reporter/templates/flat.html b/src/cucu/reporter/templates/flat.html index 101142c7..2c3baaa0 100644 --- a/src/cucu/reporter/templates/flat.html +++ b/src/cucu/reporter/templates/flat.html @@ -22,7 +22,7 @@ Scenario Total Steps Status - Duration + Duration (s) {% for feature in features %} @@ -35,7 +35,7 @@ {{ escape(scenario['name']) }}
    {{ scenario['tags'] }} {{ scenario['total_steps'] }} {{ scenario['status'] }} - {{ '{:.3f}'.format(scenario['duration']) }}s + {{ scenario['duration'] }} {% endif %} {% endfor %} diff --git a/src/cucu/reporter/templates/index.html b/src/cucu/reporter/templates/index.html index b8db5041..ffe4400e 100644 --- a/src/cucu/reporter/templates/index.html +++ b/src/cucu/reporter/templates/index.html @@ -24,7 +24,7 @@ Failed
    {{ grand_totals['total_scenarios_failed'] }} Skipped
    {{ grand_totals['total_scenarios_skipped'] }} Status
      - Duration
    {{ '{:.3f}'.format(grand_totals['duration']) }}s + Duration (s)
    {{ '{:.3f}'.format(grand_totals['duration']) }}s {% for feature in features %} @@ -36,7 +36,7 @@ {{ feature['total_scenarios_failed'] }} {{ feature['total_scenarios_skipped'] }} {{ feature['status'] }} - {{ '{:.3f}'.format(feature['duration']) }}s + {{ feature['duration'] }} {% endfor %} diff --git a/src/cucu/reporter/templates/scenario.html b/src/cucu/reporter/templates/scenario.html index bcd412a7..ff93e5ef 100644 --- a/src/cucu/reporter/templates/scenario.html +++ b/src/cucu/reporter/templates/scenario.html @@ -35,7 +35,7 @@
  • -
    Started {{ scenario["started_at"] }} for {{ '{:.3f}'.format(scenario['duration']) }}s
    +
    Started {{ scenario["started_at"] }} for {{ scenario['duration'] }}
  • @@ -75,7 +75,7 @@ {% endif %} -
    Offset and Duration
    +
    Offset and Duration (s)
    {% for step in steps %}