Skip to content

Commit

Permalink
tests/test_utils: use the localsshmanager mark to disable the ssh test
Browse files Browse the repository at this point in the history
They should only run when explicitly requested. Also enable them on
Travis.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information
jluebbe committed Nov 11, 2018
1 parent c1ca0fa commit 9c39771
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -19,7 +19,7 @@ install:
- pip install -r travis-requirements.txt - pip install -r travis-requirements.txt
script: script:
- pip install -e . - pip install -e .
- pytest --cov-config .coveragerc --cov=labgrid - pytest --cov-config .coveragerc --cov=labgrid --local-sshmanager
- python setup.py build_sphinx - python setup.py build_sphinx
- make -C man all - make -C man all
- git --no-pager diff --exit-code - git --no-pager diff --exit-code
Expand Down
16 changes: 15 additions & 1 deletion tests/test_util.py
Expand Up @@ -77,13 +77,16 @@ def test_sshconnection_inactive_raise():
with pytest.raises(ExecutionError): with pytest.raises(ExecutionError):
con.run_command("echo Hallo") con.run_command("echo Hallo")


@pytest.mark.localsshmanager
def test_sshconnection_connect(connection_localhost): def test_sshconnection_connect(connection_localhost):
assert connection_localhost.isconnected() assert connection_localhost.isconnected()
assert os.path.exists(connection_localhost._socket) assert os.path.exists(connection_localhost._socket)


@pytest.mark.localsshmanager
def test_sshconnection_run(connection_localhost): def test_sshconnection_run(connection_localhost):
assert connection_localhost.run_command("echo Hello") == 0 assert connection_localhost.run_command("echo Hello") == 0


@pytest.mark.localsshmanager
def test_sshconnection_port_forward_add_remove(connection_localhost): def test_sshconnection_port_forward_add_remove(connection_localhost):
port = 1337 port = 1337
test_string = "Hello World" test_string = "Hello World"
Expand All @@ -100,20 +103,22 @@ def test_sshconnection_port_forward_add_remove(connection_localhost):
assert client_socket.recv(16).decode("utf-8") == test_string assert client_socket.recv(16).decode("utf-8") == test_string
connection_localhost.remove_port_forward('localhost', port) connection_localhost.remove_port_forward('localhost', port)


@pytest.mark.localsshmanager
def test_sshconnection_port_forward_remove_raise(connection_localhost): def test_sshconnection_port_forward_remove_raise(connection_localhost):
port = 1337 port = 1337


with pytest.raises(ForwardError): with pytest.raises(ForwardError):
connection_localhost.remove_port_forward('localhost', port) connection_localhost.remove_port_forward('localhost', port)


@pytest.mark.localsshmanager
def test_sshconnection_port_forward_add_duplicate(connection_localhost): def test_sshconnection_port_forward_add_duplicate(connection_localhost):
port = 1337 port = 1337


first_port = connection_localhost.add_port_forward('localhost', port) first_port = connection_localhost.add_port_forward('localhost', port)
second_port = connection_localhost.add_port_forward('localhost', port) second_port = connection_localhost.add_port_forward('localhost', port)
assert first_port == second_port assert first_port == second_port



@pytest.mark.localsshmanager
def test_sshconnection_put_file(connection_localhost, tmpdir): def test_sshconnection_put_file(connection_localhost, tmpdir):
port = 1337 port = 1337


Expand All @@ -126,33 +131,39 @@ def test_sshconnection_put_file(connection_localhost, tmpdir):
assert os.path.isfile('/tmp/test') assert os.path.isfile('/tmp/test')
assert open('/tmp/test', 'r').readlines() == [ "Teststring" ] assert open('/tmp/test', 'r').readlines() == [ "Teststring" ]


@pytest.mark.localsshmanager
def test_sshconnection_get_file(connection_localhost, tmpdir): def test_sshconnection_get_file(connection_localhost, tmpdir):


p = tmpdir.join("test") p = tmpdir.join("test")
connection_localhost.get_file('/tmp/test', p) connection_localhost.get_file('/tmp/test', p)


@pytest.mark.localsshmanager
def test_sshmanager_open(sshmanager_fix): def test_sshmanager_open(sshmanager_fix):
con = sshmanager_fix.open("localhost") con = sshmanager_fix.open("localhost")


assert isinstance(con, SSHConnection) assert isinstance(con, SSHConnection)


@pytest.mark.localsshmanager
def test_sshmanager_add_forward(sshmanager_fix): def test_sshmanager_add_forward(sshmanager_fix):
port = sshmanager_fix.request_forward("localhost", 'localhost', 3000) port = sshmanager_fix.request_forward("localhost", 'localhost', 3000)


assert port < 65536 assert port < 65536


@pytest.mark.localsshmanager
def test_sshmanager_remove_forward(sshmanager_fix): def test_sshmanager_remove_forward(sshmanager_fix):
port = sshmanager_fix.request_forward("localhost", 'localhost', 3000) port = sshmanager_fix.request_forward("localhost", 'localhost', 3000)
sshmanager_fix.remove_forward('localhost', 'localhost', 3000) sshmanager_fix.remove_forward('localhost', 'localhost', 3000)


assert 3000 not in sshmanager_fix.get('localhost')._forwards assert 3000 not in sshmanager_fix.get('localhost')._forwards


@pytest.mark.localsshmanager
def test_sshmanager_close(sshmanager_fix): def test_sshmanager_close(sshmanager_fix):
con = sshmanager_fix.open("localhost") con = sshmanager_fix.open("localhost")


assert isinstance(con, SSHConnection) assert isinstance(con, SSHConnection)
sshmanager_fix.close("localhost") sshmanager_fix.close("localhost")


@pytest.mark.localsshmanager
def test_sshmanager_remove_raise(sshmanager_fix): def test_sshmanager_remove_raise(sshmanager_fix):
con = sshmanager_fix.open("localhost") con = sshmanager_fix.open("localhost")
con.connect() con.connect()
Expand Down Expand Up @@ -191,6 +202,7 @@ def test_proxymanager_no_proxy(target):


assert (host, port) == proxymanager.get_host_and_port(nr) assert (host, port) == proxymanager.get_host_and_port(nr)


@pytest.mark.localsshmanager
def test_proxymanager_remote_forced_proxy(target): def test_proxymanager_remote_forced_proxy(target):
sshmanager.close_all() sshmanager.close_all()
host = 'localhost' host = 'localhost'
Expand All @@ -203,6 +215,7 @@ def test_proxymanager_remote_forced_proxy(target):
assert (host, port) != (nhost, nport) assert (host, port) != (nhost, nport)
sshmanager.close_all() sshmanager.close_all()


@pytest.mark.localsshmanager
def test_proxymanager_local_forced_proxy(target): def test_proxymanager_local_forced_proxy(target):
host = 'localhost' host = 'localhost'
port = 5000 port = 5000
Expand All @@ -213,6 +226,7 @@ def test_proxymanager_local_forced_proxy(target):


assert (host, port) != (nhost, nport) assert (host, port) != (nhost, nport)


@pytest.mark.localsshmanager
def test_remote_managedfile(target, tmpdir): def test_remote_managedfile(target, tmpdir):
import hashlib import hashlib
import getpass import getpass
Expand Down

0 comments on commit 9c39771

Please sign in to comment.