Skip to content

Commit 95341da

Browse files
authored
Search string must be encoded to bytes (#93)
1 parent 439f0f5 commit 95341da

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/lithium/interestingness/outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def interesting(
7575
outputs = (run_info.out, run_info.err)
7676
for data in outputs:
7777
if (args.regex and re.match(args.search, data, flags=re.MULTILINE)) or (
78-
args.search in data
78+
args.search.encode("utf-8") in data
7979
):
8080
LOG.info("[Interesting] Match detected!")
8181
return True

tests/test_interestingness.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import sys
1010
import time
1111
from pathlib import Path
12+
from unittest.mock import MagicMock, patch
1213

1314
import pytest
1415

1516
import lithium
17+
from lithium.interestingness import outputs
18+
from lithium.interestingness.timed_run import RunData
1619

1720
CAT_CMD = [
1821
sys.executable,
@@ -228,6 +231,16 @@ def test_outputs_true() -> None:
228231
assert lith.test_count == 1
229232

230233

234+
def test_outputs_in_bytes_true() -> None:
235+
"""Test that output test properly identifies string in bytes object"""
236+
mock_run_data = MagicMock(RunData)
237+
mock_run_data.err = b""
238+
mock_run_data.out = b"magic bytes"
239+
with patch("lithium.interestingness.outputs.timed_run") as mock_timed_run:
240+
mock_timed_run.return_value = mock_run_data
241+
assert outputs.interesting(["-s", "magic bytes"] + LS_CMD)
242+
243+
231244
def test_outputs_false() -> None:
232245
"""interestingness 'outputs' negative test"""
233246
lith = lithium.Lithium()

0 commit comments

Comments
 (0)