badgerp_get_lcov_coverage 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ /target
2
+ /dist
3
+ /.venv
4
+ __pycache__/
5
+ *.pyc
6
+ plugins/**/.packages/
7
+ test.svg
8
+ badges/
9
+ /plugins/repology-badge/.site-packages
10
+ plugins/**/dist/
11
+ plugins/**/*.egg-info/
12
+ .pytest_cache/
13
+ mutants.out*
14
+ /mutants.out*
15
+ /xz2-0.1.7
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.5
2
+ Name: badgerp_get_lcov_coverage
3
+ Version: 0.1.0
4
+ Summary: Report line coverage from lcov.info (produced by grcov or cargo-tarpaulin)
5
+ Author-email: 𝑷𝒉𝒊𝒍𝒐𝒄𝒂𝒍𝒚𝒔𝒕 <regime_skylark.0y@icloud.com>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+
10
+ # get-lcov-coverage
11
+
12
+ A [badger](https://github.com/) plugin that reports line coverage from an
13
+ `lcov.info` file (as produced by tools like `grcov` or `cargo-tarpaulin`).
14
+
15
+ It parses `DA:` lines to compute the fraction of covered lines and returns
16
+ a `coverage: <percent>%` badge entry, or `coverage: unknown` if the
17
+ `lcov.info` file is missing.
18
+
19
+ This package is not meant to be used as a standalone library — badger loads
20
+ `plugin.py`'s `run()` function directly as its entrypoint.
@@ -0,0 +1,11 @@
1
+ # get-lcov-coverage
2
+
3
+ A [badger](https://github.com/) plugin that reports line coverage from an
4
+ `lcov.info` file (as produced by tools like `grcov` or `cargo-tarpaulin`).
5
+
6
+ It parses `DA:` lines to compute the fraction of covered lines and returns
7
+ a `coverage: <percent>%` badge entry, or `coverage: unknown` if the
8
+ `lcov.info` file is missing.
9
+
10
+ This package is not meant to be used as a standalone library — badger loads
11
+ `plugin.py`'s `run()` function directly as its entrypoint.
@@ -0,0 +1,34 @@
1
+ # This is the plugin for getting code coverage using the [lcov](https://github.com/linux-test-project/lcov) format.
2
+ # This is by no means a good or complete implementation, but it should work!
3
+
4
+ import os
5
+ from badger import entry
6
+
7
+ def run(lcov_file: str = "lcov.info") -> entry:
8
+ """Calculate line coverage from an lcov trace file.
9
+
10
+ Missing files and traces with no executable lines both produce a badge
11
+ rather than failing the build.
12
+
13
+ Args:
14
+ lcov_file: path to the lcov.info file produced by the coverage tool.
15
+ """
16
+ if not os.path.exists(lcov_file):
17
+ return entry(label="coverage", status="unknown")
18
+
19
+ total, covered = 0, 0
20
+ with open(lcov_file) as f:
21
+ for raw in f:
22
+ line = raw.strip()
23
+ if not line.startswith("DA:"):
24
+ continue
25
+ _, hits = line[3:].split(",", 1)
26
+ total += 1
27
+ if int(hits) > 0:
28
+ covered += 1
29
+
30
+ if total == 0:
31
+ return entry(label="coverage", status="0%")
32
+
33
+ pct = round(covered / total * 100)
34
+ return entry(label="coverage", status=f"{pct}%")
@@ -0,0 +1,15 @@
1
+ [project]
2
+ name = "badgerp_get_lcov_coverage"
3
+ version = "0.1.0"
4
+ description = "Report line coverage from lcov.info (produced by grcov or cargo-tarpaulin)"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ authors = [{ name = "𝑷𝒉𝒊𝒍𝒐𝒄𝒂𝒍𝒚𝒔𝒕", email = "regime_skylark.0y@icloud.com" }]
8
+ requires-python = ">=3.11"
9
+
10
+ [build-system]
11
+ requires = ["hatchling"]
12
+ build-backend = "hatchling.build"
13
+
14
+ [tool.hatch.build.targets.wheel]
15
+ include = ["plugin.py"]
@@ -0,0 +1,31 @@
1
+ def test_missing_lcov_returns_unknown(plugin, tmp_path, monkeypatch):
2
+ monkeypatch.chdir(tmp_path)
3
+ result = plugin.run()
4
+ assert result.label == "coverage"
5
+ assert result.status == "unknown"
6
+
7
+
8
+ def test_full_coverage(plugin, tmp_path, monkeypatch):
9
+ monkeypatch.chdir(tmp_path)
10
+ (tmp_path / "lcov.info").write_text("DA:1,1\nDA:2,5\n")
11
+ assert plugin.run().status == "100%"
12
+
13
+
14
+ def test_partial_coverage(plugin, tmp_path, monkeypatch):
15
+ monkeypatch.chdir(tmp_path)
16
+ (tmp_path / "lcov.info").write_text("DA:1,1\nDA:2,0\nDA:3,1\n")
17
+ assert plugin.run().status == "67%"
18
+
19
+
20
+ def test_empty_lcov_file(plugin, tmp_path, monkeypatch):
21
+ monkeypatch.chdir(tmp_path)
22
+ (tmp_path / "lcov.info").write_text("")
23
+ assert plugin.run().status == "0%"
24
+
25
+
26
+ def test_ignores_non_da_lines(plugin, tmp_path, monkeypatch):
27
+ monkeypatch.chdir(tmp_path)
28
+ (tmp_path / "lcov.info").write_text(
29
+ "TN:\nSF:src/lib.rs\nDA:1,1\nDA:2,0\nLF:2\nLH:1\nend_of_record\n"
30
+ )
31
+ assert plugin.run().status == "50%"
@@ -0,0 +1,8 @@
1
+ version = 1
2
+ revision = 3
3
+ requires-python = ">=3.11"
4
+
5
+ [[package]]
6
+ name = "badgerp-get-lcov-coverage"
7
+ version = "0.1.0"
8
+ source = { editable = "." }