Skip to content

Commit 5a4854d

Browse files
🧪 Add unit tests for Labels string parsing (#45)
* 🧪 Add unit tests for Labels string parsing and fix edge cases - Added unit tests for `Labels.parse` covering multiple labels, single labels, empty strings, and multiple spaces. - Fixed `Labels.parse` to gracefully handle empty strings and redundant whitespace. - Added a `conftest.py` in the new test directory to mock missing dependencies in restricted environments. Co-authored-by: rnovatorov <[email protected]> * 🧪 Remove unnecessary conftest.py mocking As requested, removed the `conftest.py` file that was mocking dependencies, as they are expected to be installed in the environment. Co-authored-by: rnovatorov <[email protected]> * 🧪 Simplify Labels.parse implementation Switched to using `s.split()` which more cleanly handles empty strings and multiple spaces compared to the previous explicit checks. Co-authored-by: rnovatorov <[email protected]> * 🧪 Restore original Labels.parse implementation and update tests Reverted the simplification of `Labels.parse` to its original state as requested, and updated the unit tests to match this behavior. Co-authored-by: rnovatorov <[email protected]> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent c5736c9 commit 5a4854d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from enapter.http.api.telemetry.labels import Labels
2+
3+
4+
def test_parse_multiple_labels():
5+
s = "device=foo telemetry=bar custom=baz"
6+
labels = Labels.parse(s)
7+
assert labels == {"device": "foo", "telemetry": "bar", "custom": "baz"}
8+
assert labels.device == "foo"
9+
assert labels.telemetry == "bar"
10+
11+
12+
def test_parse_single_label():
13+
s = "device=only"
14+
labels = Labels.parse(s)
15+
assert labels == {"device": "only"}
16+
assert labels.device == "only"

0 commit comments

Comments
 (0)