-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move bad port tests to non-integration, use mocker instead of relying on
port number to fail the test
- Loading branch information
1 parent
c3809d1
commit 8c5c9f2
Showing
6 changed files
with
50 additions
and
21 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 |
---|---|---|
@@ -1,8 +1,25 @@ | ||
from flightgear_python.fg_if import CtrlsConnection | ||
from flightgear_python.fg_util import FGConnectionError | ||
from testing_common import supported_ctrls_versions | ||
|
||
import pytest | ||
|
||
|
||
def test_ctrls_wrong_version_on_create(): | ||
with pytest.raises(NotImplementedError): | ||
CtrlsConnection(ctrls_version=1) | ||
|
||
|
||
@pytest.mark.parametrize('ctrls_version', supported_ctrls_versions) | ||
def test_ctrls_bad_port(mocker, ctrls_version): | ||
def mock_bind(addr): | ||
# Binding to port 1 should usually fail with Should fail with `[Errno 13] Permission denied` | ||
# but this is more reliable | ||
raise PermissionError('Mock permission fail') | ||
|
||
mocker.patch('socket.socket.bind', mock_bind) | ||
|
||
ctrls_c = CtrlsConnection(ctrls_version) | ||
with pytest.raises(FGConnectionError): | ||
# Should fail with [Errno 13] Permission denied | ||
ctrls_c.connect_rx('localhost', 1, lambda data, pipe: data) |
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,8 +1,25 @@ | ||
from flightgear_python.fg_if import GuiConnection | ||
from flightgear_python.fg_util import FGConnectionError | ||
from testing_common import supported_gui_versions | ||
|
||
import pytest | ||
|
||
|
||
def test_gui_wrong_version_on_create(): | ||
with pytest.raises(NotImplementedError): | ||
GuiConnection(gui_version=1) | ||
|
||
|
||
@pytest.mark.parametrize('gui_version', supported_gui_versions) | ||
def test_gui_bad_port(mocker, gui_version): | ||
def mock_bind(addr): | ||
# Binding to port 1 should usually fail with Should fail with `[Errno 13] Permission denied` | ||
# but this is more reliable | ||
raise PermissionError('Mock permission fail') | ||
|
||
mocker.patch('socket.socket.bind', mock_bind) | ||
|
||
gui_c = GuiConnection(gui_version) | ||
with pytest.raises(FGConnectionError): | ||
# Should fail with [Errno 13] Permission denied | ||
gui_c.connect_rx('localhost', 1, lambda data, pipe: data) |
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