Skip to content

Commit 1d68375

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. - Added the dependency to `unittest2` in case of Python 2.6 to `requirements.txt`.
1 parent afcd64e commit 1d68375

File tree

12 files changed

+56
-20
lines changed

12 files changed

+56
-20
lines changed

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: 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

git/objects/submodule/base.py

Lines changed: 4 additions & 1 deletion
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

git/test/lib/helper.py

Lines changed: 10 additions & 4 deletions
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
16+
if sys.version_info[0:2] == (2, 6):
17+
import unittest2 as unittest
18+
else:
19+
import unittest
1720

1821
from git.compat import string_types, is_win, PY3
1922
from git.util import rmtree
2023

2124
import os.path as osp
2225

26+
TestCase = unittest.TestCase
2327

2428
ospd = osp.dirname
2529

@@ -329,8 +333,10 @@ 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, 6):
337+
assertRaisesRegex = TestCase.assertRaisesRegex
338+
elif sys.version_info[0:2] == (2, 7):
339+
assertRaisesRegex = TestCase.assertRaisesRegexp
334340

335341
def _small_repo_url(self):
336342
""":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
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

git/test/test_base.py

Lines changed: 5 additions & 3 deletions
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:

git/test/test_index.py

Lines changed: 4 additions & 1 deletion
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,

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
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,

git/test/test_repo.py

Lines changed: 4 additions & 2 deletions
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

git/test/test_submodule.py

Lines changed: 4 additions & 1 deletion
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

git/test/test_tree.py

Lines changed: 4 additions & 1 deletion
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,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy