Skip to content

Commit f3d5df2

Browse files
committed
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).
1 parent 5149c80 commit f3d5df2

File tree

15 files changed

+81
-27
lines changed

15 files changed

+81
-27
lines changed

.appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ environment:
77
matrix:
88
## MINGW
99
#
10+
- PYTHON: "C:\\Python26"
11+
PYTHON_VERSION: "2.6"
12+
GIT_PATH: "%GIT_DAEMON_PATH%"
1013
- PYTHON: "C:\\Python27"
1114
PYTHON_VERSION: "2.7"
1215
GIT_PATH: "%GIT_DAEMON_PATH%"

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
language: python
22
python:
3+
- "2.6"
34
- "2.7"
45
- "3.3"
56
- "3.4"
67
- "3.5"
78
# - "pypy" - won't work as smmap doesn't work (see gitdb/.travis.yml for details)
9+
#matrix:
10+
# allow_failures:
11+
# - python: "2.6"
812
git:
913
# a higher depth is needed for most of the tests - must be high enough to not actually be shallow
1014
# as we clone our own repository in the process
@@ -15,6 +19,7 @@ install:
1519
- git fetch --tags
1620
- pip install -r test-requirements.txt
1721
- pip install codecov sphinx
22+
- if [ "$TRAVIS_PYTHON_VERSION" == '2.6' ]; then pip install unittest2; fi
1823

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

git/cmd.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
139139
CREATE_NO_WINDOW = 0x08000000
140140

141141
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
142-
# seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
142+
# see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
143143
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP
144-
if is_win
144+
if is_win and sys.version_info >= (2, 7)
145145
else 0)
146146

147147

@@ -245,7 +245,7 @@ def __del__(self):
245245
return
246246

247247
# can be that nothing really exists anymore ...
248-
if os is None or os.kill is None:
248+
if os is None or getattr(os, 'kill', None) is None:
249249
return
250250

251251
# try to kill it
@@ -831,8 +831,12 @@ def _call_process(self, method, *args, **kwargs):
831831
:return: Same as ``execute``"""
832832
# Handle optional arguments prior to calling transform_kwargs
833833
# otherwise these'll end up in args, which is bad.
834-
_kwargs = {k: v for k, v in kwargs.items() if k in execute_kwargs}
835-
kwargs = {k: v for k, v in kwargs.items() if k not in execute_kwargs}
834+
_kwargs = dict()
835+
for kwarg in execute_kwargs:
836+
try:
837+
_kwargs[kwarg] = kwargs.pop(kwarg)
838+
except KeyError:
839+
pass
836840

837841
insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
838842

git/objects/submodule/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import logging
44
import os
55
import stat
6-
from unittest.case import SkipTest
6+
try:
7+
from unittest import SkipTest
8+
except ImportError:
9+
from unittest2 import SkipTest
710
import uuid
811

912
import git

git/test/lib/helper.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77

88
import contextlib
99
from functools import wraps
10+
import sys
1011
import io
1112
import logging
1213
import os
1314
import tempfile
1415
import textwrap
1516
import time
16-
from unittest import TestCase
17-
import unittest
1817

19-
from git.compat import string_types, is_win, PY3
18+
from git.compat import string_types, is_win
2019
from git.util import rmtree, cwd
2120

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

27+
TestCase = unittest.TestCase
2428

2529
ospd = osp.dirname
2630

@@ -335,8 +339,11 @@ class TestBase(TestCase):
335339
of the project history ( to assure tests don't fail for others ).
336340
"""
337341

338-
if not PY3:
339-
assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
342+
# On py26, unittest2 has assertRaisesRegex
343+
# On py3, unittest has assertRaisesRegex
344+
# On py27, we use unittest, which names it differently:
345+
if sys.version_info[0:2] == (2, 7):
346+
assertRaisesRegex = TestCase.assertRaisesRegexp
340347

341348
def _small_repo_url(self):
342349
""":return" a path to a small, clonable repository"""

git/test/test_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import os
88
import sys
99
import tempfile
10-
from unittest import skipIf
10+
try:
11+
from unittest import SkipTest, skipIf
12+
except ImportError:
13+
from unittest2 import SkipTest, skipIf
1114

1215
from git import (
1316
Blob,
@@ -131,7 +134,6 @@ def test_add_unicode(self, rw_repo):
131134
try:
132135
file_path.encode(sys.getfilesystemencoding())
133136
except UnicodeEncodeError:
134-
from unittest import SkipTest
135137
raise SkipTest("Environment doesn't support unicode filenames")
136138

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

git/test/test_fun.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from io import BytesIO
22
from stat import S_IFDIR, S_IFREG, S_IFLNK
3-
from unittest.case import skipIf
3+
try:
4+
from unittest import skipIf
5+
except ImportError:
6+
from unittest2 import skipIf
47

58
from git.compat import PY3
69
from git.index import IndexFile

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
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,
@@ -149,8 +152,9 @@ def add_bad_blob():
149152
except Exception as ex:
150153
msg_py3 = "required argument is not an integer"
151154
msg_py2 = "cannot convert argument to integer"
152-
## msg_py26 ="unsupported operand type(s) for &: 'str' and 'long'"
153-
assert msg_py2 in str(ex) or msg_py3 in str(ex), str(ex)
155+
msg_py26 = "unsupported operand type(s) for &: 'str' and 'long'"
156+
assert msg_py2 in str(ex) or msg_py3 in str(ex) or \
157+
msg_py26 in str(ex), str(ex)
154158

155159
## 2nd time should not fail due to stray lock file
156160
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
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,
@@ -53,7 +56,6 @@
5356
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cygpath
5457
from git.test.lib import with_rw_directory
5558
from git.util import join_path_native, rmtree, rmfile, bin_to_hex
56-
from unittest import SkipTest
5759

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

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