summaryrefslogtreecommitdiff
path: root/functional_tests
diff options
context:
space:
mode:
Diffstat (limited to 'functional_tests')
-rw-r--r--functional_tests/doc_tests/test_multiprocess/multiprocess.rst1
-rw-r--r--functional_tests/doc_tests/test_xunit_plugin/test_skips.rst2
-rw-r--r--functional_tests/support/coverage2/blah.py6
-rw-r--r--functional_tests/support/coverage2/moo.py2
-rw-r--r--functional_tests/support/coverage2/tests/test_covered.py8
-rw-r--r--functional_tests/support/dir3/.hidden0
-rw-r--r--functional_tests/support/issue134/test.py3
-rw-r--r--functional_tests/support/issue513/test.py3
-rw-r--r--functional_tests/test_coverage_plugin.py64
-rw-r--r--functional_tests/test_failure.py29
-rw-r--r--functional_tests/test_importer.py70
-rw-r--r--functional_tests/test_multiprocessing/test_concurrent_shared.py4
-rw-r--r--functional_tests/test_withid_failures.rst16
-rw-r--r--functional_tests/test_xunit.py17
14 files changed, 203 insertions, 22 deletions
diff --git a/functional_tests/doc_tests/test_multiprocess/multiprocess.rst b/functional_tests/doc_tests/test_multiprocess/multiprocess.rst
index d463ba0..ca966af 100644
--- a/functional_tests/doc_tests/test_multiprocess/multiprocess.rst
+++ b/functional_tests/doc_tests/test_multiprocess/multiprocess.rst
@@ -223,6 +223,7 @@ Then we can run again and see the failures.
... plugins=[MultiProcess()]) #doctest: +ELLIPSIS
setup called
teardown called
+ ...
test_can_split....
...
FAILED (failures=...)
diff --git a/functional_tests/doc_tests/test_xunit_plugin/test_skips.rst b/functional_tests/doc_tests/test_xunit_plugin/test_skips.rst
index c0c3fbc..dd0590e 100644
--- a/functional_tests/doc_tests/test_xunit_plugin/test_skips.rst
+++ b/functional_tests/doc_tests/test_xunit_plugin/test_skips.rst
@@ -37,4 +37,4 @@ Ran 4 tests in ...s
FAILED (SKIP=1, errors=1, failures=1)
>>> open(outfile, 'r').read() # doctest: +ELLIPSIS
-'<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="4" errors="1" failures="1" skip="1"><testcase classname="test_skip" name="test_ok" time="..." /><testcase classname="test_skip" name="test_err" time="..."><error type="...Exception" message="oh no">...</error></testcase><testcase classname="test_skip" name="test_fail" time="..."><failure type="...AssertionError" message="bye">...</failure></testcase><testcase classname="test_skip" name="test_skip" time="..."><skipped type="...SkipTest" message="not me">...</skipped></testcase></testsuite>'
+'<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="4" errors="1" failures="1" skip="1"><testcase classname="test_skip" name="test_ok" time="..."></testcase><testcase classname="test_skip" name="test_err" time="..."><error type="...Exception" message="oh no">...</error></testcase><testcase classname="test_skip" name="test_fail" time="..."><failure type="...AssertionError" message="bye">...</failure></testcase><testcase classname="test_skip" name="test_skip" time="..."><skipped type="...SkipTest" message="not me">...</skipped></testcase></testsuite>'
diff --git a/functional_tests/support/coverage2/blah.py b/functional_tests/support/coverage2/blah.py
new file mode 100644
index 0000000..ef6657c
--- /dev/null
+++ b/functional_tests/support/coverage2/blah.py
@@ -0,0 +1,6 @@
+def dostuff():
+ print 'hi'
+
+
+def notcov():
+ print 'not covered'
diff --git a/functional_tests/support/coverage2/moo.py b/functional_tests/support/coverage2/moo.py
new file mode 100644
index 0000000..7ad09bf
--- /dev/null
+++ b/functional_tests/support/coverage2/moo.py
@@ -0,0 +1,2 @@
+def moo():
+ print 'covered'
diff --git a/functional_tests/support/coverage2/tests/test_covered.py b/functional_tests/support/coverage2/tests/test_covered.py
new file mode 100644
index 0000000..034f984
--- /dev/null
+++ b/functional_tests/support/coverage2/tests/test_covered.py
@@ -0,0 +1,8 @@
+import blah
+import moo
+
+def test_blah():
+ blah.dostuff()
+
+def test_moo():
+ moo.dostuff()
diff --git a/functional_tests/support/dir3/.hidden b/functional_tests/support/dir3/.hidden
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/functional_tests/support/dir3/.hidden
diff --git a/functional_tests/support/issue134/test.py b/functional_tests/support/issue134/test.py
new file mode 100644
index 0000000..78e1e22
--- /dev/null
+++ b/functional_tests/support/issue134/test.py
@@ -0,0 +1,3 @@
+def test():
+ print "something"
+ raise IOError(42, "test")
diff --git a/functional_tests/support/issue513/test.py b/functional_tests/support/issue513/test.py
new file mode 100644
index 0000000..a0c6238
--- /dev/null
+++ b/functional_tests/support/issue513/test.py
@@ -0,0 +1,3 @@
+def test():
+ raise '\xf1'.encode('ASCII')
+ yield
diff --git a/functional_tests/test_coverage_plugin.py b/functional_tests/test_coverage_plugin.py
index d1b2632..3242695 100644
--- a/functional_tests/test_coverage_plugin.py
+++ b/functional_tests/test_coverage_plugin.py
@@ -8,14 +8,23 @@ from nose.plugins.cover import Coverage
support = os.path.join(os.path.dirname(__file__), 'support')
+try:
+ import coverage
+ hasCoverage = True
+except ImportError:
+ hasCoverage = False
+
class TestCoveragePlugin(PluginTester, unittest.TestCase):
activate = "--with-coverage"
- args = ['-v', '--cover-package=blah', '--cover-html']
+ args = ['-v', '--cover-package=blah', '--cover-html', '--cover-min-percentage', '25']
plugins = [Coverage()]
suitepath = os.path.join(support, 'coverage')
def setUp(self):
+ if not hasCoverage:
+ raise unittest.SkipTest('coverage not available; skipping')
+
self.cover_file = os.path.join(os.getcwd(), '.coverage')
self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
if os.path.exists(self.cover_file):
@@ -25,13 +34,60 @@ class TestCoveragePlugin(PluginTester, unittest.TestCase):
super(TestCoveragePlugin, self).setUp()
def runTest(self):
- self.assertTrue("blah 4 1 75% 6" in self.output)
- self.assertTrue("Ran 1 test in""" in self.output)
+ self.assertTrue("blah 4 3 25% 1" in self.output)
+ self.assertTrue("Ran 1 test in" in self.output)
# Assert coverage html report exists
self.assertTrue(os.path.exists(os.path.join(self.cover_html_dir,
- 'index.html')))
+ 'index.html')))
# Assert coverage data is saved
self.assertTrue(os.path.exists(self.cover_file))
+
+class TestCoverageMinPercentagePlugin(PluginTester, unittest.TestCase):
+ activate = "--with-coverage"
+ args = ['-v', '--cover-package=blah', '--cover-min-percentage', '100']
+ plugins = [Coverage()]
+ suitepath = os.path.join(support, 'coverage')
+
+ def setUp(self):
+ if not hasCoverage:
+ raise unittest.SkipTest('coverage not available; skipping')
+
+ self.cover_file = os.path.join(os.getcwd(), '.coverage')
+ self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
+ if os.path.exists(self.cover_file):
+ os.unlink(self.cover_file)
+ if os.path.exists(self.cover_html_dir):
+ shutil.rmtree(self.cover_html_dir)
+ self.assertRaises(SystemExit,
+ super(TestCoverageMinPercentagePlugin, self).setUp)
+
+ def runTest(self):
+ pass
+
+
+class TestCoverageMinPercentageTOTALPlugin(PluginTester, unittest.TestCase):
+ activate = "--with-coverage"
+ args = ['-v', '--cover-package=blah', '--cover-package=moo',
+ '--cover-min-percentage', '100']
+ plugins = [Coverage()]
+ suitepath = os.path.join(support, 'coverage2')
+
+ def setUp(self):
+ if not hasCoverage:
+ raise unittest.SkipTest('coverage not available; skipping')
+
+ self.cover_file = os.path.join(os.getcwd(), '.coverage')
+ self.cover_html_dir = os.path.join(os.getcwd(), 'cover')
+ if os.path.exists(self.cover_file):
+ os.unlink(self.cover_file)
+ if os.path.exists(self.cover_html_dir):
+ shutil.rmtree(self.cover_html_dir)
+ self.assertRaises(SystemExit,
+ super(TestCoverageMinPercentageTOTALPlugin, self).setUp)
+
+ def runTest(self):
+ pass
+
if __name__ == '__main__':
unittest.main()
diff --git a/functional_tests/test_failure.py b/functional_tests/test_failure.py
new file mode 100644
index 0000000..e9d17e9
--- /dev/null
+++ b/functional_tests/test_failure.py
@@ -0,0 +1,29 @@
+import os
+import unittest
+
+from nose.plugins import PluginTester
+
+support = os.path.join(os.path.dirname(__file__), 'support', 'issue513')
+
+class TestPrintedTraceback(PluginTester, unittest.TestCase):
+ args = ['--where='+support]
+ activate = "-v"
+
+ def makeSuite(self):
+ # make PluginTester happy, because we don't specify suitepath, we
+ # have to implement this function
+ return None
+
+ def test_correct_exception_raised(self):
+ print
+ print '!' * 70
+ print str(self.output)
+ print '!' * 70
+ print
+
+ # Look for the line in the traceback causing the failure
+ assert "raise '\\xf1'.encode('ASCII')" in str(self.output)
+ assert 'FAILED (errors=1)' in str(self.output)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/functional_tests/test_importer.py b/functional_tests/test_importer.py
index c24fdcf..20fb15d 100644
--- a/functional_tests/test_importer.py
+++ b/functional_tests/test_importer.py
@@ -2,6 +2,7 @@ import os
import sys
import unittest
from nose.importer import Importer
+from nose.plugins.skip import SkipTest
class TestImporter(unittest.TestCase):
@@ -16,7 +17,15 @@ class TestImporter(unittest.TestCase):
sys.modules.pop('pak', None)
sys.modules.pop('pak.mod', None)
sys.modules.pop('pak.sub', None)
-
+ try:
+ os.symlink(
+ os.path.abspath(os.path.join(self.dir, 'dir1', 'pak')),
+ os.path.join(self.dir, 'dir3', 'pak'))
+ except (AttributeError, NotImplementedError):
+ self.has_symlinks = False
+ else:
+ self.has_symlinks = True
+
def tearDown(self):
to_del = [ m for m in sys.modules.keys() if
m not in self._mods ]
@@ -25,14 +34,16 @@ class TestImporter(unittest.TestCase):
del sys.modules[mod]
sys.modules.update(self._mods)
sys.path = self._path[:]
+ if self.has_symlinks:
+ os.unlink(os.path.join(self.dir, 'dir3', 'pak'))
def test_import_from_dir(self):
imp = self.imp
d1 = os.path.join(self.dir, 'dir1')
d2 = os.path.join(self.dir, 'dir2')
-
- # simple name
+
+ # simple name
m1 = imp.importFromDir(d1, 'mod')
m2 = imp.importFromDir(d2, 'mod')
self.assertNotEqual(m1, m2)
@@ -44,14 +55,34 @@ class TestImporter(unittest.TestCase):
self.assertNotEqual(p1, p2)
self.assertNotEqual(p1.__file__, p2.__file__)
+ def test_import_from_dirlink(self):
+ if not self.has_symlinks:
+ raise SkipTest("symlinks not available")
+ imp = self.imp
+
+ d1 = os.path.join(self.dir, 'dir3')
+ d2 = os.path.join(self.dir, 'dir2')
+
+ # simple name
+ m1 = imp.importFromDir(d1, 'pak')
+ m2 = imp.importFromDir(d2, 'pak')
+ self.assertNotEqual(m1, m2)
+ self.assertNotEqual(m1.__file__, m2.__file__)
+
+ # dotted name
+ p1 = imp.importFromDir(d1, 'pak.mod')
+ p2 = imp.importFromDir(d2, 'pak.mod')
+ self.assertNotEqual(p1, p2)
+ self.assertNotEqual(p1.__file__, p2.__file__)
+
def test_import_from_path(self):
imp = self.imp
jn = os.path.join
d1 = jn(self.dir, 'dir1')
d2 = jn(self.dir, 'dir2')
-
- # simple name
+
+ # simple name
m1 = imp.importFromPath(jn(d1, 'mod.py'), 'mod')
m2 = imp.importFromPath(jn(d2, 'mod.py'), 'mod')
self.assertNotEqual(m1, m2)
@@ -88,12 +119,12 @@ class TestImporter(unittest.TestCase):
assert 'test_pak' in sys.modules, 'test_pak was not imported?'
test_pak = sys.modules['test_pak']
assert hasattr(test_pak, 'test_sub'), "test_pak.test_sub was not set"
-
+
def test_cached_no_reload(self):
imp = self.imp
d1 = os.path.join(self.dir, 'dir1')
m1 = imp.importFromDir(d1, 'mod')
- m2 = imp.importFromDir(d1, 'mod')
+ m2 = imp.importFromDir(d1, 'mod')
assert m1 is m2, "%s is not %s" % (m1, m2)
def test_cached_no_reload_dotted(self):
@@ -133,13 +164,34 @@ class TestImporter(unittest.TestCase):
assert mod_nose_imported2 != mod_sys_imported, \
"nose failed to reimport same name, different dir"
+ def test_sys_modules_symlinked_package_no_reload(self):
+ if not self.has_symlinks:
+ raise SkipTest("symlinks not available")
+ imp = self.imp
+
+ d1 = os.path.join(self.dir, 'dir1')
+ d2 = os.path.join(self.dir, 'dir3')
+ sys.path.insert(0, d1)
+ # Symlinked package
+ mod_sys_imported = __import__('pak')
+ mod_nose_imported = imp.importFromDir(d2, 'pak')
+ assert mod_nose_imported is mod_sys_imported, \
+ "nose reimported a module in sys.modules from the same file"
+
+ # Module inside symlinked package
+ mod_sys_imported = __import__('pak.mod', fromlist=['mod'])
+ mod_nose_imported = imp.importFromDir(d2, 'pak.mod')
+ assert mod_nose_imported is mod_sys_imported, \
+ ("nose reimported a module in sys.modules from the same file",
+ mod_sys_imported.__file__, mod_nose_imported.__file__)
+
def test_import_pkg_from_path_fpw(self):
imp = self.imp
imp.config.firstPackageWins = True
jn = os.path.join
d1 = jn(self.dir, 'dir1')
d2 = jn(self.dir, 'dir2')
-
+
# dotted name
p1 = imp.importFromPath(jn(d1, 'pak', 'mod.py'), 'pak.mod')
p2 = imp.importFromPath(jn(d2, 'pak', 'mod.py'), 'pak.mod')
@@ -161,7 +213,7 @@ class TestImporter(unittest.TestCase):
assert dp1.__path__
assert dp2.__path__
self.assertEqual(dp1.__path__, dp2.__path__)
-
+
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.DEBUG)
diff --git a/functional_tests/test_multiprocessing/test_concurrent_shared.py b/functional_tests/test_multiprocessing/test_concurrent_shared.py
index 2552c2b..629493e 100644
--- a/functional_tests/test_multiprocessing/test_concurrent_shared.py
+++ b/functional_tests/test_multiprocessing/test_concurrent_shared.py
@@ -11,3 +11,7 @@ class TestConcurrentShared(MPTestBase):
assert 'Ran 2 tests in 1.' in self.output, "make sure two tests use 1.x seconds (no more than 2 seconsd)"
assert str(self.output).strip().endswith('OK')
+
+class TestConcurrentSharedWithAutomaticProcessesCount(TestConcurrentShared):
+ """Make sure negative numbers are handled gracefully."""
+ processes = -1
diff --git a/functional_tests/test_withid_failures.rst b/functional_tests/test_withid_failures.rst
index 5a371b7..cf09d4f 100644
--- a/functional_tests/test_withid_failures.rst
+++ b/functional_tests/test_withid_failures.rst
@@ -6,17 +6,17 @@
>>> idfile = tempfile.mktemp()
>>> support = os.path.join(os.path.dirname(__file__), 'support', 'id_fails')
>>> argv = [__file__, '-v', '--with-id', '--id-file', idfile, support]
- >>> run(argv=argv, plugins=[TestId()])
- #1 Failure: ImportError (No module named apackagethatdoesntexist) ... ERROR
+ >>> run(argv=argv, plugins=[TestId()]) # doctest: +ELLIPSIS
+ #1 Failure: ImportError (No module ...apackagethatdoesntexist...) ... ERROR
#2 test_b.test ... ok
#3 test_b.test_fail ... FAIL
<BLANKLINE>
======================================================================
- ERROR: Failure: ImportError (No module named apackagethatdoesntexist)
+ ERROR: Failure: ImportError (No module ...apackagethatdoesntexist...)
----------------------------------------------------------------------
Traceback (most recent call last):
...
- ImportError: No module named apackagethatdoesntexist
+ ImportError: No module ...apackagethatdoesntexist...
<BLANKLINE>
======================================================================
FAIL: test_b.test_fail
@@ -34,15 +34,15 @@ Addressing failures works (sometimes).
>>> argv.append('1')
>>> _junk = sys.modules.pop('test_a', None) # 2.3 requires
- >>> run(argv=argv, plugins=[TestId()])
- #1 Failure: ImportError (No module named apackagethatdoesntexist) ... ERROR
+ >>> run(argv=argv, plugins=[TestId()]) #doctest: +ELLIPSIS
+ #1 Failure: ImportError (No module ...apackagethatdoesntexist...) ... ERROR
<BLANKLINE>
======================================================================
- ERROR: Failure: ImportError (No module named apackagethatdoesntexist)
+ ERROR: Failure: ImportError (No module ...apackagethatdoesntexist...)
----------------------------------------------------------------------
Traceback (most recent call last):
...
- ImportError: No module named apackagethatdoesntexist
+ ImportError: No module ...apackagethatdoesntexist...
<BLANKLINE>
----------------------------------------------------------------------
Ran 1 test in ...s
diff --git a/functional_tests/test_xunit.py b/functional_tests/test_xunit.py
index 5d21a17..d137513 100644
--- a/functional_tests/test_xunit.py
+++ b/functional_tests/test_xunit.py
@@ -3,6 +3,7 @@ import codecs
import os
import sys
import unittest
+from nose.plugins.capture import Capture
from nose.plugins.xunit import Xunit
from nose.plugins.skip import Skip
from nose.plugins import PluginTester
@@ -45,6 +46,22 @@ class TestXUnitPlugin(PluginTester, unittest.TestCase):
assert '</testsuite>' in result
+class TestIssue134(PluginTester, unittest.TestCase):
+ activate = '--with-xunit'
+ args = ['-v','--xunit-file=%s' % xml_results_filename]
+ plugins = [Capture(), Xunit()]
+ suitepath = os.path.join(support, 'issue134')
+
+ def runTest(self):
+ print str(self.output)
+ f = open(xml_results_filename,'r')
+ result = f.read()
+ f.close()
+ print result
+ assert 'raise IOError(42, "test")' in result
+ assert 'tests="1" errors="1" failures="0" skip="0"' in result
+
+
class TestIssue279(PluginTester, unittest.TestCase):
activate = '--with-xunit'
args = ['-v','--xunit-file=%s' % xml_results_filename]