Skip to content

Commit

Permalink
chore(internal): remove unused npx target
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Sep 22, 2024
1 parent 845c08e commit a20dbee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions pyright/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Binary(NamedTuple):

# we have to define twice to support runtime type checking
# on python < 3.7 as typing.get_args is not available
Target = Literal['node', 'npm', 'npx']
_TARGETS = {'node', 'npm', 'npx'}
Target = Literal['node', 'npm']
_TARGETS = {'node', 'npm'}


def check_target(value: Any) -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def tmp_path_fixture(tmp_path: Path) -> Iterator[Path]:
os.chdir(cwd)


@pytest.fixture(name='npx', scope='session')
def npx_fixture() -> str:
@pytest.fixture(name='node', scope='session')
def node_fixture() -> str:
return str(
node._ensure_available('npx').path # pyright: ignore[reportPrivateUsage]
node._ensure_available('node').path # pyright: ignore[reportPrivateUsage]
)


Expand Down
34 changes: 17 additions & 17 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytest_subprocess import FakeProcess

import pyright
from pyright import node
import pyright.node
from pyright.utils import maybe_decode

if TYPE_CHECKING:
Expand All @@ -32,39 +32,39 @@
],
)
def test_target_version(
npx: str,
node: str,
fake_process: FakeProcess,
output: bytes,
version: Tuple[int, ...],
) -> None:
fake_process.register_subprocess( # pyright: ignore[reportUnknownMemberType]
[npx, '--version'], stdout=output
[node, '--version'], stdout=output
)
assert node.version('npx') == version
assert pyright.node.version('node') == version


def test_target_version_not_found(
npx: str,
node: str,
fake_process: FakeProcess,
capsys: 'CaptureFixture[str]',
) -> None:
fake_process.register_subprocess( # pyright: ignore[reportUnknownMemberType]
[npx, '--version'], stdout='hello world'
[node, '--version'], stdout='hello world'
)

with pytest.raises(pyright.errors.VersionCheckFailed) as exc:
node.version('npx')
pyright.node.version('node')

captured = capsys.readouterr()
assert captured.out == ''
assert captured.err == 'hello world\n'
assert exc.match('Could not find version from `npx --version`, see output above')
assert exc.match('Could not find version from `node --version`, see output above')


def test_run_env_argument(tmp_path: Path) -> None:
"""Ensure the `run()` function can accept an `env` argument."""
tmp_path.joinpath('test.js').write_text('console.log(process.env.MY_ENV_VAR)')
proc = node.run(
proc = pyright.node.run(
'node',
'test.js',
env={**os.environ, 'MY_ENV_VAR': 'hello!'},
Expand All @@ -79,7 +79,7 @@ def test_run_env_argument(tmp_path: Path) -> None:
@mock.patch('pyright.node.USE_GLOBAL_NODE', False)
def test_node_version_env() -> None:
"""Ensure the custom version is respected."""
proc = node.run(
proc = pyright.node.run(
'node',
'--version',
stdout=subprocess.PIPE,
Expand All @@ -100,46 +100,46 @@ def test_update_path_env(tmp_path: Path) -> None:
assert sep in {':', ';'}

# no env
path = node._update_path_env(env=None, target_bin=target)
path = pyright.node._update_path_env(env=None, target_bin=target)
assert path.startswith(f'{target.absolute()}{sep}')

# env without PATH
path = node._update_path_env(
path = pyright.node._update_path_env(
env={'FOO': 'bar'},
target_bin=target,
)
assert path.startswith(f'{target.absolute()}{sep}')

# env with empty PATH
path = node._update_path_env(
path = pyright.node._update_path_env(
env={'PATH': ''},
target_bin=target,
)
assert path.startswith(f'{target.absolute()}{sep}')

# env with set PATH without the separator postfix
path = node._update_path_env(
path = pyright.node._update_path_env(
env={'PATH': '/foo'},
target_bin=target,
)
assert path == f'{target.absolute()}{sep}/foo'

# env with set PATH with the separator as a prefix
path = node._update_path_env(
path = pyright.node._update_path_env(
env={'PATH': f'{sep}/foo'},
target_bin=target,
)
assert path == f'{target.absolute()}{sep}/foo'

# returned env included non PATH environment variables
path = node._update_path_env(
path = pyright.node._update_path_env(
env={'PATH': '/foo', 'FOO': 'bar'},
target_bin=target,
)
assert path == f'{target.absolute()}{sep}/foo'

# accepts a custom path separator
path = node._update_path_env(
path = pyright.node._update_path_env(
env={'PATH': '/foo'},
target_bin=target,
sep='---',
Expand Down
3 changes: 1 addition & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def test_check_target() -> None:
with pytest.raises(TypeError) as exc:
check_target('foo')

assert exc.match(r'foo is not a valid target, expected one of ((npx|npm|node), )+')
assert exc.match(r'foo is not a valid target, expected one of ((npm|node), )+')
check_target('npm')
check_target('npx')
check_target('node')

0 comments on commit a20dbee

Please sign in to comment.