1414import escpos .exceptions
1515
1616
17- def generate_dummy_config (path , content = None ):
17+ def generate_dummy_config (path , content = None ) -> None :
1818 """Generate a dummy config in path"""
1919 dummy_config_content = content
2020 if not content :
@@ -23,15 +23,15 @@ def generate_dummy_config(path, content=None):
2323 assert path .read_text () == dummy_config_content
2424
2525
26- def simple_printer_test (config ):
26+ def simple_printer_test (config ) -> None :
2727 """Simple test for the dummy printer."""
2828 p = config .printer ()
2929 p ._raw (b"1234" )
3030
3131 assert p .output == b"1234"
3232
3333
34- def test_config_load_with_invalid_config_yaml (tmp_path ):
34+ def test_config_load_with_invalid_config_yaml (tmp_path ) -> None :
3535 """Test the loading of a config with a invalid config file (yaml issue)."""
3636 # generate a dummy config
3737 config_file = tmp_path / "config.yaml"
@@ -45,7 +45,7 @@ def test_config_load_with_invalid_config_yaml(tmp_path):
4545 c .load (config_path = config_file )
4646
4747
48- def test_config_load_with_invalid_config_content (tmp_path ):
48+ def test_config_load_with_invalid_config_content (tmp_path ) -> None :
4949 """Test the loading of a config with a invalid config file (content issue)."""
5050 # generate a dummy config
5151 config_file = tmp_path / "config.yaml"
@@ -61,7 +61,7 @@ def test_config_load_with_invalid_config_content(tmp_path):
6161 c .load (config_path = config_file )
6262
6363
64- def test_config_load_with_missing_config (tmp_path ):
64+ def test_config_load_with_missing_config (tmp_path ) -> None :
6565 """Test the loading of a config that does not exist."""
6666 # test the config loading
6767 from escpos import config
@@ -94,7 +94,7 @@ def test_config_load_from_appdir() -> None:
9494 simple_printer_test (c )
9595
9696
97- def test_config_load_with_file (tmp_path ):
97+ def test_config_load_with_file (tmp_path ) -> None :
9898 """Test the loading of a config with a config file."""
9999 # generate a dummy config
100100 config_file = tmp_path / "config.yaml"
@@ -110,7 +110,7 @@ def test_config_load_with_file(tmp_path):
110110 simple_printer_test (c )
111111
112112
113- def test_config_load_with_path (tmp_path ):
113+ def test_config_load_with_path (tmp_path ) -> None :
114114 """Test the loading of a config with a config path."""
115115 # generate a dummy config
116116 config_file = tmp_path / "config.yaml"
@@ -124,3 +124,49 @@ def test_config_load_with_path(tmp_path):
124124
125125 # test the resulting printer object
126126 simple_printer_test (c )
127+
128+
129+ def test_config_load_yaml_string_with_invalid_config_yaml () -> None :
130+ """Invalid YAML string should raise ConfigSyntaxError."""
131+ from escpos import config
132+
133+ c = config .Config ()
134+ with pytest .raises (escpos .exceptions .ConfigSyntaxError ):
135+ c .load_yaml_string ("}invalid}yaml}" )
136+
137+
138+ def test_config_load_yaml_string_with_invalid_config_content () -> None :
139+ """Invalid content should raise ConfigSyntaxError."""
140+ from escpos import config
141+
142+ c = config .Config ()
143+ with pytest .raises (escpos .exceptions .ConfigSyntaxError ):
144+ c .load_yaml_string ("printer:\n type: NoPrinterWithThatName\n " )
145+
146+
147+ def test_config_load_yaml_string_with_valid_config () -> None :
148+ """Valid YAML string should produce a Dummy printer."""
149+ from escpos import config
150+
151+ c = config .Config ()
152+ c .load_yaml_string ("printer:\n type: Dummy\n " )
153+ simple_printer_test (c )
154+
155+
156+ def test_config_load_with_empty_printer_section () -> None :
157+ """Config with an empty printer section should raise ConfigSyntaxError."""
158+ from escpos import config
159+
160+ c = config .Config ()
161+ with pytest .raises (escpos .exceptions .ConfigSyntaxError ):
162+ c .load_yaml_string ("printer: {}" )
163+
164+
165+ def test_config_load_yaml_string_without_printer_section () -> None :
166+ """Config without a printer section should raise ConfigSectionMissingError."""
167+ from escpos import config
168+
169+ c = config .Config ()
170+ c .load_yaml_string ("{}" )
171+ with pytest .raises (escpos .exceptions .ConfigSectionMissingError ):
172+ c .printer ()
0 commit comments