__init__.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # __init__.py -- The tests for dulwich
  2. # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) any later version of
  8. # the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. """Tests for Dulwich."""
  20. import doctest
  21. import os
  22. import shutil
  23. import subprocess
  24. import sys
  25. import tempfile
  26. if sys.version_info >= (2, 7):
  27. # If Python itself provides an exception, use that
  28. import unittest
  29. from unittest import SkipTest as TestSkipped
  30. from unittest import TestCase
  31. else:
  32. try:
  33. import unittest2 as unittest
  34. from unittest2 import SkipTest as TestSkipped
  35. from unittest2 import TestCase
  36. except ImportError:
  37. import unittest
  38. from testtools.testcase import TestSkipped
  39. from testtools.testcase import TestCase
  40. TestCase.skipException = TestSkipped
  41. class BlackboxTestCase(TestCase):
  42. """Blackbox testing."""
  43. bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
  44. "..", "..", "bin"))
  45. def bin_path(self, name):
  46. """Determine the full path of a binary.
  47. :param name: Name of the script
  48. :return: Full path
  49. """
  50. return os.path.join(self.bin_directory, name)
  51. def run_command(self, name, args):
  52. """Run a Dulwich command.
  53. :param name: Name of the command, as it exists in bin/
  54. :param args: Arguments to the command
  55. """
  56. env = dict(os.environ)
  57. env["PYTHONPATH"] = os.pathsep.join(sys.path)
  58. # Since they don't have any extensions, Windows can't recognize
  59. # executablility of the Python files in /bin. Even then, we'd have to
  60. # expect the user to set up file associations for .py files.
  61. #
  62. # Save us from all that headache and call python with the bin script.
  63. argv = [sys.executable, self.bin_path(name)] + args
  64. return subprocess.Popen(argv,
  65. stdout=subprocess.PIPE,
  66. stdin=subprocess.PIPE, stderr=subprocess.PIPE,
  67. env=env)
  68. def self_test_suite():
  69. names = [
  70. 'blackbox',
  71. 'client',
  72. 'fastexport',
  73. 'file',
  74. 'index',
  75. 'lru_cache',
  76. 'objects',
  77. 'object_store',
  78. 'pack',
  79. 'patch',
  80. 'protocol',
  81. 'repository',
  82. 'server',
  83. 'web',
  84. ]
  85. module_names = ['dulwich.tests.test_' + name for name in names]
  86. loader = unittest.TestLoader()
  87. return loader.loadTestsFromNames(module_names)
  88. def tutorial_test_suite():
  89. tutorial = [
  90. 'introduction',
  91. 'repo',
  92. 'object-store',
  93. 'conclusion',
  94. ]
  95. tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
  96. def setup(test):
  97. test.__dulwich_tempdir = tempfile.mkdtemp()
  98. os.chdir(test.__dulwich_tempdir)
  99. def teardown(test):
  100. shutil.rmtree(test.__dulwich_tempdir)
  101. return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
  102. *tutorial_files)
  103. def nocompat_test_suite():
  104. result = unittest.TestSuite()
  105. result.addTests(self_test_suite())
  106. result.addTests(tutorial_test_suite())
  107. return result
  108. def test_suite():
  109. result = unittest.TestSuite()
  110. result.addTests(self_test_suite())
  111. result.addTests(tutorial_test_suite())
  112. from dulwich.tests.compat import test_suite as compat_test_suite
  113. result.addTests(compat_test_suite())
  114. return result