Skip to content

Commit

Permalink
Merge pull request #83 from TGoddessana/improve-test
Browse files Browse the repository at this point in the history
Improve test, remove uncecessary codes
  • Loading branch information
TGoddessana authored Feb 11, 2024
2 parents a10f56b + d1d994d commit 2e4fe68
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 41 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
from flask import Flask


@pytest.fixture
def app() -> Flask:
app = Flask(__name__)
app.config["TESTING"] = True
return app
6 changes: 3 additions & 3 deletions tests/shells/test_bpython_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@


@pytest.fixture
def bpython_shell():
def bpython_shell() -> BPythonShell:
return BPythonShell()


def test_get_shell_name(bpython_shell):
def test_get_shell_name(bpython_shell: BPythonShell) -> None:
assert bpython_shell.get_shell_name() == "BPython"


def test_get_shell_version(bpython_shell):
def test_get_shell_version(bpython_shell: BPythonShell) -> None:
assert bpython_shell.get_shell_version() == version("bpython")
6 changes: 3 additions & 3 deletions tests/shells/test_ipython_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@


@pytest.fixture
def ipython_shell():
def ipython_shell() -> IPythonShell:
return IPythonShell()


def test_get_shell_name(ipython_shell):
def test_get_shell_name(ipython_shell: IPythonShell) -> None:
assert ipython_shell.get_shell_name() == "IPython"


def test_get_shell_version(ipython_shell):
def test_get_shell_version(ipython_shell: IPythonShell) -> None:
from IPython import __version__

assert ipython_shell.get_shell_version() == __version__
25 changes: 3 additions & 22 deletions tests/shells/test_ptpython_shell.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
from importlib.metadata import version

import pytest
from flask import Flask

from flask_moreshell.shells.ptpython_shell import PTPythonShell


@pytest.fixture
def app():
app = Flask(__name__)
app.config["TESTING"] = True
return app


@pytest.fixture
def ptpython_shell():
def ptpython_shell() -> PTPythonShell:
return PTPythonShell()


def test_get_shell_name(ptpython_shell):
def test_get_shell_name(ptpython_shell: PTPythonShell) -> None:
assert ptpython_shell.get_shell_name() == "PTPython"


def test_get_shell_version(ptpython_shell):
def test_get_shell_version(ptpython_shell: PTPythonShell) -> None:
assert ptpython_shell.get_shell_version() == version("ptpython")


def test_load(ptpython_shell, monkeypatch, capsys, app):
with app.app_context():
ptpython_shell.load()

stdout = capsys.readouterr().out

assert ptpython_shell.get_shell_name() in stdout
assert ptpython_shell.get_shell_version() in stdout
assert "PTPython" in stdout
18 changes: 5 additions & 13 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,32 @@


@pytest.fixture
def app():
def app() -> Flask:
app = Flask(__name__)
app.config["TESTING"] = True
return app


@pytest.fixture
def runner(app):
def runner(app: Flask) -> CliRunner:
return CliRunner()


def test_ipython_shell(runner, app):
def test_ipython_shell(runner: CliRunner, app: Flask) -> None:
with app.app_context():
result = runner.invoke(shell, ["--shelltype", "ipython"])
assert result.exit_code == 0
assert "IPython" in result.output


# def test_bpython_shell(runner, app):
# with app.app_context():
# result = runner.invoke(shell, ["--shelltype", "bpython"])
# assert result.output == ""
# assert result.exit_code == 0
# assert "BPython" in result.output


def test_pypython_shell(runner, app):
def test_ptpython_shell(runner: CliRunner, app: Flask) -> None:
with app.app_context():
result = runner.invoke(shell, ["--shelltype", "ptpython"])
assert result.exit_code == 0
assert "PTPython" in result.output


def test_python_shell(runner, app):
def test_python_shell(runner: CliRunner, app: Flask) -> None:
with app.app_context():
result = runner.invoke(shell, ["--shelltype", "python"])
assert result.exit_code == 0
Expand Down

0 comments on commit 2e4fe68

Please sign in to comment.