-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'check' command and update actions
- Loading branch information
Showing
10 changed files
with
187 additions
and
23 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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
|
||
from glotter.source import get_sources, BAD_SOURCES | ||
from glotter.settings import Settings | ||
|
||
|
||
def check(_args): | ||
# Get all sources | ||
all_sources = get_sources(Settings().source_root, check_bad_sources=True) | ||
|
||
# If no bad sources, exit with zero status | ||
bad_sources = all_sources[BAD_SOURCES] | ||
if not bad_sources: | ||
print("All filenames correspond to valid projects") | ||
sys.exit(0) | ||
|
||
# Show bad sources and exit with non-zero status | ||
print("The following filenames do not correspond to a valid project:") | ||
for source in sorted(bad_sources): | ||
print(f"- {source}") | ||
|
||
sys.exit(1) |
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import sys | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from glotter.__main__ import main | ||
from glotter.source import BAD_SOURCES | ||
|
||
|
||
def test_check_no_errors(mock_get_sources, mock_settings, mock_sources, capsys): | ||
mock_get_sources.return_value = {**mock_sources, BAD_SOURCES: []} | ||
|
||
with pytest.raises(SystemExit) as e: | ||
call_check() | ||
|
||
assert e.value.code == 0 | ||
|
||
output = capsys.readouterr().out | ||
assert "All filenames correspond to valid projects" in output | ||
|
||
|
||
def test_check_errors(mock_get_sources, mock_settings, mock_sources, capsys): | ||
mock_get_sources.return_value = { | ||
**mock_sources, | ||
BAD_SOURCES: ["stuff/nonsense", "garbage/blah", "junk/whatever"], | ||
} | ||
|
||
with pytest.raises(SystemExit) as e: | ||
call_check() | ||
|
||
assert e.value.code != 0 | ||
|
||
output = capsys.readouterr().out | ||
expected_output = """\ | ||
- garbage/blah | ||
- junk/whatever | ||
- stuff/nonsense | ||
""" | ||
assert expected_output in output | ||
|
||
|
||
def call_check(args=None): | ||
args = args or [] | ||
with patch.object(sys, "argv", ["glotter", "check"] + args): | ||
main() | ||
|
||
|
||
class MockArgs: | ||
pass | ||
|
||
|
||
@pytest.fixture() | ||
def mock_get_sources(): | ||
with patch("glotter.check.get_sources") as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture() | ||
def mock_settings(): | ||
with patch("glotter.test_doc_generator.Settings") as mock: | ||
yield mock |