Skip to content

Commit a795f40

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 a795f40

File tree

14 files changed

+65
-25
lines changed

14 files changed

+65
-25
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 0 deletions
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

‎git/cmd.py‎

Lines changed: 6 additions & 2 deletions
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: vfork, vinkwargs.items() ifkinexecute_kwargs}
816-
kwargs={k: vfork, vinkwargs.items() ifknotinexecute_kwargs}
815+
_kwargs=dict()
816+
forkwarginexecute_kwargs:
817+
try:
818+
_kwargs[kwarg] =kwargs.pop(kwarg)
819+
exceptKeyError:
820+
pass
817821

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

‎git/objects/submodule/base.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
importos
3939
importlogging
4040
importuuid
41-
fromunittest.caseimportSkipTest
41+
try:
42+
fromunittestimportSkipTest
43+
exceptImportError:
44+
fromunittest2importSkipTest
4245
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS
4346
fromgit.objects.baseimportIndexObject, Object
4447
fromgit.cmdimportGit

‎git/test/lib/helper.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
from __future__ importprint_function
77

88
fromfunctoolsimportwraps
9+
importsys
910
importio
1011
importlogging
1112
importos
1213
importtempfile
1314
importtextwrap
1415
importtime
15-
fromunittestimportTestCase
16-
importunittest
1716

18-
fromgit.compatimportstring_types, is_win, PY3
17+
fromgit.compatimportstring_types, is_win
1918
fromgit.utilimportrmtree
2019

2120
importos.pathasosp
21+
ifsys.version_info[0:2] == (2, 6):
22+
importunittest2asunittest
23+
else:
24+
importunittest
2225

26+
TestCase=unittest.TestCase
2327

2428
ospd=osp.dirname
2529

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

332-
ifnotPY3:
333-
assertRaisesRegex=unittest.TestCase.assertRaisesRegexp
336+
# On py26, unittest2 has assertRaisesRegex
337+
# On py3, unittest has assertRaisesRegex
338+
# On py27, we use unittest, which names it differently:
339+
ifsys.version_info[0:2] == (2, 7):
340+
assertRaisesRegex=TestCase.assertRaisesRegexp
334341

335342
def_small_repo_url(self):
336343
""":return" a path to a small, clonable repository"""

‎git/test/performance/test_odb.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
importsys
55
fromtimeimporttime
6-
fromunittest.caseimportskipIf
6+
try:
7+
fromunittestimportskipIf
8+
exceptImportError:
9+
fromunittest2importskipIf
10+
711

812
fromgit.compatimportPY3
913
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS

‎git/test/test_base.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
importos
88
importsys
99
importtempfile
10-
fromunittestimportskipIf
11-
10+
try:
11+
fromunittestimportSkipTest, skipIf
12+
exceptImportError:
13+
fromunittest2importSkipTest, skipIf
1214
importgit.objects.baseasbase
1315
fromgit.test.libimport (
1416
TestBase,
@@ -129,7 +131,6 @@ def test_add_unicode(self, rw_repo):
129131
try:
130132
file_path.encode(sys.getfilesystemencoding())
131133
exceptUnicodeEncodeError:
132-
fromunittestimportSkipTest
133134
raiseSkipTest("Environment doesn't support unicode filenames")
134135

135136
withopen(file_path, "wb") asfp:

‎git/test/test_fun.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
fromgitdb.baseimportIStream
1818
fromgitdb.typimportstr_tree_type
1919
fromgit.compatimportPY3
20-
21-
fromunittest.caseimportskipIf
20+
try:
21+
fromunittestimportskipIf
22+
exceptImportError:
23+
fromunittest2importskipIf
2224
fromstatimport (
2325
S_IFDIR,
2426
S_IFREG,

‎git/test/test_index.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
)
1414
importsys
1515
importtempfile
16-
fromunittest.caseimportskipIf
16+
try:
17+
fromunittestimportskipIf
18+
exceptImportError:
19+
fromunittest2importskipIf
1720

1821
fromgitimport (
1922
IndexFile,
@@ -147,8 +150,9 @@ def add_bad_blob():
147150
exceptExceptionasex:
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-
assertmsg_py2instr(ex) ormsg_py3instr(ex), str(ex)
153+
msg_py26="unsupported operand type(s) for &: 'str' and 'long'"
154+
assertmsg_py2instr(ex) ormsg_py3instr(ex) or \
155+
msg_py26instr(ex), str(ex)
152156

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

‎git/test/test_remote.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
importrandom
88
importtempfile
9-
fromunittest.caseimportskipIf
9+
try:
10+
fromunittestimportskipIf
11+
exceptImportError:
12+
fromunittest2importskipIf
1013

1114
fromgitimport (
1215
RemoteProgress,

‎git/test/test_repo.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
importpickle
1212
importsys
1313
importtempfile
14-
fromunittest.caseimportskipIf
14+
try:
15+
fromunittestimportskipIf, SkipTest
16+
exceptImportError:
17+
fromunittest2importskipIf, SkipTest
1518

1619
fromgitimport (
1720
InvalidGitRepositoryError,
@@ -54,7 +57,6 @@
5457
fromgit.test.libimportwith_rw_directory
5558
fromgit.utilimportjoin_path_native, rmtree, rmfile
5659
fromgitdb.utilimportbin_to_hex
57-
fromunittestimportSkipTest
5860

5961
importfunctoolsasfnt
6062
importos.pathasosp

0 commit comments

Comments
(0)