summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Maier <maiera@de.ibm.com>2016-10-21 11:11:22 +0200
committerAndreas Maier <maiera@de.ibm.com>2016-10-24 16:02:31 +0200
commitf3d5df2ce3addd9e9e1863f4f33665a16b415b71 (patch)
treec22a1d74ed859e6eaca9903fa8600ec51c3b44db
parent5149c807ec5f396c1114851ffbd0f88d65d4c84f (diff)
downloadgitpython-f3d5df2ce3addd9e9e1863f4f33665a16b415b71.tar.gz
Fixes to support Python 2.6 again.
Details: - Added Python 2.6 again to .travis.yml (it was removed in commit 4486bcb). - Replaced the use of dictionary comprehensions in `git/cmd.py` around line 800 with the code before that change (in commit 25a2ebf). Reason: dict comprehensions were introduced only in Python 2.7. - Changed the import source for `SkipTest` and `skipIf` from `unittest.case` to first trying `unittest` and upon ImportError from `unittest2`. This was done in `git/util.py` and in several testcases. Reason: `SkipTest` and `skipIf` were introduced to unittest only in Python 2.7, and `unittest2` is a backport of `unittest` additions to Python 2.6. - In git/test/lib/helper.py, fixed the definition of `assertRaisesRegex` to work on py26. - For Python 2.6, added the `unittest2` dependency to `requirements.txt` and changed `.travis.yml` to install `unittest2`. Because git/util.py uses SkipTest from unittest/unittest2, the dependency could not be added to `test-requirements.txt`. - Fixed an assertion in `git/test/test_index.py` to also allow a Python 2.6 specific exception message. - In `is_cygwin_git()` in `git/util.py`, replaced `check_output()` with `Popen()`. It was added in Python 2.7. - Enabled Python 2.6 for Windows: - Added Python 2.6 for MINGW in .appveyor.yml. - When defining `PROC_CREATIONFLAGS` in `git/cmd.py`, made use of certain win32 and subprocess flags that were introduced in Python 2.7, dependent on whether we run on Python 2.7 or higher. - In `AutoInterrupt.__del__()` in `git/cmd.py`, allowed for `os` not having `kill()`. `os.kill()` was added for Windows in Python 2.7 (For Linux, it existed in Python 2.6 already).
-rw-r--r--.appveyor.yml3
-rw-r--r--.travis.yml5
-rw-r--r--git/cmd.py14
-rw-r--r--git/objects/submodule/base.py5
-rw-r--r--git/test/lib/helper.py17
-rw-r--r--git/test/test_base.py6
-rw-r--r--git/test/test_fun.py5
-rw-r--r--git/test/test_index.py10
-rw-r--r--git/test/test_remote.py5
-rw-r--r--git/test/test_repo.py6
-rw-r--r--git/test/test_submodule.py5
-rw-r--r--git/test/test_tree.py5
-rw-r--r--git/test/test_util.py6
-rw-r--r--git/util.py15
-rw-r--r--requirements.txt1
15 files changed, 81 insertions, 27 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index 701fc4ac..69b7fe56 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -7,6 +7,9 @@ environment:
matrix:
## MINGW
#
+ - PYTHON: "C:\\Python26"
+ PYTHON_VERSION: "2.6"
+ GIT_PATH: "%GIT_DAEMON_PATH%"
- PYTHON: "C:\\Python27"
PYTHON_VERSION: "2.7"
GIT_PATH: "%GIT_DAEMON_PATH%"
diff --git a/.travis.yml b/.travis.yml
index f7dd247b..a3f8c705 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,14 @@
language: python
python:
+ - "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
# - "pypy" - won't work as smmap doesn't work (see gitdb/.travis.yml for details)
+#matrix:
+# allow_failures:
+# - python: "2.6"
git:
# a higher depth is needed for most of the tests - must be high enough to not actually be shallow
# as we clone our own repository in the process
@@ -15,6 +19,7 @@ install:
- git fetch --tags
- pip install -r test-requirements.txt
- pip install codecov sphinx
+ - if [ "$TRAVIS_PYTHON_VERSION" == '2.6' ]; then pip install unittest2; fi
# generate some reflog as git-python tests need it (in master)
- ./init-tests-after-clone.sh
diff --git a/git/cmd.py b/git/cmd.py
index 72ba82c3..78b5ff70 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -139,9 +139,9 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
CREATE_NO_WINDOW = 0x08000000
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
-# seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
+# see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP
- if is_win
+ if is_win and sys.version_info >= (2, 7)
else 0)
@@ -245,7 +245,7 @@ class Git(LazyMixin):
return
# can be that nothing really exists anymore ...
- if os is None or os.kill is None:
+ if os is None or getattr(os, 'kill', None) is None:
return
# try to kill it
@@ -831,8 +831,12 @@ class Git(LazyMixin):
:return: Same as ``execute``"""
# Handle optional arguments prior to calling transform_kwargs
# otherwise these'll end up in args, which is bad.
- _kwargs = {k: v for k, v in kwargs.items() if k in execute_kwargs}
- kwargs = {k: v for k, v in kwargs.items() if k not in execute_kwargs}
+ _kwargs = dict()
+ for kwarg in execute_kwargs:
+ try:
+ _kwargs[kwarg] = kwargs.pop(kwarg)
+ except KeyError:
+ pass
insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 18988b97..a35240f1 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -3,7 +3,10 @@ from io import BytesIO
import logging
import os
import stat
-from unittest.case import SkipTest
+try:
+ from unittest import SkipTest
+except ImportError:
+ from unittest2 import SkipTest
import uuid
import git
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 1515f2a1..743f720c 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -7,20 +7,24 @@ from __future__ import print_function
import contextlib
from functools import wraps
+import sys
import io
import logging
import os
import tempfile
import textwrap
import time
-from unittest import TestCase
-import unittest
-from git.compat import string_types, is_win, PY3
+from git.compat import string_types, is_win
from git.util import rmtree, cwd
import os.path as osp
+if sys.version_info[0:2] == (2, 6):
+ import unittest2 as unittest
+else:
+ import unittest
+TestCase = unittest.TestCase
ospd = osp.dirname
@@ -335,8 +339,11 @@ class TestBase(TestCase):
of the project history ( to assure tests don't fail for others ).
"""
- if not PY3:
- assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
+ # On py26, unittest2 has assertRaisesRegex
+ # On py3, unittest has assertRaisesRegex
+ # On py27, we use unittest, which names it differently:
+ if sys.version_info[0:2] == (2, 7):
+ assertRaisesRegex = TestCase.assertRaisesRegexp
def _small_repo_url(self):
""":return" a path to a small, clonable repository"""
diff --git a/git/test/test_base.py b/git/test/test_base.py
index cec40de8..69f161be 100644
--- a/git/test/test_base.py
+++ b/git/test/test_base.py
@@ -7,7 +7,10 @@
import os
import sys
import tempfile
-from unittest import skipIf
+try:
+ from unittest import SkipTest, skipIf
+except ImportError:
+ from unittest2 import SkipTest, skipIf
from git import (
Blob,
@@ -131,7 +134,6 @@ class TestBase(TestBase):
try:
file_path.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
- from unittest import SkipTest
raise SkipTest("Environment doesn't support unicode filenames")
with open(file_path, "wb") as fp:
diff --git a/git/test/test_fun.py b/git/test/test_fun.py
index 9d436653..b472fe19 100644
--- a/git/test/test_fun.py
+++ b/git/test/test_fun.py
@@ -1,6 +1,9 @@
from io import BytesIO
from stat import S_IFDIR, S_IFREG, S_IFLNK
-from unittest.case import skipIf
+try:
+ from unittest import skipIf
+except ImportError:
+ from unittest2 import skipIf
from git.compat import PY3
from git.index import IndexFile
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 1abe22f4..071ac623 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -13,7 +13,10 @@ from stat import (
)
import sys
import tempfile
-from unittest.case import skipIf
+try:
+ from unittest import skipIf
+except ImportError:
+ from unittest2 import skipIf
from git import (
IndexFile,
@@ -149,8 +152,9 @@ class TestIndex(TestBase):
except Exception as ex:
msg_py3 = "required argument is not an integer"
msg_py2 = "cannot convert argument to integer"
- ## msg_py26 ="unsupported operand type(s) for &: 'str' and 'long'"
- assert msg_py2 in str(ex) or msg_py3 in str(ex), str(ex)
+ msg_py26 = "unsupported operand type(s) for &: 'str' and 'long'"
+ assert msg_py2 in str(ex) or msg_py3 in str(ex) or \
+ msg_py26 in str(ex), str(ex)
## 2nd time should not fail due to stray lock file
try:
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index 8b50ea35..aae4fb9f 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -6,7 +6,10 @@
import random
import tempfile
-from unittest.case import skipIf
+try:
+ from unittest import skipIf
+except ImportError:
+ from unittest2 import skipIf
from git import (
RemoteProgress,
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 374a26ee..9ad80ee6 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -11,7 +11,10 @@ import os
import pickle
import sys
import tempfile
-from unittest.case import skipIf
+try:
+ from unittest import skipIf, SkipTest
+except ImportError:
+ from unittest2 import skipIf, SkipTest
from git import (
InvalidGitRepositoryError,
@@ -53,7 +56,6 @@ from git.test.lib import (
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cygpath
from git.test.lib import with_rw_directory
from git.util import join_path_native, rmtree, rmfile, bin_to_hex
-from unittest import SkipTest
import functools as fnt
import os.path as osp
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index 7b05f49a..59a40fa0 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -3,7 +3,10 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import os
import sys
-from unittest.case import skipIf
+try:
+ from unittest import skipIf
+except ImportError:
+ from unittest2 import skipIf
import git
from git.cmd import Git
diff --git a/git/test/test_tree.py b/git/test/test_tree.py
index f9259874..ab85bc9c 100644
--- a/git/test/test_tree.py
+++ b/git/test/test_tree.py
@@ -6,7 +6,10 @@
from io import BytesIO
import sys
-from unittest.case import skipIf
+try:
+ from unittest import skipIf
+except ImportError:
+ from unittest2 import skipIf
from git import (
Tree,
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 8f8d2272..525c8609 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -6,7 +6,11 @@
import tempfile
import time
-from unittest.case import skipIf
+try:
+ from unittest import skipIf
+except ImportError:
+ from unittest2 import skipIf
+
import ddt
diff --git a/git/util.py b/git/util.py
index 1e0d3eb4..6e3ddfab 100644
--- a/git/util.py
+++ b/git/util.py
@@ -11,11 +11,15 @@ import getpass
import logging
import os
import platform
+import subprocess
import re
import shutil
import stat
import time
-from unittest.case import SkipTest
+try:
+ from unittest import SkipTest
+except ImportError:
+ from unittest2 import SkipTest
from gitdb.util import (# NOQA @IgnorePep8
make_sha,
@@ -303,7 +307,7 @@ def is_cygwin_git(git_executable):
if not is_win:
return False
- from subprocess import check_output
+ #from subprocess import check_output
is_cygwin = _is_cygwin_cache.get(git_executable)
if is_cygwin is None:
@@ -316,8 +320,11 @@ def is_cygwin_git(git_executable):
## Just a name given, not a real path.
uname_cmd = osp.join(git_dir, 'uname')
- uname = check_output(uname_cmd, universal_newlines=True)
- is_cygwin = 'CYGWIN' in uname
+ process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE,
+ universal_newlines=True)
+ uname_out, _ = process.communicate()
+ #retcode = process.poll()
+ is_cygwin = 'CYGWIN' in uname_out
except Exception as ex:
log.debug('Failed checking if running in CYGWIN due to: %r', ex)
_is_cygwin_cache[git_executable] = is_cygwin
diff --git a/requirements.txt b/requirements.txt
index 39644606..a8e7a7a8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
gitdb>=0.6.4
ddt>=1.1.1
+unittest2; python_version < '2.7'