/functional_tests/test_issue_082.py

https://bitbucket.org/jpellerin/nose/ · Python · 74 lines · 50 code · 16 blank · 8 comment · 6 complexity · a13fcf31b235fd59ce6604de59eb30fa MD5 · raw file

  1. import os
  2. import re
  3. try:
  4. from cStringIO import StringIO
  5. except ImportError:
  6. from StringIO import StringIO
  7. import sys
  8. import unittest
  9. from nose.plugins import Plugin, PluginTester
  10. from nose.plugins.builtin import FailureDetail, Capture, Doctest
  11. support = os.path.join(os.path.dirname(__file__), 'support')
  12. class IncludeUnderscoreFilesPlugin(Plugin):
  13. # Note that this is purely for purposes of testing nose itself, and is
  14. # not intended to be a useful plugin. In particular, the rules it
  15. # applies for _*.py files differ from the nose defaults (e.g. the
  16. # --testmatch option is ignored).
  17. name = "underscorefiles"
  18. def wantFile(self, file):
  19. base = os.path.basename(file)
  20. dummy, ext = os.path.splitext(base)
  21. pysrc = ext == '.py'
  22. if pysrc and os.path.basename(file).startswith("_"):
  23. return True
  24. def wantDirectory(self, dirname):
  25. if os.path.basename(dirname).startswith("_"):
  26. return True
  27. class TestIncludeUnderscoreFiles(PluginTester, unittest.TestCase):
  28. activate = '--with-underscorefiles'
  29. plugins = [IncludeUnderscoreFilesPlugin(), Doctest()]
  30. args = ['-v', '--with-doctest']
  31. suitepath = os.path.join(support, 'issue082')
  32. ignoreFiles = (re.compile(r'^\.'),
  33. # we want _*.py, but don't want e.g. __init__.py, since that
  34. # appears to cause infinite recursion at the moment
  35. re.compile(r'^__'),
  36. re.compile(r'^setup\.py$')
  37. )
  38. def test_assert_info_in_output(self):
  39. print self.output
  40. # In future, all four test cases will be run. Backwards-compatibility
  41. # means that can't be done in nose 0.10.
  42. assert '_mypackage._eggs' not in str(self.output)
  43. assert '_mypackage.bacon' not in str(self.output)
  44. assert 'Doctest: mypublicpackage._foo ... FAIL' in str(self.output)
  45. assert 'Doctest: mypublicpackage.bar ... FAIL' in str(self.output)
  46. class TestExcludeUnderscoreFilesByDefault(PluginTester, unittest.TestCase):
  47. activate = '-v'
  48. plugins = [Doctest()]
  49. args = ['--with-doctest']
  50. suitepath = os.path.join(support, 'issue082')
  51. def test_assert_info_in_output(self):
  52. print self.output
  53. assert '_mypackage._eggs' not in str(self.output)
  54. assert '_mypackage.bacon' not in str(self.output)
  55. assert 'mypublicpackage._foo' not in str(self.output)
  56. assert 'Doctest: mypublicpackage.bar ... FAIL' in str(self.output)
  57. if __name__ == '__main__':
  58. unittest.main()