New Addon

Google BK
This commit is contained in:
2023-04-23 18:17:03 +07:00
parent 1c7fd2b476
commit 702d080a1e
248 changed files with 72745 additions and 0 deletions
@@ -0,0 +1,60 @@
from backup.file import File
from os.path import exists, join
from os import remove
import pytest
import json
TEST_DATA = "when you press my special key I play a little melody"
def readfile(path):
with open(path) as f:
return f.read()
@pytest.mark.asyncio
async def test_basic(tmpdir: str) -> None:
path = join(tmpdir, "test.json")
backup_path = join(tmpdir, "test.json.backup")
assert not File.exists(path)
File.write(path, TEST_DATA)
assert File.exists(path)
assert readfile(path) == TEST_DATA
assert readfile(backup_path) == TEST_DATA
assert File.read(path) == TEST_DATA
File.delete(path)
assert not exists(path)
assert not exists(backup_path)
assert not File.exists(path)
@pytest.mark.asyncio
async def test_file_deleted(tmpdir: str) -> None:
path = join(tmpdir, "test.json")
File.write(path, TEST_DATA)
remove(path)
assert File.read(path) == TEST_DATA
@pytest.mark.asyncio
async def test_backup_deleted(tmpdir: str) -> None:
path = join(tmpdir, "test.json")
backup_path = join(tmpdir, "test.json.backup")
File.write(path, TEST_DATA)
remove(backup_path)
assert File.read(path) == TEST_DATA
@pytest.mark.asyncio
async def test_decode_error(tmpdir: str) -> None:
path = join(tmpdir, "test.json")
File.write(path, TEST_DATA)
with open(path, "w"):
# emptys the file contents
pass
with open(path) as f:
assert len(f.read()) == 0
assert File.read(path) == TEST_DATA