Skip to content

Commit 58f6d56

Browse files
dimblebyradoering
andauthored
tests: removing tomlkit from poetry locker (#131)
companion to python-poetry/poetry#6562 Co-authored-by: Randy Döring <[email protected]>
1 parent 3f27c6b commit 58f6d56

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from typing import TYPE_CHECKING
77
from typing import Any
8+
from typing import cast
89

910
import pytest
1011

@@ -179,7 +180,13 @@ def _factory(
179180

180181
poetry = Factory().create_poetry(project_dir)
181182

182-
locker = TestLocker(poetry.locker.lock.path, poetry.locker._local_config)
183+
lock = poetry.locker.lock
184+
if isinstance(lock, Path):
185+
lock_path = cast("Path", lock)
186+
else:
187+
# poetry < 1.3
188+
lock_path = lock.path
189+
locker = TestLocker(lock_path, poetry.locker._local_config)
183190
locker.write()
184191

185192
poetry.set_locker(locker)

tests/helpers.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
import os
44

55
from contextlib import contextmanager
6+
from pathlib import Path
67
from typing import TYPE_CHECKING
78
from typing import Any
89
from typing import Iterator
10+
from typing import cast
911

1012
from poetry.console.application import Application
11-
from poetry.core.toml.file import TOMLFile
1213
from poetry.factory import Factory
1314
from poetry.installation.executor import Executor
1415
from poetry.packages import Locker
1516

1617

1718
if TYPE_CHECKING:
18-
from pathlib import Path
19-
2019
from poetry.core.packages.package import Package
2120
from poetry.installation.operations.operation import Operation
2221
from poetry.poetry import Poetry
@@ -34,17 +33,18 @@ def reset_poetry(self) -> None:
3433
self._poetry = Factory().create_poetry(poetry.file.path.parent)
3534
self._poetry.set_pool(poetry.pool)
3635
self._poetry.set_config(poetry.config)
37-
self._poetry.set_locker(
38-
TestLocker(poetry.locker.lock.path, self._poetry.local_config)
39-
)
36+
lock = poetry.locker.lock
37+
if isinstance(lock, Path):
38+
lock_path = cast("Path", lock)
39+
else:
40+
# poetry < 1.3
41+
lock_path = lock.path
42+
self._poetry.set_locker(TestLocker(lock_path, self._poetry.local_config))
4043

4144

4245
class TestLocker(Locker):
4346
def __init__(self, lock: str | Path, local_config: dict[str, Any]) -> None:
44-
self._lock = TOMLFile(lock)
45-
self._local_config = local_config
46-
self._lock_data: TOMLDocument | None = None
47-
self._content_hash = self._get_content_hash()
47+
super().__init__(lock, local_config)
4848
self._locked = False
4949
self._write = False
5050
self._contains_credential = False

tests/test_exporter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from cleo.io.null_io import NullIO
1010
from poetry.core.packages.dependency import Dependency
1111
from poetry.core.packages.dependency_group import MAIN_GROUP
12-
from poetry.core.toml.file import TOMLFile
1312
from poetry.core.version.markers import parse_marker
1413
from poetry.factory import Factory
1514
from poetry.packages import Locker as BaseLocker
@@ -46,9 +45,8 @@
4645

4746
class Locker(BaseLocker):
4847
def __init__(self, fixture_root: Path) -> None:
49-
self._lock = TOMLFile(fixture_root / "poetry.lock")
48+
super().__init__(fixture_root / "poetry.lock", {})
5049
self._locked = True
51-
self._content_hash = self._get_content_hash()
5250

5351
def locked(self, is_locked: bool = True) -> Locker:
5452
self._locked = is_locked

0 commit comments

Comments
 (0)