Skip to content

Commit

Permalink
Restore Windows compatibility in doctest.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed May 24, 2023
1 parent 436ce31 commit 21ab99d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import ntpath
import posixpath
import pprint
import textwrap

import jaraco.path
Expand Down Expand Up @@ -51,3 +54,18 @@ class Paths:
@pytest.fixture(params=['persist', 'ephemeral'])
def run_mode(monkeypatch, request):
monkeypatch.setenv('PIP_RUN_MODE', request.param)


@pytest.fixture
def doctest_namespace():
def norm_path(path):
return (
path.replace(ntpath.sep, posixpath.sep)
.replace(ntpath.pathsep, posixpath.sep)
.replace('//', '/')
)

def norm_env_paths(env):
return {key: norm_path(value) for key, value in env.items()}

return dict(locals(), pprint=pprint.pprint)
4 changes: 2 additions & 2 deletions pip_run/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def _build_env(target, *, orig=os.environ):
"""
Prepend target to PYTHONPATH and add $target/bin to PATH.
>>> import pprint
>>> orig = dict(PYTHONPATH='/orig', PATH='/orig')
>>> pprint.pprint(_build_env(pathlib.Path('/tmp/pip-run/target'), orig=orig))
>>> env = _build_env(pathlib.Path('/tmp/pip-run/target'), orig=orig)
>>> pprint(norm_env_paths(env))
{'PATH': '/tmp/pip-run/target/bin:/orig',
'PYTHONPATH': '/tmp/pip-run/target:/orig'}
"""
Expand Down

0 comments on commit 21ab99d

Please sign in to comment.