1
0
mirror of https://github.com/python-escpos/python-escpos synced 2025-08-24 09:03:34 +00:00

Improve test coverage and fix issue in path loading (#602)

* reactivate skipped tests

* remove unused internal interfaces

* enable pytest in VS Code

* simplify and fix path logic in loader

* increase test coverage

* test missing config

* check for wrong printer names

* Skipped appdir test
This commit is contained in:
Patrick Kanzler
2023-12-06 00:25:36 +01:00
committed by GitHub
parent 5914c7c560
commit 815f247df1
8 changed files with 167 additions and 39 deletions

View File

@@ -12,10 +12,6 @@ class CodePageManager:
"""Initialize codepage manager."""
self.data = data
def get_all(self):
"""Get list of all codepages."""
return self.data.values()
@staticmethod
def get_encoding_name(encoding):
"""Get encoding name.

View File

@@ -3,6 +3,7 @@
This module contains the implementations of abstract base class :py:class:`Config`.
"""
import os
import pathlib
import appdirs
import yaml
@@ -56,23 +57,19 @@ class Config(object):
config_path = os.path.join(
appdirs.user_config_dir(self._app_name), self._config_file
)
if isinstance(config_path, pathlib.Path):
# store string if posixpath
config_path = config_path.as_posix()
if not os.path.isfile(config_path):
# supplied path is not a file --> assume default file
config_path = os.path.join(config_path, self._config_file)
try:
# First check if it's file like. If it is, pyyaml can load it.
# I'm checking type instead of catching exceptions to keep the
# exception handling simple
if hasattr(config_path, "read"):
config = yaml.safe_load(config_path)
else:
# If it isn't, it's a path. We have to open it first, otherwise
# pyyaml will try to read it as yaml
with open(config_path, "rb") as config_file:
config = yaml.safe_load(config_file)
with open(config_path, "rb") as config_file:
config = yaml.safe_load(config_file)
except EnvironmentError:
raise exceptions.ConfigNotFoundError(
"Couldn't read config at {config_path}".format(
config_path=str(config_path),
)
f"Couldn't read config at {config_path}"
)
except yaml.YAMLError:
raise exceptions.ConfigSyntaxError("Error parsing YAML")