From 07287893684a6f3074454d8990b6e9d33d49d6bb Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 28 Sep 2015 13:58:47 -0700 Subject: [PATCH 1/4] fix python 3 support --- requirements-py2.txt | 1 + requirements.txt | 1 - setup.py | 20 +++++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/requirements-py2.txt b/requirements-py2.txt index 9a23970..6d85abd 100644 --- a/requirements-py2.txt +++ b/requirements-py2.txt @@ -1 +1,2 @@ unittest2 +futures diff --git a/requirements.txt b/requirements.txt index 2fc2d56..776f294 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ tornado>=3.0.1,<4.2 -futures PyYAML>=3.0 six>=1.4.0 diff --git a/setup.py b/setup.py index cfe2967..ad80ef1 100644 --- a/setup.py +++ b/setup.py @@ -1,29 +1,35 @@ #!/usr/bin/env python import collections +import sys from setuptools import setup, find_packages from pip.req import parse_requirements +from pip.download import PipSession -def get_install_requirements(): +def get_install_requirements(path): - ReqOpts = collections.namedtuple('ReqOpts', ['skip_requirements_regex', 'default_vcs']) + ReqOpts = collections.namedtuple('ReqOpts', ['skip_requirements_regex', 'default_vcs', 'isolated_mode']) - opts = ReqOpts(None, 'git') + opts = ReqOpts(None, 'git', False) requires = [] dependency_links = [] - for ir in parse_requirements('requirements.txt', options=opts): + session = PipSession() + + for ir in parse_requirements(path, options=opts, session=session): if ir is not None: - if ir.url is not None: - dependency_links.append(str(ir.url)) + if getattr(ir, 'url', getattr(ir, 'link', None)) is not None: + dependency_links.append(str(getattr(ir, 'url', getattr(ir, 'link')))) if ir.req is not None: requires.append(str(ir.req)) return requires, dependency_links -install_requires, dependency_links = get_install_requirements() +install_requires, dependency_links = get_install_requirements('requirements.txt') +if sys.version_info < (3, 0, 0): + install_requires += get_install_requirements('requirements-py2.txt')[0] setup( name="hacheck", From 92028ff79aa80902cbee4f8ce15afbbbf9943d82 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 5 Oct 2015 11:36:59 -0700 Subject: [PATCH 2/4] fix halist on py3 --- hacheck/haupdown.py | 4 +++- tests/test_callables.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hacheck/haupdown.py b/hacheck/haupdown.py index 3a5dcde..d557581 100644 --- a/hacheck/haupdown.py +++ b/hacheck/haupdown.py @@ -2,6 +2,7 @@ from __future__ import print_function +import codecs import contextlib import json import optparse @@ -105,7 +106,8 @@ def main(default_action='list'): 'http://127.0.0.1:%d/recent' % opts.port, timeout=3 )) as f: - resp = json.load(f) + reader = codecs.getreader('utf-8') + resp = json.load(reader(f)) for s in sorted(resp['seen_services']): if isinstance(s, six.string_types): print_s(s) diff --git a/tests/test_callables.py b/tests/test_callables.py index d2ac310..fbe1911 100644 --- a/tests/test_callables.py +++ b/tests/test_callables.py @@ -78,7 +78,7 @@ def test_list(self): mock_urlopen.return_value.read.return_value = json.dumps({ "seen_services": ["foo"], "threshold_seconds": 10, - }) + }).encode('utf-8') self.assertEqual(hacheck.haupdown.halist(), 0) mock_urlopen.assert_called_once_with('http://127.0.0.1:3333/recent', timeout=mock.ANY) mock_print.assert_called_once_with("foo") From f63b76983265306d5fb7c3045a194f7eb84859d1 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 5 Oct 2015 18:30:56 -0700 Subject: [PATCH 3/4] fix unit tests --- hacheck/haupdown.py | 2 +- tests/test_callables.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hacheck/haupdown.py b/hacheck/haupdown.py index d557581..12b41aa 100644 --- a/hacheck/haupdown.py +++ b/hacheck/haupdown.py @@ -103,7 +103,7 @@ def main(default_action='list'): if opts.action == 'list': with contextlib.closing(urlopen( - 'http://127.0.0.1:%d/recent' % opts.port, + 'http://127.0.0.1:{0:d}/recent'.format(opts.port), timeout=3 )) as f: reader = codecs.getreader('utf-8') diff --git a/tests/test_callables.py b/tests/test_callables.py index fbe1911..6b40a56 100644 --- a/tests/test_callables.py +++ b/tests/test_callables.py @@ -9,6 +9,8 @@ import hacheck.haupdown import hacheck.spool +from six.moves import StringIO + # can't use an actual mock.sentinel because it doesn't support string ops sentinel_service_name = 'testing_service_name' @@ -75,10 +77,10 @@ def test_status_downed(self): def test_list(self): with self.setup_wrapper() as (spooler, mock_print): with mock.patch.object(hacheck.haupdown, 'urlopen') as mock_urlopen: - mock_urlopen.return_value.read.return_value = json.dumps({ + mock_urlopen.return_value = StringIO(json.dumps({ "seen_services": ["foo"], "threshold_seconds": 10, - }).encode('utf-8') + }).encode('utf-8')) self.assertEqual(hacheck.haupdown.halist(), 0) mock_urlopen.assert_called_once_with('http://127.0.0.1:3333/recent', timeout=mock.ANY) mock_print.assert_called_once_with("foo") From afd9c14dc5abd2bf239fd5c12248eaa664873920 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 5 Oct 2015 18:36:28 -0700 Subject: [PATCH 4/4] right, the whole point was to test wire data, not unicode data --- tests/test_callables.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_callables.py b/tests/test_callables.py index 6b40a56..0883d30 100644 --- a/tests/test_callables.py +++ b/tests/test_callables.py @@ -9,7 +9,7 @@ import hacheck.haupdown import hacheck.spool -from six.moves import StringIO +from six import BytesIO # can't use an actual mock.sentinel because it doesn't support string ops sentinel_service_name = 'testing_service_name' @@ -70,14 +70,16 @@ def test_status(self): def test_status_downed(self): with self.setup_wrapper() as (spooler, mock_print): - spooler.status_all_down.return_value = [(sentinel_service_name, {'service': sentinel_service_name, 'reason': ''})] + spooler.status_all_down.return_value = [ + (sentinel_service_name, {'service': sentinel_service_name, 'reason': ''}) + ] self.assertEqual(hacheck.haupdown.status_downed(), 0) mock_print.assert_called_once_with("DOWN\t%s\t%s", sentinel_service_name, mock.ANY) def test_list(self): with self.setup_wrapper() as (spooler, mock_print): with mock.patch.object(hacheck.haupdown, 'urlopen') as mock_urlopen: - mock_urlopen.return_value = StringIO(json.dumps({ + mock_urlopen.return_value = BytesIO(json.dumps({ "seen_services": ["foo"], "threshold_seconds": 10, }).encode('utf-8'))