feat: filter option parsing with tests
This commit is contained in:
parent
db60fdd635
commit
54ee01c475
18
filter/kyofilter
Executable file
18
filter/kyofilter
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CUPS filter for TA 3505ci - injects department account code into PostScript stream."""
|
||||
import sys
|
||||
|
||||
|
||||
def parse_options(options_str):
|
||||
options = {}
|
||||
for token in options_str.split():
|
||||
if '=' in token:
|
||||
k, v = token.split('=', 1)
|
||||
options[k] = v
|
||||
else:
|
||||
options[token] = 'true'
|
||||
return options
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
8
tests/conftest.py
Normal file
8
tests/conftest.py
Normal file
@ -0,0 +1,8 @@
|
||||
import importlib.util, pathlib, sys
|
||||
from importlib.machinery import SourceFileLoader
|
||||
|
||||
_path = pathlib.Path(__file__).parent.parent / "filter" / "kyofilter"
|
||||
_spec = importlib.util.spec_from_loader("kyofilter", SourceFileLoader("kyofilter", str(_path)))
|
||||
_mod = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(_mod)
|
||||
sys.modules["kyofilter"] = _mod
|
||||
16
tests/test_kyofilter.py
Normal file
16
tests/test_kyofilter.py
Normal file
@ -0,0 +1,16 @@
|
||||
import kyofilter
|
||||
|
||||
|
||||
class TestParseOptions:
|
||||
def test_single_key_value(self):
|
||||
assert kyofilter.parse_options("KmManagment=MG12345") == {"KmManagment": "MG12345"}
|
||||
|
||||
def test_multiple_options(self):
|
||||
result = kyofilter.parse_options("KmManagment=MG12345 Duplex=DuplexNoTumble")
|
||||
assert result == {"KmManagment": "MG12345", "Duplex": "DuplexNoTumble"}
|
||||
|
||||
def test_empty_string(self):
|
||||
assert kyofilter.parse_options("") == {}
|
||||
|
||||
def test_flag_without_value(self):
|
||||
assert kyofilter.parse_options("SomeFlag") == {"SomeFlag": "true"}
|
||||
Loading…
x
Reference in New Issue
Block a user