Skip to content

Commit 7e35290

Browse files
committed
Fixes to support Python 2.6 again.
Details: - 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 control file to install `unittest2`. - Fixed an assertion in `git/test/test_index.py` to also allow a Python 2.6 specific exception message.
1 parent afcd64e commit 7e35290

14 files changed

+63
-25
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ install:
1818
- git submodule update --init --recursive
1919
- git fetch --tags
2020
- pip install codecov flake8 ddt sphinx
21+
- if [ "$TRAVIS_PYTHON_VERSION" == '2.6' ]; then pip install unittest2; fi
2122

2223
# generate some reflog as git-python tests need it (in master)
2324
- ./init-tests-after-clone.sh

Diff for: git/cmd.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,12 @@ def _call_process(self, method, *args, **kwargs):
812812
:return: Same as ``execute``"""
813813
# Handle optional arguments prior to calling transform_kwargs
814814
# otherwise these'll end up in args, which is bad.
815-
_kwargs = {k: v for k, v in kwargs.items() if k in execute_kwargs}
816-
kwargs = {k: v for k, v in kwargs.items() if k not in execute_kwargs}
815+
_kwargs = dict()
816+
for kwarg in execute_kwargs:
817+
try:
818+
_kwargs[kwarg] = kwargs.pop(kwarg)
819+
except KeyError:
820+
pass
817821

818822
insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
819823

Diff for: git/objects/submodule/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
import os
3939
import logging
4040
import uuid
41-
from unittest.case import SkipTest
41+
try:
42+
from unittest import SkipTest
43+
except ImportError:
44+
from unittest2 import SkipTest
4245
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
4346
from git.objects.base import IndexObject, Object
4447
from git.cmd import Git

Diff for: git/test/lib/helper.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
from __future__ import print_function
77

88
from functools import wraps
9+
import sys
910
import io
1011
import logging
1112
import os
1213
import tempfile
1314
import textwrap
1415
import time
15-
from unittest import TestCase
16-
import unittest
1716

18-
from git.compat import string_types, is_win, PY3
17+
from git.compat import string_types, is_win
1918
from git.util import rmtree
2019

2120
import os.path as osp
21+
if sys.version_info[0:2] == (2, 6):
22+
import unittest2 as unittest
23+
else:
24+
import unittest
2225

26+
TestCase = unittest.TestCase
2327

2428
ospd = osp.dirname
2529

@@ -329,8 +333,8 @@ class TestBase(TestCase):
329333
of the project history ( to assure tests don't fail for others ).
330334
"""
331335

332-
if not PY3:
333-
assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
336+
if sys.version_info[0:2] == (2, 7):
337+
assertRaisesRegex = TestCase.assertRaisesRegexp
334338

335339
def _small_repo_url(self):
336340
""":return" a path to a small, clonable repository"""

Diff for: git/test/performance/test_odb.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
import sys
55
from time import time
6-
from unittest.case import skipIf
6+
try:
7+
from unittest import skipIf
8+
except ImportError:
9+
from unittest2 import skipIf
10+
711

812
from git.compat import PY3
913
from git.util import HIDE_WINDOWS_KNOWN_ERRORS

Diff for: git/test/test_base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import os
88
import sys
99
import tempfile
10-
from unittest import skipIf
11-
10+
try:
11+
from unittest import SkipTest, skipIf
12+
except ImportError:
13+
from unittest2 import SkipTest, skipIf
1214
import git.objects.base as base
1315
from git.test.lib import (
1416
TestBase,
@@ -129,7 +131,7 @@ def test_add_unicode(self, rw_repo):
129131
try:
130132
file_path.encode(sys.getfilesystemencoding())
131133
except UnicodeEncodeError:
132-
from unittest import SkipTest
134+
133135
raise SkipTest("Environment doesn't support unicode filenames")
134136

135137
with open(file_path, "wb") as fp:

Diff for: git/test/test_fun.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from gitdb.base import IStream
1818
from gitdb.typ import str_tree_type
1919
from git.compat import PY3
20-
21-
from unittest.case import skipIf
20+
try:
21+
from unittest import skipIf
22+
except ImportError:
23+
from unittest2 import skipIf
2224
from stat import (
2325
S_IFDIR,
2426
S_IFREG,

Diff for: git/test/test_index.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
)
1414
import sys
1515
import tempfile
16-
from unittest.case import skipIf
16+
try:
17+
from unittest import skipIf
18+
except ImportError:
19+
from unittest2 import skipIf
1720

1821
from git import (
1922
IndexFile,
@@ -147,8 +150,9 @@ def add_bad_blob():
147150
except Exception as ex:
148151
msg_py3 = "required argument is not an integer"
149152
msg_py2 = "cannot convert argument to integer"
150-
## msg_py26 ="unsupported operand type(s) for &: 'str' and 'long'"
151-
assert msg_py2 in str(ex) or msg_py3 in str(ex), str(ex)
153+
msg_py26 = "unsupported operand type(s) for &: 'str' and 'long'"
154+
assert msg_py2 in str(ex) or msg_py3 in str(ex) or \
155+
msg_py26 in str(ex), str(ex)
152156

153157
## 2nd time should not fail due to stray lock file
154158
try:

Diff for: git/test/test_remote.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import random
88
import tempfile
9-
from unittest.case import skipIf
9+
try:
10+
from unittest import skipIf
11+
except ImportError:
12+
from unittest2 import skipIf
1013

1114
from git import (
1215
RemoteProgress,

Diff for: git/test/test_repo.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import pickle
1212
import sys
1313
import tempfile
14-
from unittest.case import skipIf
14+
try:
15+
from unittest import skipIf, SkipTest
16+
except ImportError:
17+
from unittest2 import skipIf, SkipTest
1518

1619
from git import (
1720
InvalidGitRepositoryError,
@@ -54,7 +57,6 @@
5457
from git.test.lib import with_rw_directory
5558
from git.util import join_path_native, rmtree, rmfile
5659
from gitdb.util import bin_to_hex
57-
from unittest import SkipTest
5860

5961
import functools as fnt
6062
import os.path as osp

Diff for: git/test/test_submodule.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
33
import os
44
import sys
5-
from unittest.case import skipIf
5+
try:
6+
from unittest import skipIf
7+
except ImportError:
8+
from unittest2 import skipIf
69

710
import git
811
from git.cmd import Git

Diff for: git/test/test_tree.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from io import BytesIO
88
import os
99
import sys
10-
from unittest.case import skipIf
10+
try:
11+
from unittest import skipIf
12+
except ImportError:
13+
from unittest2 import skipIf
1114

1215
from git import (
1316
Tree,

Diff for: git/util.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
PY3
3535
)
3636
from .exc import InvalidGitRepositoryError
37-
from unittest.case import SkipTest
38-
37+
try:
38+
from unittest import SkipTest
39+
except ImportError:
40+
from unittest2 import SkipTest
3941

4042
# NOTE: Some of the unused imports might be used/imported by others.
4143
# Handle once test-cases are back up and running.

Diff for: requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
gitdb>=0.6.4
22
ddt
3-
mock
3+
mock
4+
unittest2; python_version < '2.7'

0 commit comments

Comments
 (0)