From 6991262c6954bbed45d7cf1c29c53b7d7492a185 Mon Sep 17 00:00:00 2001 From: Markus Siemens Date: Mon, 31 Aug 2015 20:23:34 +0200 Subject: [PATCH] Fix Python3 problem when checking for new version --- PyGitUp/gitup.py | 4 +++- tests/test_version.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/test_version.py diff --git a/PyGitUp/gitup.py b/PyGitUp/gitup.py index f938ab0..a6e9f87 100644 --- a/PyGitUp/gitup.py +++ b/PyGitUp/gitup.py @@ -38,6 +38,7 @@ ############################################################################### # Python libs +import codecs import errno import sys import os @@ -400,7 +401,8 @@ def version_info(self): try: # Get version information from the PyPI JSON API - details = json.loads(urlopen(PYPI_URL).read().decode('utf-8')) + reader = codecs.getreader('utf-8') + details = json.load(reader(urlopen(PYPI_URL))) online_version = details['info']['version'] except (HTTPError, URLError, ValueError): recent = True # To not disturb the user with HTTP/parsing errors diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..4c9d983 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,36 @@ +# System imports +import socket + +# 3rd party libs +from nose.plugins.skip import SkipTest +from nose.tools import * + +# PyGitup imports +from tests import capture + +test_name = 'version' + + +def test_version(): + """ Run 'git up': Check version """ + try: + import pkg_resources as pkg + except ImportError: + raise SkipTest('pip not installed') + + try: + socket.gethostbyname('pypi.python.org') + except socket.error: + raise SkipTest('Can\'t connect to PYPI') + + from PyGitUp.gitup import GitUp + with capture() as [stdout, _]: + GitUp(sparse=True).version_info() + stdout = stdout.getvalue() + + package = pkg.get_distribution('git-up') + local_version_str = package.version + + assert_in(local_version_str, stdout) + +