spv-dev team mailing list archive
-
spv-dev team
-
Mailing list archive
-
Message #00021
[Merge] lp:~bouf10/slidepresenterview/tests-osspecific into lp:slidepresenterview
F.-A. Bourbonnais has proposed merging lp:~bouf10/slidepresenterview/tests-osspecific into lp:slidepresenterview.
Requested reviews:
SlidePresenterView Development Team (spv-dev)
- Add decorators to indicate if a tests must be run only on a specific platform
- Migrate all unit tests to unittest2
- New MultiplePrefixesTestLoader to also discover methods prefixes with 'should' in test's __main__
Unittest2
=========
Unittest2 (http://pypi.python.org/pypi/unittest2) is the backport of all new unittest's features from Python 2.7/3.2 to Python 2.4+.
I switched to unittest2 since the Skip* decorators has been already added to unittest2. And many other new features could be really useful for SPV.
See those references to learn what is new:
- http://www.voidspace.org.uk/python/articles/unittest2.shtml#unittest-is-changing
- http://docs.python.org/dev/library/unittest.html
Consequences
============
- Nose 0.11.*2* is required
- All unit tests must import unittest2 (already done for this branch based on trunk)
- *Be sure to migrate your tests too when merging into your branch*
- *Be sure to adjust your __main__ to use the custom tests loader*
--
https://code.launchpad.net/~bouf10/slidepresenterview/tests-osspecific/+merge/29656
Your team SlidePresenterView Development Team is requested to review the proposed merge of lp:~bouf10/slidepresenterview/tests-osspecific into lp:slidepresenterview.
=== modified file 'HACKING'
--- HACKING 2010-05-05 01:54:25 +0000
+++ HACKING 2010-07-11 17:41:04 +0000
@@ -8,8 +8,8 @@
- All runtime dependencies
- PyQt4 dev (for pyuic4)
* See runtime dependencies
- - Nose (to run tests)
- * easy_install nose
+ - Nose >=0.11.2 (to run tests)
+ * easy_install "nose>=0.11.2"
- Voidspace's Mock
* Since 2010-01, we use a patched version of Mock. That version
in already included in thirdparty/mock.py.
=== modified file 'setup.cfg'
--- setup.cfg 2010-05-03 02:55:07 +0000
+++ setup.cfg 2010-07-11 17:41:04 +0000
@@ -5,3 +5,4 @@
with-freshen=1
testmatch=(?:^|[\b_\.%s-])([Tt]est|should)
where=slidepresenterview/
+exclude=slidepresenterview/tests/manual
=== modified file 'slidepresenterview/tests/__init__.py'
--- slidepresenterview/tests/__init__.py 2010-01-07 04:58:32 +0000
+++ slidepresenterview/tests/__init__.py 2010-07-11 17:41:04 +0000
@@ -25,7 +25,7 @@
import os
import doctest
-import unittest
+import unittest2
@@ -50,6 +50,37 @@
sys.path.insert(0, os.path.join(BASE_DIR, 'thirdparty'))
+#########
+# Extensions
+#####
+
+class MultiplePrefixesTestLoader(unittest2.TestLoader):
+ """
+ Extension of TestLoader to support multiple prefixes
+ for test methods' name
+
+ By default, prefixes are 'test' and 'should'
+ """
+
+ testMethodPrefixes = ['test', 'should']
+
+ def getTestCaseNames(self, testCaseClass):
+ names_all_prefixes = []
+ for prefix in self.testMethodPrefixes:
+ self.testMethodPrefix = prefix
+ names = unittest2.TestLoader.getTestCaseNames(self, testCaseClass)
+ names_all_prefixes.extend(names)
+ return names_all_prefixes
+
+
+def SkipIfNotWindows():
+ return unittest2.skipIf(os.name not in ['win32', 'ce'],
+ "Not running on Windows (but %s)." % os.name)
+
+def SkipIfNotPosix():
+ return unittest2.skipIf(os.name not in ['posix', 'mac'],
+ "Not running on Posix (but %s)." % os.name)
+
##########
# Informations
=== added directory 'slidepresenterview/tests/manual'
=== added file 'slidepresenterview/tests/manual/__init__.py'
=== added file 'slidepresenterview/tests/manual/osspecific.py'
--- slidepresenterview/tests/manual/osspecific.py 1970-01-01 00:00:00 +0000
+++ slidepresenterview/tests/manual/osspecific.py 2010-07-11 17:41:04 +0000
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# SlidePresenterView - Console for presenters
+# https://launchpad.net/slidepresenterview
+#
+# Copyright (C) 2010 Felix-Antoine Bourbonnais <bouf10pub _AT@. rubico.info>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import os
+
+BASE_DIR = '../../..'
+_file_path = os.path.dirname(__file__)
+_base_path = os.path.abspath(os.path.join(_file_path, BASE_DIR))
+
+import sys
+sys.path.insert(0, _base_path)
+
+import unittest2
+import nose
+
+from slidepresenterview.tests import SkipIfNotPosix, SkipIfNotWindows
+
+
+@SkipIfNotWindows()
+class WindowsTest(unittest2.TestCase):
+
+ def testUTestsWithWin(self):
+ pass
+
+
+@SkipIfNotPosix()
+class PosixTest(unittest2.TestCase):
+
+ def testUTestsWithPosix(self):
+ pass
+
+
+class PerMethodTest(unittest2.TestCase):
+
+ @SkipIfNotWindows()
+ def testOnlyWindows(self):
+ pass
+
+ @SkipIfNotPosix()
+ def testOnlyPosix(self):
+ pass
+
+
+if __name__ == "__main__":
+ print "----- Unitest2 -----"
+ unittest2.main(verbosity=2, exit=False)
+ sys.stdout.flush()
+ sys.stderr.flush()
+ print ""
+ print "----- Nose ---------"
+ env = os.environ
+ env['NOSE_VERBOSE'] = '2'
+ nose.runmodule(env=env)
\ No newline at end of file
=== modified file 'slidepresenterview/tests/unit/docformats/tests_pdf.py'
--- slidepresenterview/tests/unit/docformats/tests_pdf.py 2010-02-16 20:25:52 +0000
+++ slidepresenterview/tests/unit/docformats/tests_pdf.py 2010-07-11 17:41:04 +0000
@@ -23,7 +23,7 @@
Tests for PDF format.
"""
import os
-import unittest
+import unittest2
from nose.tools import assert_equals, assert_true
from mock import Mock, sentinel, patch_new, patch
@@ -45,7 +45,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextExistingValidFile5Page(unittest.TestCase):
+class TestContextExistingValidFile5Page(unittest2.TestCase):
"""
Context for the tests when the file linked to the PDFDocumentQt
is existing, valid and contains 5 pages.
@@ -95,7 +95,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextExistingFile0Page(unittest.TestCase):
+class TestContextExistingFile0Page(unittest2.TestCase):
"""
Context for the tests when the file linked to the PDFDocumentQt
is existing and contains 0 page.
@@ -118,7 +118,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextNonExistingFile(unittest.TestCase):
+class TestContextNonExistingFile(unittest2.TestCase):
"""
Context for the tests when the file linked to the PDFDocumentQt
is nonexisting.
@@ -131,7 +131,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextExistingNonPdfFile(unittest.TestCase):
+class TestContextExistingNonPdfFile(unittest2.TestCase):
"""
Context for the tests when the file linked to the PDFDocumentQt
is existing but is not a PDF file.
@@ -144,7 +144,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextExistingPdfFile1PageButNoPageRendering(unittest.TestCase):
+class TestContextExistingPdfFile1PageButNoPageRendering(unittest2.TestCase):
"""
Context for the tests when the file linked to the PDFDocumentQt
is existing and contains 1 page but the page cannot be rendered.
@@ -177,7 +177,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextPDFDocumentQt1Page(unittest.TestCase):
+class TestContextPDFDocumentQt1Page(unittest2.TestCase):
"""
Context for the tests when the PDFDocumentQt contains 1 page.
@@ -243,7 +243,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContextPDFDocumentQt3Pages(unittest.TestCase):
+class TestContextPDFDocumentQt3Pages(unittest2.TestCase):
"""
Context for the tests when the PDFDocumentQt contains 3 pages.
@@ -308,4 +308,5 @@
if __name__ == "__main__":
- unittest.main()
+ from slidepresenterview.tests import MultiplePrefixesTestLoader
+ unittest2.main(testLoader=MultiplePrefixesTestLoader())
=== modified file 'slidepresenterview/tests/unit/ui/tests_presentation.py'
--- slidepresenterview/tests/unit/ui/tests_presentation.py 2010-01-28 17:06:19 +0000
+++ slidepresenterview/tests/unit/ui/tests_presentation.py 2010-07-11 17:41:04 +0000
@@ -22,7 +22,7 @@
"""
Unit tests for L{slidepresenterview.ui.presentation}.
"""
-import unittest
+import unittest2
from mock import Mock, sentinel, patch_new, patch
@@ -64,7 +64,7 @@
#####
# pylint: disable-msg=W0212,R0904
-class TestContextEmptyPresentationWithoutColleague(unittest.TestCase):
+class TestContextEmptyPresentationWithoutColleague(unittest2.TestCase):
"""
Tests for an empty L{Presentation} without colleague.
"""
@@ -130,7 +130,7 @@
# pylint: disable-msg=W0212,R0904
-class TestAbstractContextEmptyPresentationWithTwoColleagues(unittest.TestCase):
+class TestAbstractContextEmptyPresentationWithTwoColleagues(unittest2.TestCase):
"""
Abstract context for tests of an empty L{Presentation} with two colleagues.
"""
@@ -602,7 +602,7 @@
# pylint: disable-msg=W0212,R0904
-class TestContext3pPresentationAtP2WithoutColleague(unittest.TestCase):
+class TestContext3pPresentationAtP2WithoutColleague(unittest2.TestCase):
"""
Tests for a L{Presentation} having 3 pages and currently being at page 2
without colleague.
@@ -657,4 +657,5 @@
if __name__ == "__main__":
- unittest.main()
+ from slidepresenterview.tests import MultiplePrefixesTestLoader
+ unittest2.main(testLoader=MultiplePrefixesTestLoader())
=== modified file 'slidepresenterview/tests/unit/ui/widgets/tests_slideview.py'
--- slidepresenterview/tests/unit/ui/widgets/tests_slideview.py 2010-02-01 04:12:47 +0000
+++ slidepresenterview/tests/unit/ui/widgets/tests_slideview.py 2010-07-11 17:41:04 +0000
@@ -22,7 +22,7 @@
"""
Unit tests for L{slidepresenterview.ui.widgets.slideview}.
"""
-import unittest
+import unittest2
from mock import Mock, patch_new
@@ -47,7 +47,7 @@
# pylint: disable-msg=W0212,R0904
class TestContextEmptySlideViewStretchableWithoutPresentation(
- unittest.TestCase):
+ unittest2.TestCase):
"""
Tests for an empty L{SlideViewStretchable} that does not know a
presentation.
@@ -104,7 +104,7 @@
# pylint: disable-msg=W0212,R0904
class TestAbstractContextEmptySlideViewStretchableWithPresentation(
- unittest.TestCase):
+ unittest2.TestCase):
"""
Abstract context for tests of a L{SlideViewStretchable} that knows a
presentation.
@@ -583,4 +583,5 @@
if __name__ == "__main__":
- unittest.main()
+ from slidepresenterview.tests import MultiplePrefixesTestLoader
+ unittest2.main(testLoader=MultiplePrefixesTestLoader())
Follow ups