Skip to content

Commit

Permalink
Merge branch 'main' into symlinked-packages-work
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 18, 2023
2 parents 7a19e8a + 62144eb commit c701bcd
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/_path.py
@@ -1,4 +1,4 @@
# from jaraco.path 3.5
# from jaraco.path 3.6

import functools
import pathlib
Expand All @@ -11,7 +11,13 @@
from typing_extensions import Protocol, runtime_checkable # type: ignore


FilesSpec = Dict[str, Union[str, bytes, 'FilesSpec']] # type: ignore
class Symlink(str):
"""
A string indicating the target of a symlink.
"""


FilesSpec = Dict[str, Union[str, bytes, Symlink, 'FilesSpec']] # type: ignore


@runtime_checkable
Expand All @@ -28,6 +34,9 @@ def write_text(self, content, **kwargs):
def write_bytes(self, content):
... # pragma: no cover

def symlink_to(self, target):
... # pragma: no cover


def _ensure_tree_maker(obj: Union[str, TreeMaker]) -> TreeMaker:
return obj if isinstance(obj, TreeMaker) else pathlib.Path(obj) # type: ignore
Expand All @@ -51,12 +60,16 @@ def build(
... "__init__.py": "",
... },
... "baz.py": "# Some code",
... }
... "bar.py": Symlink("baz.py"),
... },
... "bing": Symlink("foo"),
... }
>>> target = getfixture('tmp_path')
>>> build(spec, target)
>>> target.joinpath('foo/baz.py').read_text(encoding='utf-8')
'# Some code'
>>> target.joinpath('bing/bar.py').read_text(encoding='utf-8')
'# Some code'
"""
for name, contents in spec.items():
create(contents, _ensure_tree_maker(prefix) / name)
Expand All @@ -79,8 +92,8 @@ def _(content: str, path):


@create.register
def _(content: str, path):
path.write_text(content, encoding='utf-8')
def _(content: Symlink, path):
path.symlink_to(content)


class Recording:
Expand All @@ -107,3 +120,6 @@ def write_text(self, content, **kwargs):

def mkdir(self, **kwargs):
return

def symlink_to(self, target):
pass

0 comments on commit c701bcd

Please sign in to comment.