Skip to content

Commit a04d247

Browse files
committed
Handle corner cases
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
1 parent 1b42615 commit a04d247

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
## [Unreleased][]
44

5-
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-reporting/compare/0.11.0...HEAD
5+
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-reporting/compare/0.12.0...HEAD
6+
7+
## [0.12.0][] - 2018-12-06
8+
9+
[0.12.0]: https://github.com/chaostoolkit/chaostoolkit-reporting/compare/0.11.0...0.12.0
10+
11+
### Changed
12+
13+
- Support `"ref"` to other activities
14+
- Support versions that don't match semver specification such as `rc`
615

716
## [0.11.0][] - 2018-11-08
817

chaosreport/__init__.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import List
1515

1616
import cairosvg
17+
from chaoslib.caching import cache_activities, lookup_activity
1718
from chaoslib.types import Experiment, Journal, Run
1819
import dateparser
1920
from jinja2 import Environment, PackageLoader, select_autoescape
@@ -29,7 +30,7 @@
2930

3031
__all__ = ["__version__", "generate_report", "generate_report_header",
3132
"save_report"]
32-
__version__ = '0.11.0'
33+
__version__ = '0.12.0'
3334

3435
curdir = os.getcwd()
3536
basedir = os.path.dirname(__file__)
@@ -221,12 +222,11 @@ def generate_report(journal_path: str, export_format: str = "markdown") -> str:
221222

222223
# inject some pre-processed values into the journal for rendering
223224
experiment = journal["experiment"]
225+
cache_activities(experiment)
224226
journal["chaoslib_version"] = journal["chaoslib-version"]
225227
journal["hypo"] = experiment.get("steady-state-hypothesis")
226-
journal["num_probes"] = len(list(
227-
filter(lambda a: a["type"] == "probe", experiment["method"])))
228-
journal["num_actions"] = len(list(
229-
filter(lambda a: a["type"] == "action", experiment["method"])))
228+
journal["num_probes"] = count_activities(experiment, "probe")
229+
journal["num_actions"] = count_activities(experiment, "action")
230230
journal["human_duration"] = str(timedelta(seconds=journal["duration"]))
231231
journal["export_format"] = export_format
232232
journal["today"] = datetime.now().strftime("%d %B %Y")
@@ -239,6 +239,19 @@ def generate_report(journal_path: str, export_format: str = "markdown") -> str:
239239
return report
240240

241241

242+
def count_activities(experiment: Experiment, activity_type: str) -> int:
243+
"""
244+
Count the number of activity by type in the experiment's method
245+
"""
246+
count = 0
247+
for activity in experiment["method"]:
248+
if "ref" in activity:
249+
activity = lookup_activity(activity["ref"])
250+
if activity["type"] == activity_type:
251+
count += 1
252+
return count
253+
254+
242255
def save_report(header: str, reports: List[str], report_path: str,
243256
export_format: str = "markdown"):
244257
with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8') as fp:
@@ -290,6 +303,7 @@ def get_report_template(report_version: str,
290303

291304
templates = sorted(templates, key=lambda vinfo: vinfo[0])
292305

306+
report_version = report_version.replace('rc1', '-rc1')
293307
for (vinfo, name) in templates:
294308
if semver.match(
295309
report_version, "<={v}".format(v=semver.format_version(

0 commit comments

Comments
 (0)