Skip to content

Commit e1d0c12

Browse files
author
Chad Smith
authored
use pytest (#297)
* use pytest
1 parent c3dabbf commit e1d0c12

File tree

8 files changed

+96
-82
lines changed

8 files changed

+96
-82
lines changed

.coveragerc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[report]
2+
exclude_lines =
3+
pragma: no cover
4+
def __repr__
5+
if self.debug:
6+
if settings.DEBUG
7+
raise AssertionError
8+
raise NotImplementedError
9+
if __name__ == .__main__.:

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ matrix:
2525
- python: '3.7'
2626
env: NOXSESSION="docs"
2727
dist: xenial
28+
- python: '3.8-dev'
29+
env: NOXSESSION="tests-3.8"
30+
dist: xenial
2831

2932
install:
3033
# commands for linux

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ prune gdbgui/__pycache__
1313

1414
exclude mypy.ini
1515
exclude .eslintrc.json
16+
exclude .coveragerc
1617
exclude .flake8
1718
exclude .prettierrc.js
1819
exclude jest.config.js

noxfile.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,33 @@
1313
@nox.session(python=python)
1414
def tests(session):
1515
session.install(".")
16-
session.run("python", "-m", "unittest", "discover")
16+
tests = session.posargs or ["tests"]
17+
session.install(".", "pytest", "pytest-cov")
18+
tests = session.posargs or ["tests"]
19+
session.run(
20+
"pytest", "--cov=gdbgui", "--cov-config", ".coveragerc", "--cov-report=", *tests
21+
)
22+
1723
session.run("yarn", "install", external=True)
1824
session.run("yarn", "test", external=True)
1925
session.run("yarn", "build", external=True)
2026

27+
session.notify("cover")
28+
29+
30+
@nox.session
31+
def cover(session):
32+
"""Coverage analysis"""
33+
session.install("coverage")
34+
session.run(
35+
"coverage",
36+
"report",
37+
"--show-missing",
38+
"--omit=gdbgui/SSLify.py",
39+
"--fail-under=30",
40+
)
41+
session.run("coverage", "erase")
42+
2143

2244
@nox.session(python="3.7")
2345
def lint(session):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"Programming Language :: Python :: 3",
6969
"Programming Language :: Python :: 3.6",
7070
"Programming Language :: Python :: 3.7",
71+
"Programming Language :: Python :: 3.8",
7172
],
7273
python_requires=">=3.6",
7374
project_urls={

tests/test_app.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/test_backend.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from gdbgui import backend
2+
from flask_socketio import send, SocketIO # type: ignore
3+
import pytest # type: ignore
4+
5+
6+
backend.setup_backend(testing=True)
7+
socketio = backend.socketio
8+
9+
10+
def test_connect():
11+
app = backend.app
12+
socketio = SocketIO()
13+
14+
@socketio.on("connect")
15+
def on_connect():
16+
send({"connected": "foo"}, json=True)
17+
18+
socketio.init_app(app, cookie="foo")
19+
client = socketio.test_client(app)
20+
received = client.get_received()
21+
assert len(received) == 1
22+
assert received[0]["args"] == {"connected": "foo"}
23+
24+
25+
@pytest.fixture
26+
def test_client():
27+
return backend.app.test_client()
28+
29+
30+
def test_load_main_page(test_client):
31+
response = test_client.get("/")
32+
assert response.status_code == 200
33+
assert "<!DOCTYPE html>" in response.data.decode()
34+
35+
36+
def test_same_port():
37+
backend.setup_backend(testing=True)

tests/test_main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import gdbgui
2+
import pytest # type: ignore
3+
import sys
4+
5+
6+
@pytest.mark.parametrize(
7+
"test_argv, init_bin_args, gdb_args",
8+
[
9+
(["gdbgui"], [], []),
10+
(["gdbgui", "--gdb-args", "mybin -myargs"], [], ["mybin", "-myargs"]),
11+
(["gdbgui", "--args", "mybin", "-myargs"], ["mybin", "-myargs"], []),
12+
],
13+
)
14+
def test_argument_parsing(monkeypatch, test_argv, init_bin_args, gdb_args):
15+
def mock_setup_backend(*args, **kwargs):
16+
pass
17+
18+
monkeypatch.setattr(gdbgui.backend, "setup_backend", mock_setup_backend)
19+
monkeypatch.setattr(sys, "argv", test_argv)
20+
gdbgui.backend.main()
21+
assert gdbgui.backend.app.config.get("initial_binary_and_args") == init_bin_args
22+
assert gdbgui.backend.app.config.get("gdb_args") == gdb_args

0 commit comments

Comments
 (0)