Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: python 3 compatibility #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ To run the tests, bootstrap Buildout and run this command:
...
$ ./bin/test

We also use Tox_. It will run the tests for Python 2.6 and 2.7.
We also use Tox_. It will run the tests for Python 2.7, 3.4, and 3.5.

::

Expand All @@ -177,7 +177,7 @@ Requirements
------------

* Git >= 1.7
* Python >= 2.6
* Python 2.7, 3.4 3.5

License
-------
Expand Down
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
install_requires = [
'GitPython>=0.3.2RC1']

# Add argparse if less than Python 2.7
if sys.version_info[0] <= 2 and sys.version_info[1] < 7:
install_requires.append('argparse>=1.2.1')

setup(name='git-sweep',
version=version,
description="Clean up branches from your Git remotes",
Expand All @@ -26,8 +22,9 @@
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: POSIX',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Version Control',
'Topic :: Text Processing'
Expand Down
7 changes: 6 additions & 1 deletion src/gitsweep/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from gitsweep.inspector import Inspector
from gitsweep.deleter import Deleter

try:
input = raw_input
except NameError:
pass


class CommandLine(object):

Expand Down Expand Up @@ -142,7 +147,7 @@ def _sweep(self):

if not args.force:
sys.stdout.write('\nDelete these branches? (y/n) ')
answer = raw_input()
answer = input()
if args.force or answer.lower().startswith('y'):
sys.stdout.write('\n')
for ref in ok_to_delete:
Expand Down
9 changes: 6 additions & 3 deletions src/gitsweep/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch

from gitsweep.tests.testcases import CommandTestCase

Expand Down Expand Up @@ -135,7 +138,7 @@ def test_will_cleanup(self):
self.make_commit()
self.command('git merge branch{0}'.format(i))

with patch('gitsweep.cli.raw_input', create=True) as ri:
with patch('gitsweep.cli.input', create=True) as ri:
ri.return_value = 'y'
(retcode, stdout, stderr) = self.gscommand('git-sweep cleanup')

Expand Down Expand Up @@ -173,7 +176,7 @@ def test_will_abort_cleanup(self):
self.make_commit()
self.command('git merge branch{0}'.format(i))

with patch('gitsweep.cli.raw_input', create=True) as ri:
with patch('gitsweep.cli.input', create=True) as ri:
ri.return_value = 'n'
(retcode, stdout, stderr) = self.gscommand('git-sweep cleanup')

Expand Down
34 changes: 23 additions & 11 deletions src/gitsweep/tests/testcases.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import sys
from os import chdir, getcwd
from os.path import join, basename
import os
from tempfile import mkdtemp
from unittest import TestCase
from uuid import uuid4 as uuid
from shutil import rmtree
from shlex import split
from contextlib import contextmanager, nested
from contextlib import contextmanager
import contextlib
from textwrap import dedent

from mock import patch
Expand Down Expand Up @@ -60,7 +62,7 @@ def setUp(self):
This will create the root commit in the test repository automaticall.
"""
super(GitSweepTestCase, self).setUp()

os.environ['GIT_AUTHOR_NAME'] = 'test'
repodir = mkdtemp()

self.repodir = repodir
Expand Down Expand Up @@ -248,16 +250,26 @@ def gscommand(self, command):
patches = (
patch.object(sys, 'stdout'),
patch.object(sys, 'stderr'))

with nested(*patches):
stdout = sys.stdout
stderr = sys.stderr
try:
self.cli.run()
except SystemExit as se:
pass
try:
with contextlib.ExitStack() as stack:
[stack.enter_context(p) for p in patches]
stdout = sys.stdout
stderr = sys.stderr
try:
self.cli.run()
except SystemExit as se:
se_code = se.code

except AttributeError:
with contextlib.nested(*patches):
stdout = sys.stdout
stderr = sys.stderr
try:
self.cli.run()
except SystemExit as se:
se_code = se.code

stdout = ''.join([i[0][0] for i in stdout.write.call_args_list])
stderr = ''.join([i[0][0] for i in stderr.write.call_args_list])

return (se.code, stdout, stderr)
return (se_code, stdout, stderr)
10 changes: 7 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ deps =
mock
commands = python -m gitsweep.scripts.test

[testenv:2.6]
basepython = python2.6

[testenv:2.7]
basepython = python2.7


[testenv:3.4]
basepython = python3.4

[testenv:3.5]
basepython = python3.5