Skip to content

Commit

Permalink
tests: removing tomlkit from poetry locker (#131)
Browse files Browse the repository at this point in the history
companion to python-poetry/poetry#6562

Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
  • Loading branch information
dimbleby and radoering committed Nov 3, 2022
1 parent 3f27c6b commit 58f6d56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import cast

import pytest

Expand Down Expand Up @@ -179,7 +180,13 @@ def _factory(

poetry = Factory().create_poetry(project_dir)

locker = TestLocker(poetry.locker.lock.path, poetry.locker._local_config)
lock = poetry.locker.lock
if isinstance(lock, Path):
lock_path = cast("Path", lock)
else:
# poetry < 1.3
lock_path = lock.path
locker = TestLocker(lock_path, poetry.locker._local_config)
locker.write()

poetry.set_locker(locker)
Expand Down
20 changes: 10 additions & 10 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import os

from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator
from typing import cast

from poetry.console.application import Application
from poetry.core.toml.file import TOMLFile
from poetry.factory import Factory
from poetry.installation.executor import Executor
from poetry.packages import Locker


if TYPE_CHECKING:
from pathlib import Path

from poetry.core.packages.package import Package
from poetry.installation.operations.operation import Operation
from poetry.poetry import Poetry
Expand All @@ -34,17 +33,18 @@ def reset_poetry(self) -> None:
self._poetry = Factory().create_poetry(poetry.file.path.parent)
self._poetry.set_pool(poetry.pool)
self._poetry.set_config(poetry.config)
self._poetry.set_locker(
TestLocker(poetry.locker.lock.path, self._poetry.local_config)
)
lock = poetry.locker.lock
if isinstance(lock, Path):
lock_path = cast("Path", lock)
else:
# poetry < 1.3
lock_path = lock.path
self._poetry.set_locker(TestLocker(lock_path, self._poetry.local_config))


class TestLocker(Locker):
def __init__(self, lock: str | Path, local_config: dict[str, Any]) -> None:
self._lock = TOMLFile(lock)
self._local_config = local_config
self._lock_data: TOMLDocument | None = None
self._content_hash = self._get_content_hash()
super().__init__(lock, local_config)
self._locked = False
self._write = False
self._contains_credential = False
Expand Down
4 changes: 1 addition & 3 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from cleo.io.null_io import NullIO
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.toml.file import TOMLFile
from poetry.core.version.markers import parse_marker
from poetry.factory import Factory
from poetry.packages import Locker as BaseLocker
Expand Down Expand Up @@ -46,9 +45,8 @@

class Locker(BaseLocker):
def __init__(self, fixture_root: Path) -> None:
self._lock = TOMLFile(fixture_root / "poetry.lock")
super().__init__(fixture_root / "poetry.lock", {})
self._locked = True
self._content_hash = self._get_content_hash()

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

0 comments on commit 58f6d56

Please sign in to comment.