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 tests for python3 using decode() on pipe output #27

Merged
merged 6 commits into from
Jun 22, 2015
Merged
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: python
python: 2.7
env:
- TOXENV=py27
- TOXENV=pypy
- TOXENV=py33
- TOXENV=py34
install:
- "./.travis-workarounds.sh"
- pip install -U tox
Expand Down
1 change: 1 addition & 0 deletions shub/deploy_reqs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import click
import os
import tempfile
Expand Down
2 changes: 1 addition & 1 deletion shub/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def cli(context):
if key and is_valid_key(key):
descriptor = os.open(
NETRC_FILE,
os.O_CREAT | os.O_RDWR | os.O_APPEND, 0600)
os.O_CREAT | os.O_RDWR | os.O_APPEND, 0o600)
with os.fdopen(descriptor, 'a+') as out:
line = 'machine scrapinghub.com login {0} password ""\n'.format(key)
out.write(line)
Expand Down
2 changes: 1 addition & 1 deletion shub/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def cli():
"version": [],
}

for command, modules in module_deps.iteritems():
for command, modules in module_deps.items():
m = missing_modules(*modules)
if m:
cli.add_command(missingmod_cmd(m), command)
Expand Down
38 changes: 21 additions & 17 deletions shub/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import unicode_literals
import imp
import os
import netrc
import subprocess
import sys

from glob import glob
from os.path import isdir
Expand All @@ -18,6 +20,9 @@
OS_WIN = True if os.name == 'nt' else False
NETRC_FILE = os.path.expanduser('~/_netrc') if OS_WIN else os.path.expanduser('~/.netrc')

FALLBACK_ENCODING = 'utf-8'
STDOUT_ENCODING = sys.stdout.encoding or FALLBACK_ENCODING


def missing_modules(*modules):
"""Receives a list of module names and returns those which are missing"""
Expand Down Expand Up @@ -71,35 +76,34 @@ def make_deploy_request(url, data, files, auth):
raise ClickException("Deploy failed: {}".format(exc))


def get_cmd_output(cmd):
return Popen(cmd, stdout=PIPE).communicate()[0].decode(STDOUT_ENCODING)


def pwd_git_version():
p = Popen(['git', 'describe', '--always'], stdout=PIPE)
d = p.communicate()[0].strip('\n')
if p.wait() != 0:
p = Popen(['git', 'rev-list', '--count', 'HEAD'], stdout=PIPE)
d = 'r%s' % p.communicate()[0].strip('\n')
process = Popen(['git', 'describe', '--always'], stdout=PIPE)
commit_id = process.communicate()[0].decode(STDOUT_ENCODING).strip('\n')
if process.wait() != 0:
commit_id = get_cmd_output(['git', 'rev-list', '--count', 'HEAD']).strip('\n')

p = Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=PIPE)
b = p.communicate()[0].strip('\n')
return '%s-%s' % (d, b)
branch = get_cmd_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip('\n')
return '%s-%s' % (commit_id, branch)


def pwd_hg_version():
p = Popen(['hg', 'tip', '--template', '{rev}'], stdout=PIPE)
d = 'r%s' % p.communicate()[0]
p = Popen(['hg', 'branch'], stdout=PIPE)
b = p.communicate()[0].strip('\n')
return '%s-%s' % (d, b)
commit_id = 'r%s' % get_cmd_output(['hg', 'tip', '--template', '{rev}'])

branch = get_cmd_output(['hg', 'branch']).strip('\n')
return '%s-%s' % (commit_id, branch)


def pwd_bzr_version():
p = Popen(['bzr', 'revno'], stdout=PIPE)
d = '%s' % p.communicate()[0].strip()
return d
return '%s' % get_cmd_output(['bzr', 'revno']).strip()


def run(cmd):
output = subprocess.check_output(cmd, shell=True)
return output.strip()
return output.decode(STDOUT_ENCODING).strip()


def decompress_egg_files():
Expand Down
8 changes: 5 additions & 3 deletions tests/test_logout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest, os
from shub.logout import remove_sh_key
import os
import unittest
from tempfile import NamedTemporaryFile
from shub.logout import remove_sh_key


class LogoutTestCase(unittest.TestCase):
_netrc_file = None
Expand All @@ -18,7 +20,7 @@ def test_was_key_removed_from_netrc(self):
def _create_tmp_netrc(self):
with NamedTemporaryFile(delete=False) as netrc:
line = 'machine scrapinghub.com login ffffffffffffffffffffffffffffffff password ""'
netrc.write(line)
netrc.write(line.encode('ascii'))
return netrc.name

def _delete_tmp_netrc(self, netrc_file):
Expand Down