Добавлены тесты для всех классов

This commit is contained in:
Ilia Miheev
2026-04-30 00:41:27 +03:00
parent 4db335f399
commit d1b1fd8e0b
7 changed files with 511 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
import pytest
from ipars import JsonManager
def test_dump_and_load(tmp_path):
jm = JsonManager()
filepath = str(tmp_path / 'data.json')
data = {'name': 'ipars', 'version': 3, 'active': True}
jm.dump(filepath, data)
result = jm.load(filepath)
assert result == data
def test_dump_and_load_list(tmp_path):
jm = JsonManager()
filepath = str(tmp_path / 'list.json')
data = [1, 2, 3, 'hello']
jm.dump(filepath, data)
result = jm.load(filepath)
assert result == data
def test_dump_and_load_with_cyrillic(tmp_path):
jm = JsonManager()
filepath = str(tmp_path / 'cyrillic.json')
data = {'текст': 'привет'}
jm.dump(filepath, data)
result = jm.load(filepath)
assert result == data
def test_load_nonexistent_file():
jm = JsonManager()
with pytest.raises(FileNotFoundError):
jm.load('nonexistent_file_xyz.json')
def test_invalid_encoding_raises():
with pytest.raises(ValueError):
JsonManager(encoding=123)
def test_load_invalid_path_type():
jm = JsonManager()
with pytest.raises(ValueError):
jm.load(123)
def test_dump_invalid_path_type(tmp_path):
jm = JsonManager()
with pytest.raises(ValueError):
jm.dump(123, {'key': 'value'})
def test_pprint_does_not_raise(capsys):
jm = JsonManager()
jm.pprint({'key': 'value'})
captured = capsys.readouterr()
assert 'key' in captured.out