Skip to content

Commit 88d14c4

Browse files
authored
Merge pull request #75 from Pennycook/feature/coverage-format
Finalize coverage schema
2 parents 71da3e8 + be06089 commit 88d14c4

File tree

10 files changed

+43
-128
lines changed

10 files changed

+43
-128
lines changed

MANIFEST.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include p3analysis/data/coverage-0.1.0.schema
2-
include p3analysis/data/coverage-0.2.0.schema
3-
include p3analysis/data/coverage-0.3.0.schema
1+
include p3analysis/data/coverage.schema
42
include p3analysis/plot/backend/templates/cascade.tex
53
include p3analysis/plot/backend/templates/navchart.tex

case-studies/babelstream/coverage.csv

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

docs/source/data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ The JSON string format follows the schema `here`_, and should be considered
7575
experimental.
7676

7777
.. _here:
78-
https://raw.githubusercontent.com/intel/p3-analysis-library/master/p3/data/coverage-0.1.0.schema
78+
https://raw.githubusercontent.com/intel/p3-analysis-library/master/p3/data/coverage.schema

p3analysis/data/_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _validate_coverage_json(json_string: str) -> object:
3434

3535
instance = json.loads(json_string)
3636

37-
schema_string = pkgutil.get_data(__name__, "coverage-0.3.0.schema")
37+
schema_string = pkgutil.get_data(__name__, "coverage.schema")
3838
if not schema_string:
3939
msg = "Could not locate coverage schema file"
4040
raise RuntimeError(msg)
@@ -47,7 +47,7 @@ def _validate_coverage_json(json_string: str) -> object:
4747
msg = "Coverage string failed schema validation"
4848
raise ValueError(msg)
4949
except jsonschema.exceptions.SchemaError:
50-
msg = "coverage-0.3.0.schema is not a valid schema"
50+
msg = "coverage.schema is not a valid schema"
5151
raise RuntimeError(msg)
5252

5353
return instance

p3analysis/data/coverage-0.1.0.schema

Lines changed: 0 additions & 37 deletions
This file was deleted.

p3analysis/data/coverage-0.3.0.schema

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://raw.githubusercontent.com/intel/p3-analysis-library/main/p3/data/coverage-0.2.0.schema",
3+
"$id": "https://raw.githubusercontent.com/intel/p3-analysis-library/main/p3/data/coverage.schema",
44
"title": "Coverage",
55
"description": "Lines of code used in each file of a code base.",
66
"type": "array",
@@ -10,31 +10,27 @@
1010
"file": {
1111
"type": "string"
1212
},
13-
"path": {
13+
"id": {
1414
"type": "string"
1515
},
16-
"regions": {
16+
"used_lines": {
1717
"type": "array",
1818
"items": {
19-
"type": "array",
20-
"prefixItems": [
21-
{
22-
"type": "integer"
23-
},
24-
{
25-
"type": "integer"
26-
},
27-
{
28-
"type": "integer"
29-
}
30-
],
31-
"items": false
19+
"type": "integer"
20+
}
21+
},
22+
"unused_lines": {
23+
"type": "array",
24+
"items": {
25+
"type": "integer"
3226
}
3327
}
3428
},
3529
"required": [
3630
"file",
37-
"regions"
31+
"id",
32+
"used_lines",
33+
"unused_lines"
3834
]
3935
}
4036
}

p3analysis/metrics/_divergence.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,8 @@ def _coverage_to_divergence(maps):
5656
for p, coverage in enumerate(maps):
5757
for entry in coverage:
5858
unique_fn = (entry["file"], entry["id"])
59-
for region in entry["lines"]:
60-
# If a region is a single integer, it represents one line.
61-
if isinstance(region, int):
62-
line = region
63-
linemap[(unique_fn, line)].add(p)
64-
65-
# If a region is a list, it represents a [start, end] pair.
66-
if isinstance(region, list):
67-
for line in range(region[0], region[1]):
68-
linemap[(unique_fn, line)].add(p)
59+
for line in entry["used_lines"]:
60+
linemap[(unique_fn, line)].add(p)
6961

7062
setmap = collections.defaultdict(int)
7163
for key, platforms in linemap.items():

tests/data/test_validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ class TestValidation(unittest.TestCase):
1313

1414
def test_coverage_json_valid(self):
1515
"""p3analysis.data.validation.coverage_json_valid"""
16-
json_string = '[{"file": "path", "id": "sha", "lines": [1, 2, [3, 5]]}]'
16+
json_string = '[{"file": "path", "id": "sha", "used_lines": [1, 2, 3, 5], "unused_lines": []}]'
1717
result_object = _validate_coverage_json(json_string)
18-
expected_object = [{"file": "path", "id": "sha", "lines": [1, 2, [3, 5]]}]
18+
expected_object = [{"file": "path", "id": "sha", "used_lines": [1, 2, 3, 5], "unused_lines": []}]
1919
self.assertTrue(result_object == expected_object)
2020

2121
def test_coverage_json_invalid(self):
2222
"""p3analysis.data.validation.coverage_json_invalid"""
23-
json_string = '[{"file": "path", "id": "sha", "lines": [["1"]]}]'
23+
json_string = '[{"file": "path", "id": "sha", "used_lines": [["1"]], "unused_lines": []}]'
2424
with self.assertRaises(ValueError):
2525
_validate_coverage_json(json_string)
2626

2727
with self.assertRaises(TypeError):
28-
json_object = [{"file": "path", "id": "sha", "lines": [["1"]]}]
28+
json_object = [{"file": "path", "id": "sha", "used_lines": [["1"]], "unused_lines": []}]
2929
_validate_coverage_json(json_object)
3030

3131

tests/metrics/test_divergence.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def test_side_effects(self):
3737
{
3838
"file": "file.cpp",
3939
"id": "0",
40-
"lines": [0],
40+
"used_lines": [0],
41+
"unused_lines": [],
4142
},
4243
],
4344
)
@@ -69,7 +70,8 @@ def test_divergence(self):
6970
{
7071
"file": "foo.cpp",
7172
"id": "0",
72-
"lines": [[0, 9]],
73+
"used_lines": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
74+
"unused_lines": [],
7375
},
7476
],
7577
)
@@ -79,12 +81,14 @@ def test_divergence(self):
7981
{
8082
"file": "foo.cpp",
8183
"id": "0",
82-
"lines": [[0, 9]],
84+
"used_lines": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
85+
"unused_lines": [],
8386
},
8487
{
8588
"file": "bar.cpp",
8689
"id": "1",
87-
"lines": [[0, 9]],
90+
"used_lines": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
91+
"unused_lines": [],
8892
},
8993
],
9094
)
@@ -123,7 +127,8 @@ def test_divergence_single(self):
123127
{
124128
"file": "file.cpp",
125129
"id": "0",
126-
"lines": [0],
130+
"used_lines": [0],
131+
"unused_lines": [],
127132
},
128133
],
129134
)
@@ -156,7 +161,8 @@ def test_divergence_duplicate(self):
156161
{
157162
"file": "foo.cpp",
158163
"id": "0",
159-
"lines": [[0, 9]],
164+
"used_lines": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
165+
"unused_lines": [],
160166
},
161167
],
162168
)
@@ -168,7 +174,8 @@ def test_divergence_duplicate(self):
168174
{
169175
"file": "foo.cpp",
170176
"id": "1",
171-
"lines": [[0, 9]],
177+
"used_lines": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
178+
"unused_lines": [],
172179
},
173180
],
174181
)

0 commit comments

Comments
 (0)