Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf3d5df2

Browse files
committed
Fixes to support Python 2.6 again.
Details:- Added Python 2.6 again to .travis.yml (it was removed in commit4486bcb).- Replaced the use of dictionary comprehensions in `git/cmd.py` around line 800 with the code before that change (in commit25a2ebf). 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 parent5149c80 commitf3d5df2

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-
ifis_win
144+
ifis_winandsys.version_info>= (2,7)
145145
else0)
146146

147147

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

247247
# can be that nothing really exists anymore ...
248-
ifosisNoneoros.killisNone:
248+
ifosisNoneorgetattr(os,'kill',None)isNone:
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:vfork,vinkwargs.items()ifkinexecute_kwargs}
835-
kwargs= {k:vfork,vinkwargs.items()ifknotinexecute_kwargs}
834+
_kwargs=dict()
835+
forkwarginexecute_kwargs:
836+
try:
837+
_kwargs[kwarg]=kwargs.pop(kwarg)
838+
exceptKeyError:
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
importlogging
44
importos
55
importstat
6-
fromunittest.caseimportSkipTest
6+
try:
7+
fromunittestimportSkipTest
8+
exceptImportError:
9+
fromunittest2importSkipTest
710
importuuid
811

912
importgit

‎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
importcontextlib
99
fromfunctoolsimportwraps
10+
importsys
1011
importio
1112
importlogging
1213
importos
1314
importtempfile
1415
importtextwrap
1516
importtime
16-
fromunittestimportTestCase
17-
importunittest
1817

19-
fromgit.compatimportstring_types,is_win,PY3
18+
fromgit.compatimportstring_types,is_win
2019
fromgit.utilimportrmtree,cwd
2120

2221
importos.pathasosp
22+
ifsys.version_info[0:2]== (2,6):
23+
importunittest2asunittest
24+
else:
25+
importunittest
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-
ifnotPY3:
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+
ifsys.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
importos
88
importsys
99
importtempfile
10-
fromunittestimportskipIf
10+
try:
11+
fromunittestimportSkipTest,skipIf
12+
exceptImportError:
13+
fromunittest2importSkipTest,skipIf
1114

1215
fromgitimport (
1316
Blob,
@@ -131,7 +134,6 @@ def test_add_unicode(self, rw_repo):
131134
try:
132135
file_path.encode(sys.getfilesystemencoding())
133136
exceptUnicodeEncodeError:
134-
fromunittestimportSkipTest
135137
raiseSkipTest("Environment doesn't support unicode filenames")
136138

137139
withopen(file_path,"wb")asfp:

‎git/test/test_fun.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
fromioimportBytesIO
22
fromstatimportS_IFDIR,S_IFREG,S_IFLNK
3-
fromunittest.caseimportskipIf
3+
try:
4+
fromunittestimportskipIf
5+
exceptImportError:
6+
fromunittest2importskipIf
47

58
fromgit.compatimportPY3
69
fromgit.indeximportIndexFile

‎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,
@@ -149,8 +152,9 @@ def add_bad_blob():
149152
exceptExceptionasex:
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-
assertmsg_py2instr(ex)ormsg_py3instr(ex),str(ex)
155+
msg_py26="unsupported operand type(s) for &: 'str' and 'long'"
156+
assertmsg_py2instr(ex)ormsg_py3instr(ex)or \
157+
msg_py26instr(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
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,
@@ -53,7 +56,6 @@
5356
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS,cygpath
5457
fromgit.test.libimportwith_rw_directory
5558
fromgit.utilimportjoin_path_native,rmtree,rmfile,bin_to_hex
56-
fromunittestimportSkipTest
5759

5860
importfunctoolsasfnt
5961
importos.pathasosp

‎git/test/test_submodule.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
44
importos
55
importsys
6-
fromunittest.caseimportskipIf
6+
try:
7+
fromunittestimportskipIf
8+
exceptImportError:
9+
fromunittest2importskipIf
710

811
importgit
912
fromgit.cmdimportGit

‎git/test/test_tree.py

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

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

1114
fromgitimport (
1215
Tree,

‎git/test/test_util.py

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

77
importtempfile
88
importtime
9-
fromunittest.caseimportskipIf
9+
try:
10+
fromunittestimportskipIf
11+
exceptImportError:
12+
fromunittest2importskipIf
13+
1014

1115
importddt
1216

‎git/util.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
importlogging
1212
importos
1313
importplatform
14+
importsubprocess
1415
importre
1516
importshutil
1617
importstat
1718
importtime
18-
fromunittest.caseimportSkipTest
19+
try:
20+
fromunittestimportSkipTest
21+
exceptImportError:
22+
fromunittest2importSkipTest
1923

2024
fromgitdb.utilimport (# NOQA @IgnorePep8
2125
make_sha,
@@ -303,7 +307,7 @@ def is_cygwin_git(git_executable):
303307
ifnotis_win:
304308
returnFalse
305309

306-
fromsubprocessimportcheck_output
310+
#from subprocess import check_output
307311

308312
is_cygwin=_is_cygwin_cache.get(git_executable)
309313
ifis_cygwinisNone:
@@ -316,8 +320,11 @@ def is_cygwin_git(git_executable):
316320

317321
## Just a name given, not a real path.
318322
uname_cmd=osp.join(git_dir,'uname')
319-
uname=check_output(uname_cmd,universal_newlines=True)
320-
is_cygwin='CYGWIN'inuname
323+
process=subprocess.Popen([uname_cmd],stdout=subprocess.PIPE,
324+
universal_newlines=True)
325+
uname_out,_=process.communicate()
326+
#retcode = process.poll()
327+
is_cygwin='CYGWIN'inuname_out
321328
exceptExceptionasex:
322329
log.debug('Failed checking if running in CYGWIN due to: %r',ex)
323330
_is_cygwin_cache[git_executable]=is_cygwin

‎requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
gitdb>=0.6.4
22
ddt>=1.1.1
3+
unittest2;python_version<'2.7'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp