diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-01-27 13:30:53 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-01-27 13:30:53 -0600 |
| commit | 3a5ce18e9b2d921c419805c0b01f2b40822e7ab9 (patch) | |
| tree | 51f2158cd556fedc20f0f2017510dd2843cb836b /config_file | |
| parent | Remove BREAKING (diff) | |
| download | config-file-3a5ce18e9b2d921c419805c0b01f2b40822e7ab9.zip | |
Add proper working support for custom parsers and raise test coverage
Diffstat (limited to 'config_file')
| -rw-r--r-- | config_file/config_file.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/config_file/config_file.py b/config_file/config_file.py index bc05d97..397c007 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -2,7 +2,6 @@ import inspect from pathlib import Path, PurePath from shutil import copyfile -from config_file.parsers.base_parser import BaseParser from config_file.parsers.ini_parser import IniParser from config_file.utils import split_on_dot @@ -47,7 +46,7 @@ class ConfigFile: if isinstance(file_path, PurePath): file_path = str(file_path) - if isinstance(parser, BaseParser) and not inspect.isabstract(parser): + if parser is not None and not inspect.isabstract(parser): return parser(self.contents) file_type = split_on_dot(file_path, only_last_dot=True)[-1] @@ -116,15 +115,12 @@ class ConfigFile: ) if not Path(original_file_path).exists(): - raise OSError(f"The {original_file_path} file to reset to does not exist.") - - try: - Path(self.path).expanduser().unlink() - except OSError: - pass + raise OSError( + f"The {original_file_path} file to restore to does not exist." + ) + Path(self.path).expanduser().unlink() copyfile(original_file_path, self.path) - self.contents = self.__read_config_file() self.parser.parsed_content = self.parser.parse(self.contents) |