|
1 | 1 | import json |
2 | 2 | import os |
3 | 3 | import sys |
| 4 | +from datetime import datetime |
4 | 5 | from enum import Enum |
5 | 6 | from pathlib import Path |
6 | | -from typing import Dict, List, cast |
| 7 | +from typing import Dict, List, Optional, cast |
7 | 8 |
|
8 | 9 | import click |
| 10 | +import timeago |
9 | 11 | from coverage import Coverage, CoverageData |
10 | 12 | from coverage.misc import NoSource |
11 | 13 | from junitparser import JUnitXml |
@@ -73,9 +75,23 @@ def get_file_cov(src: str, coverage: Coverage, coverage_data: CoverageData): |
73 | 75 |
|
74 | 76 |
|
75 | 77 | @click.command() |
76 | | -@click.argument("source") |
77 | | -def run(source: str): |
| 78 | +@click.argument("source", required=False) |
| 79 | +@click.option("--data-dir", default=None) |
| 80 | +def run(source: Optional[str], data_dir: Optional[str]): |
78 | 81 | """""" |
| 82 | + if data_dir: |
| 83 | + Path(data_dir).mkdir(exist_ok=True, parents=True) |
| 84 | + os.chdir(data_dir) |
| 85 | + |
| 86 | + if source is None: |
| 87 | + if Path(".coverage").exists(): |
| 88 | + stats = os.stat(".coverage") |
| 89 | + dt = datetime.fromtimestamp(stats.st_mtime) |
| 90 | + ago = timeago.format(dt, datetime.now()) |
| 91 | + click.echo(json.dumps({"time_since_run": ago})) |
| 92 | + else: |
| 93 | + click.echo(json.dumps({"time_since_run": None})) |
| 94 | + sys.exit(0) |
79 | 95 | src = Path(source).as_posix() |
80 | 96 | test_results = Path("junit.xml") |
81 | 97 | if not test_results.exists(): |
@@ -108,8 +124,13 @@ def run(source: str): |
108 | 124 | assert coverage_data is not None |
109 | 125 | lines, missing_lines = get_file_cov(src, coverage, coverage_data) |
110 | 126 |
|
111 | | - norm_contexts = {norm(ctx) for ctx in coverage_data.measured_contexts()} |
112 | | - assert norm_contexts.difference(status.keys()) == set() |
| 127 | + # norm_contexts = {norm(ctx) for ctx in coverage_data.measured_contexts()} |
| 128 | + |
| 129 | + # no_matching_key = norm_contexts.difference(status.keys()) |
| 130 | + |
| 131 | + # if len(no_matching_key)> 0: |
| 132 | + # lkj = '\n'.join(no_matching_key) |
| 133 | + # click.echo(f"No matching key:{lkj} ") |
113 | 134 |
|
114 | 135 | file = File( |
115 | 136 | lines={ |
|
0 commit comments