__init__.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, TestCase
  30. else:
  31. import unittest2 as unittest
  32. from unittest2 import SkipTest, TestCase
  33. class BlackboxTestCase(TestCase):
  34. """Blackbox testing."""
  35. bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
  36. "..", "..", "bin"))
  37. def bin_path(self, name):
  38. """Determine the full path of a binary.
  39. :param name: Name of the script
  40. :return: Full path
  41. """
  42. return os.path.join(self.bin_directory, name)
  43. def run_command(self, name, args):
  44. """Run a Dulwich command.
  45. :param name: Name of the command, as it exists in bin/
  46. :param args: Arguments to the command
  47. """
  48. env = dict(os.environ)
  49. env["PYTHONPATH"] = os.pathsep.join(sys.path)
  50. # Since they don't have any extensions, Windows can't recognize
  51. # executablility of the Python files in /bin. Even then, we'd have to
  52. # expect the user to set up file associations for .py files.
  53. #
  54. # Save us from all that headache and call python with the bin script.
  55. argv = [sys.executable, self.bin_path(name)] + args
  56. return subprocess.Popen(argv,
  57. stdout=subprocess.PIPE,
  58. stdin=subprocess.PIPE, stderr=subprocess.PIPE,
  59. env=env)
  60. def self_test_suite():
  61. names = [
  62. 'blackbox',
  63. 'client',
  64. 'diff_tree',
  65. 'fastexport',
  66. 'file',
  67. 'index',
  68. 'lru_cache',
  69. 'objects',
  70. 'object_store',
  71. 'pack',
  72. 'patch',
  73. 'protocol',
  74. 'repository',
  75. 'server',
  76. 'walk',
  77. 'web',
  78. ]
  79. module_names = ['dulwich.tests.test_' + name for name in names]
  80. loader = unittest.TestLoader()
  81. return loader.loadTestsFromNames(module_names)
  82. def tutorial_test_suite():
  83. tutorial = [
  84. 'introduction',
  85. 'repo',
  86. 'object-store',
  87. 'conclusion',
  88. ]
  89. tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
  90. def setup(test):
  91. test.__old_cwd = os.getcwd()
  92. test.__dulwich_tempdir = tempfile.mkdtemp()
  93. os.chdir(test.__dulwich_tempdir)
  94. def teardown(test):
  95. shutil.rmtree(test.__dulwich_tempdir)
  96. os.chdir(test.__old_cwd)
  97. return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
  98. *tutorial_files)
  99. def nocompat_test_suite():
  100. result = unittest.TestSuite()
  101. result.addTests(self_test_suite())
  102. result.addTests(tutorial_test_suite())
  103. return result
  104. def test_suite():
  105. result = unittest.TestSuite()
  106. result.addTests(self_test_suite())
  107. result.addTests(tutorial_test_suite())
  108. from dulwich.tests.compat import test_suite as compat_test_suite
  109. result.addTests(compat_test_suite())
  110. return result