Skip to content

Commit

Permalink
Merge pull request #1 from choppsv1/travis
Browse files Browse the repository at this point in the history
Travis
  • Loading branch information
choppsv1 committed Oct 2, 2015
2 parents 3185725 + b09a46a commit 3fecdc2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -10,6 +10,7 @@ env:
install:
- pip install tox
- pip install coveralls
- pip install nose

script:
- tox -e $TOXENV
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -7,5 +7,6 @@ The following modules are a collection of classes and functions
useful for efficiently interacting with local and remote hosts
using ssh.

* `host` - A Host class for interacting with a host.
* `cmd` - Execute commands either locally or remotely (wiht ssh).
* `conn` - SSH channel and socket connections with caching.
* `host` - A Host class for interacting with a host.
4 changes: 2 additions & 2 deletions setup.cfg
Expand Up @@ -3,10 +3,10 @@ verbosity=1
with-doctest=1

[coverage:run]
source=sshutil
source=sshutil,tests

[pytest]
addopts = --doctest-modules --doctest-glob='sshutil/*.py'
addopts = --doctest-modules
testpaths = sshutil

[flake8]
Expand Down
4 changes: 4 additions & 0 deletions sshutil/cmd.py
Expand Up @@ -20,6 +20,7 @@
import os
import subprocess
from sshutil import conn
from sshutil.conn import setup_travis

__author__ = 'Christian Hopps'
__version__ = '1.0'
Expand Down Expand Up @@ -370,6 +371,9 @@ def run (self, command):
return self.cmd_class(self.get_cmd(command)).run()


def setup_module (unused):
setup_travis()

if __name__ == "__main__":
import time
import gc
Expand Down
8 changes: 5 additions & 3 deletions sshutil/conn.py
Expand Up @@ -334,9 +334,11 @@ def recv (self, size=MAXSSHBUF):
return self.chan.recv(size)


def _setup_module (unused):
def setup_travis ():
import sys
global private_key # pylint: disable=W0603
from sshutil.cmd import ShellCommand

logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
print("Setup called.")
if 'USER' in os.environ:
if os.environ['USER'] != "travis":
Expand All @@ -355,7 +357,7 @@ def _setup_module (unused):
else:
logger.error("Creating ssh dir " + ssh_dir)
print("Creating ssh dir " + ssh_dir)
ShellCommand("mkdir -p {}".format(ssh_dir)).run()
os.system("mkdir -p {}".format(ssh_dir))
priv = ssh.RSAKey.generate(bits=1024)
private_key = priv

Expand Down
35 changes: 35 additions & 0 deletions tests/test_cmd.py
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-#
#
# Copyright (c) 2015 by Christian E. Hopps.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import absolute_import, division, unicode_literals, print_function, nested_scopes
import os
import paramiko as ssh
from sshutil.cmd import ShellCommand, SSHCommand

__author__ = 'Christian Hopps'
__date__ = 'September 26 2015'
__docformat__ = "restructuredtext en"


def setup_module (unused):
from sshutil.conn import setup_travis
setup_travis()


def test_ssh_command ():
cmd = SSHCommand("ls -d /etc", "localhost", debug=True)
print(cmd.run())
13 changes: 7 additions & 6 deletions tox.ini
Expand Up @@ -3,10 +3,11 @@ envlist = py27,py33,py34,py35,pypy,pypy3
platform = linux2|darwin

[testenv]
commands = py.test
deps = pytest
pytest-capturelog
passenv = SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
# commands = py.test -s
# deps = pytest
commands = nosetests -v
deps = nose
passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
setenv = OBJDIR={envtmpdir}
usedevelop = True

Expand All @@ -17,14 +18,14 @@ whitelist_externals = test
deps = coveralls
coverage
{[testenv]deps}
commands = coverage run {envbindir}/py.test
commands = coverage run {envbindir}/nosetests
bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0'
bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0'

[testenv:py35]
deps = coveralls
coverage
{[testenv]deps}
commands = coverage run {envbindir}/py.test
commands = coverage run {envbindir}/nosetests
bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0'
bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0'

0 comments on commit 3fecdc2

Please sign in to comment.