-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
160 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
paths: | ||
- rexi/** | ||
- tests/** | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
- uses: snok/install-poetry@v1 | ||
- uses: actions/cache@v3 | ||
id: cached-poetry-dependencies | ||
with: | ||
path: .venv | ||
key: venv-Linux-3.11-${{ hashFiles('**/pyproject.toml') }} | ||
- name: install deps | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: make install | ||
- name: lint | ||
run: make lint | ||
|
||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- uses: snok/install-poetry@v1 | ||
- uses: actions/cache@v3 | ||
id: cached-poetry-dependencies | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }} | ||
- name: install deps | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: rm -rf poetry.lock && make install | ||
- name: test | ||
run: make test | ||
- uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
import os | ||
import sys | ||
|
||
import typer | ||
|
||
from .rexi import RexiApp | ||
|
||
app = typer.Typer() | ||
|
||
|
||
# noinspection SpellCheckingInspection | ||
@app.command("rexi") | ||
def rexi_cli() -> None: | ||
stdin = sys.stdin.read() | ||
try: | ||
os.close(sys.stdin.fileno()) | ||
except OSError: | ||
pass | ||
sys.stdin = open("/dev/tty", "rb") # type: ignore[assignment] | ||
app: RexiApp[int] = RexiApp(stdin) | ||
app.run() |
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,26 @@ | ||
from io import BytesIO | ||
from unittest.mock import Mock | ||
|
||
from _pytest.monkeypatch import MonkeyPatch | ||
from typer.testing import CliRunner | ||
from rexi.cli import app | ||
|
||
|
||
def test_app(monkeypatch: MonkeyPatch) -> None: | ||
""" | ||
Couldn't find a better way to test the CLI without patching everything :( | ||
""" | ||
runner = CliRunner() | ||
text = b"This iS! aTe xt2 F0r T3sT!ng" | ||
a = BytesIO(text) | ||
class_mock = Mock() | ||
instance_mock = Mock() | ||
open_mock = Mock() | ||
with monkeypatch.context(): | ||
class_mock.return_value = instance_mock | ||
monkeypatch.setattr("rexi.cli.RexiApp", class_mock) | ||
monkeypatch.setattr("builtins.open", open_mock) | ||
runner.invoke(app, input=a) | ||
open_mock.assert_called_once_with("/dev/tty", "rb") | ||
class_mock.assert_called_once_with(text.decode()) | ||
instance_mock.run.assert_called_once() |
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