-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the npm API's error handling and test coverage (#2227)
- Loading branch information
1 parent
3612f81
commit f88c2bf
Showing
2 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
from pathlib import Path | ||
from subprocess import CalledProcessError | ||
|
||
import pytest | ||
from pytest_mock import MockerFixture | ||
|
||
from betty._npm import NpmRequirement, NpmUnavailable | ||
from betty._npm import NpmRequirement, NpmUnavailable, npm | ||
|
||
|
||
class TestNpm: | ||
async def test(self) -> None: | ||
await npm(["--version"]) | ||
|
||
async def test_command_not_found(self, mocker: MockerFixture) -> None: | ||
mocker.patch("betty.subprocess.run_process", side_effect=FileNotFoundError) | ||
with pytest.raises(NpmUnavailable): | ||
await npm(["--version"]) | ||
|
||
async def test_command_error(self, mocker: MockerFixture, tmp_path: Path) -> None: | ||
mocker.patch( | ||
"betty.subprocess.run_process", | ||
side_effect=CalledProcessError(1, "", "", ""), | ||
) | ||
with pytest.raises(CalledProcessError): | ||
await npm(["--version"]) | ||
|
||
|
||
class TestNpmRequirement: | ||
async def test_check_met(self) -> None: | ||
def test_is_met(self) -> None: | ||
sut = NpmRequirement() | ||
assert sut.is_met() | ||
|
||
async def test_check_unmet(self, mocker: MockerFixture) -> None: | ||
m_npm = mocker.patch("betty._npm.npm") | ||
m_npm.side_effect = NpmUnavailable() | ||
def test_is_met_with_command_not_found(self, mocker: MockerFixture) -> None: | ||
mocker.patch("betty._npm.npm", side_effect=NpmUnavailable) | ||
sut = NpmRequirement() | ||
assert not sut.is_met() | ||
|
||
def test_is_met_with_command_error(self, mocker: MockerFixture) -> None: | ||
mocker.patch("betty._npm.npm", side_effect=CalledProcessError(1, "", "", "")) | ||
sut = NpmRequirement() | ||
assert not sut.is_met() |