diff --git a/pfbudget/core/command.py b/pfbudget/core/command.py index b946ad9..61226ac 100644 --- a/pfbudget/core/command.py +++ b/pfbudget/core/command.py @@ -34,6 +34,7 @@ class ExportCommand(Command): with open(self.fn, "w", newline="") as f: json.dump([e.serialize() for e in values], f, indent=4) case ExportFormat.pickle: + raise AttributeError("pickle export not working at the moment!") with open(self.fn, "wb") as f: pickle.dump(values, f) @@ -58,6 +59,7 @@ class ImportCommand(Command): raise ImportFailedError(e) case ExportFormat.pickle: + raise AttributeError("pickle import not working at the moment!") with open(self.fn, "rb") as f: values = pickle.load(f) diff --git a/tests/test_backup.py b/tests/test_backup.py index 52f306c..b29dc2d 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -79,6 +79,15 @@ class TestBackup: assert originals == imported + command = ExportCommand(client, what, file, ExportFormat.pickle) + with pytest.raises(AttributeError): + command.execute() + + command = ImportCommand(other, what, file, ExportFormat.pickle) + with pytest.raises(AttributeError): + command.execute() + + @pytest.mark.parametrize("input, what", not_serializable) def test_try_backup_not_serializable( self, tmp_path: Path, input: Sequence[Any], what: Type[Any] diff --git a/tests/test_command.py b/tests/test_command.py index cdc6353..b62d75a 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,7 +1,6 @@ from collections.abc import Sequence import json from pathlib import Path -import pickle import pytest from typing import Any, cast @@ -68,28 +67,23 @@ class TestCommand: def test_export_pickle(self, tmp_path: Path, client: Client): file = tmp_path / "test.pickle" command = ExportCommand(client, Transaction, file, ExportFormat.pickle) - command.execute() + with pytest.raises(AttributeError): + command.execute() - with open(file, "rb") as f: - result = pickle.load(f) - assert result == mocks.transactions.simple - - cast(FakeClient, client).transactions = mocks.transactions.simple_transformed - command.execute() - - with open(file, "rb") as f: - result = pickle.load(f) - assert result == mocks.transactions.simple_transformed - - def test_import(self, tmp_path: Path, client: Client): + def test_import_json(self, tmp_path: Path, client: Client): file = tmp_path / "test" - for format in list(ExportFormat): - command = ExportCommand(client, Transaction, file, format) - command.execute() + command = ExportCommand(client, Transaction, file, ExportFormat.JSON) + command.execute() - command = ImportCommand(client, Transaction, file, format) - command.execute() + command = ImportCommand(client, Transaction, file, ExportFormat.JSON) + command.execute() - transactions = cast(FakeClient, client).transactions - assert len(transactions) > 0 - assert transactions == client.select(Transaction) + transactions = cast(FakeClient, client).transactions + assert len(transactions) > 0 + assert transactions == client.select(Transaction) + + def test_import_pickle(self, tmp_path: Path, client: Client): + file = tmp_path / "test" + command = ExportCommand(client, Transaction, file, ExportFormat.pickle) + with pytest.raises(AttributeError): + command.execute()