| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import json |
| 12 |
import sys |
| 13 |
from collections import defaultdict |
| 14 |
from pathlib import Path |
| 15 |
|
| 16 |
if __name__ == "__main__": |
| 17 |
data = [] |
| 18 |
for p in Path.cwd().glob("branch-check*"): |
| 19 |
data.extend(json.loads(l) for l in p.read_text("utf-8").splitlines()) |
| 20 |
|
| 21 |
checks = defaultdict(set) |
| 22 |
|
| 23 |
for d in data: |
| 24 |
checks[d["name"]].add(d["value"]) |
| 25 |
|
| 26 |
if not checks: |
| 27 |
print("No branches found in the branch-check file?") |
| 28 |
sys.exit(1) |
| 29 |
|
| 30 |
always_true = [] |
| 31 |
always_false = [] |
| 32 |
|
| 33 |
for c, vs in sorted(checks.items()): |
| 34 |
if len(vs) < 2: |
| 35 |
v = next(iter(vs)) |
| 36 |
assert v in (False, True) |
| 37 |
if v: |
| 38 |
always_true.append(c) |
| 39 |
else: |
| 40 |
always_false.append(c) |
| 41 |
|
| 42 |
failure = always_true or always_false |
| 43 |
|
| 44 |
if failure: |
| 45 |
print("Some branches were not properly covered.") |
| 46 |
|
| 47 |
if always_true: |
| 48 |
print() |
| 49 |
print("The following were always True:") |
| 50 |
for c in always_true: |
| 51 |
print(f" * {c}") |
| 52 |
if always_false: |
| 53 |
print() |
| 54 |
print("The following were always False:") |
| 55 |
for c in always_false: |
| 56 |
print(f" * {c}") |
| 57 |
if failure: |
| 58 |
sys.exit(1) |
| 59 |
|
| 60 |
print( |
| 61 |
f"""Successfully validated {len(checks)} branch{"es" if len(checks) > 1 else ""}.""" |
| 62 |
) |