From c2ff004bb082cb1624d0807bcfbef67177f9802c Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Fri, 3 Jan 2025 11:44:58 +0300 Subject: [PATCH] Conversion fixes --- src/gourmand/prefs.py | 14 +++++++------- tests/test_prefs.py | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/gourmand/prefs.py b/src/gourmand/prefs.py index 653d3030..dfddaf18 100644 --- a/src/gourmand/prefs.py +++ b/src/gourmand/prefs.py @@ -4,11 +4,11 @@ from typing import Any, Optional if sys.version_info >= (3, 11): - from tomllib import load as tom_load + from tomllib import loads as tom_loads else: - from tomli import load as tom_load + from tomli import loads as tom_loads -from tomli_w import dump as tom_dump +from tomli_w import dumps as tom_dumps from gourmand.gglobals import gourmanddir @@ -38,12 +38,12 @@ def get(self, key: str, default: Optional[Any] = None) -> Optional[Any]: def save(self): self.filename.parent.mkdir(exist_ok=True) with open(self.filename, 'w') as fout: - tom_dump(self, fout) + fout.write(tom_dumps(self)) def load(self) -> bool: if self.filename.is_file(): with open(self.filename) as fin: - for k, v in tom_load(fin).items(): + for k, v in tom_loads(fin.read()).items(): self.__setitem__(k, v) return True return False @@ -60,7 +60,7 @@ def update_preferences_file_format(target_dir: Path = gourmanddir): return with open(filename) as fin: - prefs = tom_load(fin) + prefs = tom_loads(fin.read()) # Gourmand 1.2.0: several sorting parameters can be saved. # The old format had `column=name` and `ascending=bool`, which are now `name=bool` @@ -70,7 +70,7 @@ def update_preferences_file_format(target_dir: Path = gourmanddir): prefs['sort_by'] = {sort_by['column']: sort_by['ascending']} with open(filename, 'w') as fout: - tom_dump(prefs, fout) + fout.write(tom_dumps(prefs)) def copy_old_installation_or_initialize(target_dir: Path): diff --git a/tests/test_prefs.py b/tests/test_prefs.py index b77aac16..8487a72f 100644 --- a/tests/test_prefs.py +++ b/tests/test_prefs.py @@ -3,13 +3,13 @@ import pytest if sys.version_info >= (3, 11): - from tomllib import load as tom_load + from tomllib import loads as tom_loads else: - from tomli import load as tom_load + from tomli import loads as tom_loads from pathlib import Path -from tomli_w import dump as tom_dump +from tomli_w import dumps as tom_dumps from gourmand.prefs import Prefs, update_preferences_file_format @@ -42,22 +42,22 @@ def test_update_preferences_file_format(tmpdir): filename = tmpdir.join('preferences.toml') with open(filename, 'w') as fout: - tom_dump({'sort_by': {'column': 'title', 'ascending': True}}, fout) + fout.write(tom_dumps({'sort_by': {'column': 'title', 'ascending': True}}) update_preferences_file_format(Path(tmpdir)) with open(filename) as fin: - d = tom_load(fin) + d = tom_loads(fin.read()) assert 'category' not in d['sort_by'].keys() assert d['sort_by']['title'] == True with open(filename, 'w') as fout: - tom_dump({}, fout) + fout.write(tom_dumps({}) update_preferences_file_format(Path(tmpdir)) with open(filename) as fin: - d = tom_load(fin) + d = tom_loads(fin.read()) assert d == {}