diff --git a/filter/kyofilter b/filter/kyofilter new file mode 100755 index 0000000..92228b2 --- /dev/null +++ b/filter/kyofilter @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..20aff12 --- /dev/null +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_kyofilter.py b/tests/test_kyofilter.py new file mode 100644 index 0000000..9bf95f7 --- /dev/null +++ b/tests/test_kyofilter.py @@ -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"}