/unit_tests/test_config.py

https://bitbucket.org/jpellerin/nose/ · Python · 141 lines · 107 code · 21 blank · 13 comment · 3 complexity · fa917af21eac9bf5fb3685f00e41f931 MD5 · raw file

  1. import re
  2. import os
  3. import tempfile
  4. import unittest
  5. import warnings
  6. import pickle
  7. import sys
  8. import nose.config
  9. from nose.plugins.manager import DefaultPluginManager
  10. from nose.plugins.skip import SkipTest
  11. from nose.plugins.prof import Profile
  12. class TestNoseConfig(unittest.TestCase):
  13. def test_defaults(self):
  14. c = nose.config.Config()
  15. assert c.addPaths == True
  16. # FIXME etc
  17. def test_reset(self):
  18. c = nose.config.Config()
  19. c.include = 'include'
  20. assert c.include == 'include'
  21. c.reset()
  22. assert c.include is None
  23. def test_update(self):
  24. c = nose.config.Config()
  25. c.update({'exclude':'x'})
  26. assert c.exclude == 'x'
  27. def test_ignore_files_default(self):
  28. """
  29. The default configuration should have several ignore file settings.
  30. """
  31. c = nose.config.Config()
  32. c.configure(['program'])
  33. self.assertEqual(len(c.ignoreFiles), 3)
  34. def test_ignore_files_single(self):
  35. """A single ignore-files flag should override the default settings."""
  36. c = nose.config.Config()
  37. c.configure(['program', '--ignore-files=a'])
  38. self.assertEqual(len(c.ignoreFiles), 1)
  39. aMatcher = c.ignoreFiles[0]
  40. assert aMatcher.match('a')
  41. assert not aMatcher.match('b')
  42. def test_ignore_files_multiple(self):
  43. """
  44. Multiple ignore-files flags should be appended together, overriding
  45. the default settings.
  46. """
  47. c = nose.config.Config()
  48. c.configure(['program', '--ignore-files=a', '-Ib'])
  49. self.assertEqual(len(c.ignoreFiles), 2)
  50. aMatcher, bMatcher = c.ignoreFiles
  51. assert aMatcher.match('a')
  52. assert not aMatcher.match('b')
  53. assert bMatcher.match('b')
  54. assert not bMatcher.match('a')
  55. def test_multiple_include(self):
  56. c = nose.config.Config()
  57. c.configure(['program', '--include=a', '--include=b'])
  58. self.assertEqual(len(c.include), 2)
  59. a, b = c.include
  60. assert a.match('a')
  61. assert not a.match('b')
  62. assert b.match('b')
  63. assert not b.match('a')
  64. def test_single_include(self):
  65. c = nose.config.Config()
  66. c.configure(['program', '--include=b'])
  67. self.assertEqual(len(c.include), 1)
  68. b = c.include[0]
  69. assert b.match('b')
  70. assert not b.match('a')
  71. def test_plugins(self):
  72. c = nose.config.Config()
  73. assert c.plugins
  74. c.plugins.begin()
  75. def test_testnames(self):
  76. c = nose.config.Config()
  77. c.configure(['program', 'foo', 'bar', 'baz.buz.biz'])
  78. self.assertEqual(c.testNames, ['foo', 'bar', 'baz.buz.biz'])
  79. c = nose.config.Config(testNames=['foo'])
  80. c.configure([])
  81. self.assertEqual(c.testNames, ['foo'])
  82. def test_where(self):
  83. # we don't need to see our own warnings
  84. warnings.filterwarnings(action='ignore',
  85. category=DeprecationWarning,
  86. module='nose.config')
  87. here = os.path.dirname(__file__)
  88. support = os.path.join(here, 'support')
  89. foo = os.path.abspath(os.path.join(support, 'foo'))
  90. c = nose.config.Config()
  91. c.configure(['program', '-w', foo, '-w', 'bar'])
  92. self.assertEqual(c.workingDir, foo)
  93. self.assertEqual(c.testNames, ['bar'])
  94. def test_progname_looks_like_option(self):
  95. # issue #184
  96. c = nose.config.Config()
  97. # the -v here is the program name, not an option
  98. # this matters eg. with python -c "import nose; nose.main()"
  99. c.configure(['-v', 'mytests'])
  100. self.assertEqual(c.verbosity, 1)
  101. def test_pickle_empty(self):
  102. c = nose.config.Config()
  103. cp = pickle.dumps(c)
  104. cc = pickle.loads(cp)
  105. def test_pickle_configured(self):
  106. if 'java' in sys.version.lower():
  107. raise SkipTest("jython has no profiler plugin")
  108. c = nose.config.Config(plugins=DefaultPluginManager())
  109. config_args = ['--with-doctest', '--with-coverage',
  110. '--with-id', '--attr=A', '--collect', '--all',
  111. '--with-isolation', '-d', '--with-xunit', '--processes=2',
  112. '--pdb']
  113. if Profile.available():
  114. config_args.append('--with-profile')
  115. c.configure(config_args)
  116. cp = pickle.dumps(c)
  117. cc = pickle.loads(cp)
  118. assert cc.plugins._plugins
  119. if __name__ == '__main__':
  120. unittest.main()