diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 00000000..82f7f004 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,9 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} \ + ${PYTHON:-python} -m subunit.run discover -s ${OS_TEST_PATH:-./tests} -t . $LISTOPT $IDOPTION + +test_id_option=--load-list $IDFILE +test_list_option=--list +group_regex=([^\.]+\.)+ diff --git a/freezer/bandwidth.py b/freezer/bandwidth.py index 9dfed39b..65bedfc6 100644 --- a/freezer/bandwidth.py +++ b/freezer/bandwidth.py @@ -1,5 +1,5 @@ import socket -from time import time, sleep +import time class ThrottledSocket(object): @@ -15,15 +15,15 @@ class ThrottledSocket(object): return setattr(self._wrappedsock, attr, value) def recv(self, *args): - start = time() + start = time.time() buf = self._wrappedsock.recv(*args) - self._sleep(len(buf), self.download_limit, start, time()) + self._sleep(len(buf), self.download_limit, start, time.time()) return buf def sendall(self, *args): - start = time() + start = time.time() res = self._wrappedsock.send(*args) - self._sleep(res, self.upload_limit, start, time()) + self._sleep(res, self.upload_limit, start, time.time()) @staticmethod def _sleep_duration(transmitted, limit, start_time, end_time): @@ -40,7 +40,7 @@ class ThrottledSocket(object): start_time, end_time) if sleep_duration > 0: - sleep(sleep_duration) + time.sleep(sleep_duration) def makefile(self, mode='r', bufsize=-1): return socket._fileobject(self, mode, bufsize) diff --git a/freezer/job.py b/freezer/job.py index b1629f3e..a11dd1fc 100644 --- a/freezer/job.py +++ b/freezer/job.py @@ -19,14 +19,14 @@ Hudson (tjh@cryptsoft.com). ======================================================================== """ -import sys import datetime +import sys import time -from freezer import utils from freezer import backup from freezer import exec_cmd from freezer import restore +from freezer import utils import logging diff --git a/requirements.txt b/requirements.txt index 12f5a48a..61b48eff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,5 @@ pymongo>=2.6.3,<3.0 apscheduler # Not in global-requirements pep3143daemon +paramiko>=1.13.0 + diff --git a/test-requirements.txt b/test-requirements.txt index c889c143..76e45f49 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,10 @@ -pytest flake8>=2.2.4,<=2.4.1 -mock>=1.1,!=1.1.4;python_version!='2.6' -mock==1.0.1;python_version=='2.6' - +pylint>=1.3.1 +hacking>=0.10.2,<0.11 +coverage>=3.6 +discover +mock>=1.0 +oslosphinx +sphinx>=1.1.2,<1.2 +testrepository>=0.0.18 +testtools>=0.9.34 diff --git a/tests/storages/test_local.py b/tests/storages/test_local.py index a38e2369..e3d8bbb0 100644 --- a/tests/storages/test_local.py +++ b/tests/storages/test_local.py @@ -1,11 +1,10 @@ import tempfile import shutil -import pytest from freezer.storage import local from freezer import utils -@pytest.mark.incremental + class TestLocalStorage(object): BACKUP_DIR_PREFIX = "freezer_test_backup_dir" FILES_DIR_PREFIX = "freezer_test_files_dir" diff --git a/tests/test_bandwidth.py b/tests/test_bandwidth.py index d1ade2d3..32556cf4 100644 --- a/tests/test_bandwidth.py +++ b/tests/test_bandwidth.py @@ -1,6 +1,5 @@ from freezer.bandwidth import ThrottledSocket, monkeypatch_bandwidth from commons import FakeSocket -import pytest class TestBandwidth: diff --git a/tests/test_job.py b/tests/test_job.py index 8c6180fb..04a9a36b 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -30,7 +30,6 @@ from freezer import (restore, backup) from freezer.job import Job, InfoJob, AdminJob, BackupJob, RestoreJob, create_job import logging from mock import patch, Mock -import pytest import unittest diff --git a/tests/test_main.py b/tests/test_main.py index 9a726796..3d25583e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -24,7 +24,6 @@ from commons import FakeSys from freezer import job from freezer.main import freezer_main -import pytest import sys ''' diff --git a/tests/test_utils.py b/tests/test_utils.py index bb7d9fe5..f56347d4 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,4 @@ from freezer import utils -import pytest import datetime from commons import * diff --git a/tests/test_vss.py b/tests/test_vss.py index 91a5380a..3b325f93 100644 --- a/tests/test_vss.py +++ b/tests/test_vss.py @@ -22,8 +22,6 @@ import subprocess import os import logging -import pytest - class TestVss: diff --git a/tests/test_winutils.py b/tests/test_winutils.py index fa938ba0..82482c18 100644 --- a/tests/test_winutils.py +++ b/tests/test_winutils.py @@ -21,8 +21,6 @@ from freezer import winutils from commons import * import logging -import pytest - class TestWinutils: diff --git a/tox.ini b/tox.ini index eea4594d..0763c586 100644 --- a/tox.ini +++ b/tox.ini @@ -5,17 +5,9 @@ skipsdist = True [testenv] usedevelop = True deps = - pytest - coverage - flake8 - pytest-cov - pytest-xdist - pymysql - python-openstackclient>=1.0.3,<1.1.0 - mock - pep3143daemon - apscheduler - pylint>=1.3.1 + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + passenv = FREEZER_TEST_SSH_KEY FREEZER_TEST_SSH_USERNAME @@ -30,12 +22,28 @@ passenv = install_command = pip install -U {opts} {packages} setenv = VIRTUAL_ENV={envdir} -commands = py.test -v --cov-report term-missing --cov freezer -[pytest] +whitelist_externals = + coverage + rm + +commands = + python setup.py testr --coverage --testr-args="{posargs}" + coverage report -m + rm -f .coverage + python_files = test_*.py norecursedirs = .tox .venv freezer_api freezer/binaries +[testend:venv] +commands = {posargs} + +[tox:jenkins] +downloadcache = ~/cache/pip + +[testenv:cover] +commands = python setup.py testr --coverage + [testenv:pep8] commands = flake8 freezer @@ -43,5 +51,13 @@ commands = flake8 freezer commands = pylint --rcfile .pylintrc freezer bin/freezerc [flake8] +# it's not a bug that we aren't using all of hacking +# H102 -> apache2 license exists +# H103 -> license is apache +# H201 -> no bare excepts +# H501 -> don't use locals() for str formatting +# H903 -> \n not \r\n +ignore = H +select = H102, H103, H201, H501, H903, H201, H306, H301, H233 show-source = True exclude = .venv,.tox,dist,doc,test,*egg,tests