Skip to content

Commit 1978b56

Browse files
test: replace toml usage with tomli and tomli-w
Replaces toml library calls with `tomli` and `tomli-w` calls and removes the `toml` library dependency from dev dependencies.
1 parent 268cad1 commit 1978b56

File tree

6 files changed

+41
-19
lines changed

6 files changed

+41
-19
lines changed

pdm.lock

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dev = [
4444
"urllib3>=2.0.7",
4545
"pytest-html>=4.1.1",
4646
"pytest-asyncio>=0.23.3",
47-
"toml>=0.10.2",
47+
"tomli-w>=1.0.0",
4848
]
4949
[build-system]
5050
requires = ["pdm-pep517>=1.0"]

test/e2e/conftest.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import logging
22
import os
3+
from pathlib import Path
34
import subprocess
45
import sys
56
import tempfile
67
import time
78
import pytest
8-
import toml
9+
import tomli
910
from threading import Thread
10-
from toml import load
11+
12+
import tomli_w
1113
from test.e2e.utils.database_utils import TestDb
1214
from test.e2e.env_config import PORT
1315
from test.e2e.pageobjects.create_paste_page import CreatePastePage
@@ -69,11 +71,14 @@ def create_paste_page(page: Page) -> CreatePastePage:
6971
def database() -> Generator[None, None, None]:
7072
log.info("Setting up temp database")
7173
with tempfile.NamedTemporaryFile(suffix="", delete=False) as temp:
72-
props = load(config_path)
74+
props = tomli.loads(Path(config_path).read_text())
7375
props["database_uri"] = f"sqlite:///{temp.name}"
74-
props["expiries"] = {"1hour": 4, "1day": 4} # It expires in 4 seconds instead of an hour
76+
props["expiries"] = {
77+
"1hour": 4,
78+
"1day": 4,
79+
} # It expires in 4 seconds instead of an hour
7580
with open(config_path, "w") as config_file:
76-
toml.dump(props, config_file)
81+
tomli_w.dump(props, config_file)
7782
yield
7883
log.info("Tearing down temp database")
7984
close_all_sessions()
@@ -85,4 +90,6 @@ def database() -> Generator[None, None, None]:
8590
@pytest.fixture
8691
def clear_db():
8792
log.info("Clearing temp database")
88-
TestDb(load(config_path)["database_uri"]).clear_tables("paste", "file")
93+
TestDb(
94+
tomli.loads(Path(config_path).read_text())["database_uri"]
95+
).clear_tables("paste", "file")

test/e2e/utils/props_utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2+
from pathlib import Path
23

3-
from toml import load
4+
from tomli import loads
45

56

67
def load_props():
78
config_path = os.path.join("test", "e2e", "pinnwand.toml")
8-
return load(config_path)
9+
return loads(Path(config_path).read_text())

test/integration/test_config.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22

3+
import tomli_w
4+
35
from pinnwand.configuration import Configuration
46
import tempfile
5-
import toml
7+
import tomli
68
import pytest
79

810

@@ -39,14 +41,13 @@ def test_env_variables_precedence(monkeypatch, temp_dotenv_file):
3941
def test_load_file_config():
4042
with tempfile.NamedTemporaryFile(suffix="", delete=False) as temp:
4143

42-
props = toml.load(temp.name)
44+
props = tomli.load(temp)
4345
url = "sqlite:///database.db"
4446
props["database_uri"] = url
4547

46-
with open(temp.name, "w") as config_file:
47-
toml.dump(props, config_file)
48+
with open(temp.name, "wb") as config_file:
49+
tomli_w.dump(props, config_file)
4850
config: Configuration = Configuration()
4951

5052
config.load_config_file(temp.name)
5153
assert config.database_uri == url
52-

test/integration/test_reaping_job.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import asyncio
22
import os
3+
from pathlib import Path
34
import tempfile
4-
import toml
5+
import tomli
56
from unittest.mock import patch, MagicMock
67
from sqlalchemy import create_engine
78

89

910
import pytest
1011
from click.testing import CliRunner
12+
import tomli_w
1113

1214
from pinnwand import command, utility
1315
from pinnwand.database import utils, manager, models
@@ -19,11 +21,11 @@
1921
def temp_database_url() -> str:
2022
"""Override the config's database_url with a temporary one."""
2123
with tempfile.NamedTemporaryFile(suffix="", delete=False) as temp:
22-
props = toml.load(config_path)
24+
props = tomli.loads(Path(config_path).read_text())
2325
url = f"sqlite:///{temp.name}"
2426
props["database_uri"] = url
25-
with open(config_path, "w") as config_file:
26-
toml.dump(props, config_file)
27+
with open(config_path, "wb") as config_file:
28+
tomli_w.dump(props, config_file)
2729

2830
yield url
2931

0 commit comments

Comments
 (0)