jenkins-bot has submitted this change and it was merged.
Change subject: Move tests to pybal.test; use Twisted's test runner
......................................................................
Move tests to pybal.test; use Twisted's test runner
Twisted extends the unittest module in Python's standard library with Trial,
its bundled unit-testing framework. It provides a number of features that are
useful for testing twisted-based code, chief among them the ability to return a
Deferred from a test-case method, with the result of the test being conditional
on the Deferred firing.
Trial's test runner does muck with unittest.TestCase's setUpClass and
tearDownClass, though, so I had to move the code we had in those methods to
setUp and tearDown (which means they run before and after each test, rather
than before and after all tests in a class). The consequence of this is
negligible.
I also moved the unit tests to pybal.test, to better conform with Trial
conventions.
Change-Id: I88492320314902908b92e28b2aeffada3b7bd19d
---
M .gitignore
M .travis.yml
R pybal/test/__init__.py
R pybal/test/test_ipvs.py
R pybal/test/test_monitor.py
R pybal/test/test_util.py
M setup.py
M tox.ini
8 files changed, 23 insertions(+), 32 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
Rush: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/.gitignore b/.gitignore
index a19910e..fd7f02e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,4 @@
*.pyc
.tox
/.coverage
-/htmlcov
+_trial_temp
diff --git a/.travis.yml b/.travis.yml
index 88d6620..1aea97d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,4 @@
language: python
python: 2.7
-script: python setup.py test
+install: pip install tox
+script: tox
diff --git a/tests/__init__.py b/pybal/test/__init__.py
similarity index 100%
rename from tests/__init__.py
rename to pybal/test/__init__.py
diff --git a/tests/test_ipvs.py b/pybal/test/test_ipvs.py
similarity index 96%
rename from tests/test_ipvs.py
rename to pybal/test/test_ipvs.py
index 8e85d53..7139970 100644
--- a/tests/test_ipvs.py
+++ b/pybal/test/test_ipvs.py
@@ -113,25 +113,22 @@
class LVSServiceTestCase(unittest.TestCase):
"""Test case for `pybal.ipvs.LVSService`."""
- @classmethod
- def setUpClass(cls):
- def stubbedModifyState(cls, cmdList):
- cls.cmdList = cmdList
-
- cls.origModifyState = pybal.ipvs.IPVSManager.modifyState
- setattr(pybal.ipvs.IPVSManager, 'modifyState',
- classmethod(stubbedModifyState))
-
- @classmethod
- def tearDownClass(cls):
- pybal.ipvs.IPVSManager.modifyState = cls.origModifyState
-
def setUp(self):
self.config = pybal.util.ConfigDict({'dryrun': 'true'})
self.service = ('tcp', '127.0.0.1', 80, 'rr')
self.server = ServerStub('localhost', port=8080)
pybal.pybal.BGPFailover.prefixes.clear()
+ def stubbedModifyState(cls, cmdList):
+ cls.cmdList = cmdList
+
+ self.origModifyState = pybal.ipvs.IPVSManager.modifyState
+ setattr(pybal.ipvs.IPVSManager, 'modifyState',
+ classmethod(stubbedModifyState))
+
+ def tearDown(self):
+ pybal.ipvs.IPVSManager.modifyState = self.origModifyState
+
def testConstructor(self):
"""Test `LVSService.__init__`."""
with self.assertRaises(ValueError):
diff --git a/tests/test_monitor.py b/pybal/test/test_monitor.py
similarity index 100%
rename from tests/test_monitor.py
rename to pybal/test/test_monitor.py
diff --git a/tests/test_util.py b/pybal/test/test_util.py
similarity index 93%
rename from tests/test_util.py
rename to pybal/test/test_util.py
index ea8d1ff..8f1e7a9 100644
--- a/tests/test_util.py
+++ b/pybal/test/test_util.py
@@ -19,20 +19,14 @@
TIMESTAMP_REGEXP = r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+'
- @classmethod
- def setUpClass(cls):
- file_handle, cls.path = tempfile.mkstemp('.pybal.test.log')
- os.close(file_handle)
-
- @classmethod
- def tearDownClass(cls):
- os.unlink(cls.path)
-
def setUp(self):
+ file_handle, self.path = tempfile.mkstemp('.pybal.test.log')
+ os.close(file_handle)
self.log_file = pybal.util.LogFile(self.path)
def tearDown(self):
self.log_file.file.close()
+ os.unlink(self.path)
def testWrite(self):
"""Test `LogFile.write`."""
diff --git a/setup.py b/setup.py
index e8e05f0..436443d 100644
--- a/setup.py
+++ b/setup.py
@@ -14,5 +14,5 @@
url="http://wikitech.wikimedia.org/view/Pybal",
packages=['pybal', 'pybal.monitors'],
requires=['twisted'],
- test_suite='tests',
- )
+ test_suite='pybal.test',
+)
diff --git a/tox.ini b/tox.ini
index a4077ce..ff66407 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,15 +2,14 @@
envlist = py27, flake8
[testenv]
-commands = {envpython} setup.py test
+commands = trial pybal
deps = twisted
[testenv:cover]
-commands = coverage run setup.py test
- coverage report --omit=".tox*,tests/*,setup.py"
- coverage html --omit=".tox*,tests/*,setup.py"
-deps = twisted
- coverage
+commands =
+ coverage run --source pybal --branch {envdir}/bin/trial pybal
+ coverage report --omit=pybal/test --show-missing
+deps = twisted coverage
[testenv:flake8]
commands = flake8
--
To view, visit https://gerrit.wikimedia.org/r/173086
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I88492320314902908b92e28b2aeffada3b7bd19d
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Mark Bergsma <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Rush <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits