Browse Source

Fix the tutorial tests on python3. Fixes: #573

Jelmer Vernooij 7 years ago
parent
commit
2d1e979d77
6 changed files with 13 additions and 10 deletions
  1. 1 1
      Makefile
  2. 2 0
      NEWS
  3. 4 2
      docs/tutorial/object-store.txt
  4. 3 3
      docs/tutorial/remote.txt
  5. 1 1
      docs/tutorial/repo.txt
  6. 2 3
      dulwich/tests/__init__.py

+ 1 - 1
Makefile

@@ -5,7 +5,7 @@ FLAKE8 ?= flake8
 SETUP = $(PYTHON) setup.py
 PYDOCTOR ?= pydoctor
 TESTRUNNER ?= unittest
-RUNTEST = PYTHONHASHSEED=random PYTHONPATH=.:$(PYTHONPATH) $(PYTHON) -m $(TESTRUNNER) $(TEST_OPTIONS)
+RUNTEST = PYTHONHASHSEED=random PYTHONPATH=$(shell pwd):$(PYTHONPATH) $(PYTHON) -m $(TESTRUNNER) $(TEST_OPTIONS)
 COVERAGE = python3-coverage
 
 DESTDIR=/

+ 2 - 0
NEWS

@@ -12,6 +12,8 @@
 
   * Fix handling of encoding for tags. (Jelmer Vernooij, #608)
 
+  * Fix tutorial tests on Python 3. (Jelmer Vernooij, #573)
+
 0.19.2	2018-04-07
 
  BUG FIXES

+ 4 - 2
docs/tutorial/object-store.txt

@@ -169,8 +169,10 @@ The diff between the previous head and the new one can be printed using
 write_tree_diff::
 
   >>> from dulwich.patch import write_tree_diff
-  >>> import sys
-  >>> write_tree_diff(sys.stdout, repo.object_store, commit.tree, tree.id)
+  >>> from io import BytesIO
+  >>> out = BytesIO()
+  >>> write_tree_diff(out, repo.object_store, commit.tree, tree.id)
+  >>> import sys; _ = sys.stdout.write(out.getvalue().decode('ascii'))
   diff --git a/spam b/spam
   index c55063a..16ee268 100644
   --- a/spam

+ 3 - 3
docs/tutorial/remote.txt

@@ -5,7 +5,7 @@ Most of the tests in this file require a Dulwich server, so let's start one:
     >>> from dulwich.repo import Repo
     >>> from dulwich.server import DictBackend, TCPGitServer
     >>> import threading
-    >>> repo = Repo.init(b"remote", mkdir=True)
+    >>> repo = Repo.init("remote", mkdir=True)
     >>> cid = repo.do_commit(b"message", committer=b"Jelmer <jelmer@samba.org>")
     >>> backend = DictBackend({b'/': repo})
     >>> dul_server = TCPGitServer(backend, b'localhost', 0)
@@ -32,7 +32,7 @@ Dulwich provides support for accessing remote repositories in
 one manually::
 
    >>> from dulwich.client import TCPGitClient
-   >>> client = TCPGitClient(server_address.encode('ascii'), server_port)
+   >>> client = TCPGitClient(server_address, server_port)
 
 Retrieving raw pack files
 -------------------------
@@ -76,7 +76,7 @@ in which case Dulwich takes care of providing the right graph walker, and
 importing the received pack file into the local repository::
 
    >>> from dulwich.repo import Repo
-   >>> local = Repo.init(b"local", mkdir=True)
+   >>> local = Repo.init("local", mkdir=True)
    >>> remote_refs = client.fetch(b"/", local)
 
 Let's shut down the server now that all tests have been run::

+ 1 - 1
docs/tutorial/repo.txt

@@ -53,7 +53,7 @@ so only non-bare repositories will have an index, too. To open the index, simply
 call::
 
     >>> index = repo.open_index()
-    >>> print(index.path.decode(sys.getfilesystemencoding()))
+    >>> print(index.path)
     myrepo/.git/index
 
 Since the repository was just created, the index will be empty::

+ 2 - 3
dulwich/tests/__init__.py

@@ -159,9 +159,8 @@ def tutorial_test_suite():
 def nocompat_test_suite():
     result = unittest.TestSuite()
     result.addTests(self_test_suite())
+    result.addTests(tutorial_test_suite())
     from dulwich.contrib import test_suite as contrib_test_suite
-    if sys.version_info[0] == 2:
-        result.addTests(tutorial_test_suite())
     result.addTests(contrib_test_suite())
     return result
 
@@ -176,7 +175,7 @@ def compat_test_suite():
 def test_suite():
     result = unittest.TestSuite()
     result.addTests(self_test_suite())
-    if sys.version_info[0] == 2 and sys.platform != 'win32':
+    if sys.platform != 'win32':
         result.addTests(tutorial_test_suite())
     from dulwich.tests.compat import test_suite as compat_test_suite
     result.addTests(compat_test_suite())