From 802884347b1f484eb4595c4872b6e53e48217ff6 Mon Sep 17 00:00:00 2001 From: Tom Scanlan Date: Sat, 16 Nov 2019 14:26:38 -0500 Subject: [PATCH] fix tests note how to test locally, and make test.py pass for existing data Signed-off-by: Tom Scanlan --- README.md | 9 +++++++++ test.py | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 102a265..7f04d10 100644 --- a/README.md +++ b/README.md @@ -148,3 +148,12 @@ list of tags from the following set: This project is dedicated to the public domain. Copyright and related rights in the work worldwide are waived through the [CC0 1.0 Universal public domain dedication](http://creativecommons.org/publicdomain/zero/1.0/). All contributions to this project must be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of your copyright interest. + +## Local Testing + +Install circleci locally according to the [docs](https://circleci.com/docs/2.0/local-cli/). + + brew install circleci + circleci config validate + pip install rtyaml + circleci local execute --job build diff --git a/test.py b/test.py index 2f4f4cc..5451657 100644 --- a/test.py +++ b/test.py @@ -5,6 +5,10 @@ import sys import rtyaml +acceptable_allegation_length = 750 +acceptable_text_length = 800 +acceptable_text_length_ratio_above = .86 + has_error = False def error(*args): global has_error @@ -119,13 +123,21 @@ def remove_markdown_link_urls(s): if bad_tags: error(incident, cons, "Consequence has invalid 'tags': {}.".format(bad_tags)) + stripped_text_length = len(remove_markdown_link_urls(incident["text"])) + stripped_cons_length = len(" ".join(remove_markdown_link_urls(str(cons)) for cons in incident["consequences"])) + # Suggest incidents whose allegation or text fields probably could be shortened. - if len(incident["allegation"]) > 750: + if len(incident["allegation"]) > acceptable_allegation_length: error(incident, "'allegation' could probably be shorter.") - if len(incident["consequences"]) > 2 and len(remove_markdown_link_urls(incident["text"])) > 800: - error(incident, "'text' could probably be shorter.") - elif len(incident["consequences"]) > 2 and len(incident["text"]) > 400 and len(remove_markdown_link_urls(incident["text"])) > .8 * (len(incident["allegation"]) + len(" ".join(remove_markdown_link_urls(str(cons)) for cons in incident["consequences"]))): - error(incident, "'text' could probably be shorter.") + + if len(incident["consequences"]) > 2: + if stripped_text_length > acceptable_text_length: + error(incident, "'text' is too long. Goal %d, found %d." % acceptable_text_length , stripped_text_length) + + else: + + if len(incident["text"]) > acceptable_text_length/2 and (stripped_text_length > (acceptable_text_length_ratio_above * (len(incident["allegation"]) + stripped_cons_length))): + error(incident, "'text' could should be shorter based on length of allegations and consequences. Goal %d, found %d." % ((acceptable_text_length_ratio_above * (len(incident["allegation"]) + stripped_cons_length)), stripped_text_length )) if has_error: