Skip to content

Commit

Permalink
Test changes towards getting them passing on Travis too
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 7, 2015
1 parent c060601 commit 79e8dca
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 101 deletions.
29 changes: 17 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: python
os:
- linux
- osx
- linux
- osx
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- '2.6'
- '2.7'
- '3.3'
- '3.4'
env:
global:
- secure: EUpWmrnhHKPkz9cOGbEEwhBtUBRqtQ775ck042B8/pI9ZZZghbKl3Jm8ahpfms3JiZcHMCG06MBREs1ISK/g2OfHKsdULCg5g3UFXteVQo769kwh/x4lniSbU2eipcN0s9Q/Ak5zStwTa5aNQ4FU/3zSgTDxi/OcDKGXDbVwHD8=
Expand All @@ -20,15 +20,20 @@ install:
- pip install -r requirements-opt.txt || echo "skipped"
- pip install coveralls
script:
- ./pretest
- travis_wait coverage run --source=jira setup.py test
- "./pretest"
- travis_wait python setup.py test
after_success:
coveralls
python setup.py build_sphinx upload_docs
- coveralls
- python setup.py build_sphinx upload_docs
branches:
only:
- master
notifications:
hipchat: 7d72ba6ba0bf07248f17e0a6a1a899@DevOps
#matrix:
# fast_finish: true
deploy:
provider: pypi
user: sorin
password:
secure: R/fYV3nMSrv444/HJeT0p5gBMg3pn1Zon4AR33DG94kG/ONerKg5hCxNL94FBU/uFmXpi8qGEeattNMDCes75LTZkLvTy6z16WZZHOOR625n/ZGzhNd8kXHAqng5JtX6uMx6ZxFAbG83ljrbssxum2FcFDGcIz7auQPMFnRUCY0=
distributions: "sdist bdist_wheel"

21 changes: 10 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,34 @@
JIRA Python Library
===================

.. image:: https://pypip.in/py_versions/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/license/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://api.travis-ci.org/pycontribs/jira.svg?branch=master
:target: https://travis-ci.org/pycontribs/jira

.. image:: https://img.shields.io/coveralls/pycontribs/jira.svg
:target: https://coveralls.io/r/pycontribs/jira

.. image:: https://pypip.in/download/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/version/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/egg/jira/badge.png?style=flat
.. image:: https://pypip.in/egg/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/wheel/jira/badge.png?style=flat
.. image:: https://pypip.in/wheel/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/license/jira/badge.png?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/status/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

.. image:: https://pypip.in/py_versions/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/
.. image:: https://img.shields.io/coveralls/pycontribs/jira.svg
:target: https://coveralls.io/r/pycontribs/jira

.. image:: https://pypip.in/format/jira/badge.svg?style=flat
:target: https://pypi.python.org/pypi/jira/

This library eases the use of the JIRA REST API from Python

Expand Down
27 changes: 8 additions & 19 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@
import copy
import os
import re
import sys
import string
import warnings
import tempfile
import logging
import requests
import json
import warnings


from six import string_types
from six.moves import html_parser
from six import print_ as print


from jira.exceptions import raise_on_error, JIRAError
# JIRA specific resources
from jira.resources import Resource, Issue, Comment, Project, Attachment, Component, Dashboard, Filter, Votes, Watchers, Worklog, IssueLink, IssueLinkType, IssueType, Priority, Version, Role, Resolution, SecurityLevel, Status, User, CustomFieldOption, RemoteLink
# GreenHopper specific resources
from jira.resources import GreenHopperResource, Board, Sprint
from jira.resilientsession import ResilientSession
from .utils import threaded_requests

try:
from random import SystemRandom
Expand All @@ -51,18 +49,6 @@
# warnings.warn("Python default encoding is '%s' instead of 'UTF8' which means that there is a big change of having problems. Possible workaround http://stackoverflow.com/a/17628350/99834" % encoding)


def threaded_requests(requests):
for fn, url, request_args in requests:
th = threading.Thread(
target=fn, args=(url,), kwargs=request_args, name=url,
)
th.start()

for th in threading.enumerate():
if th.name.startswith('http'):
th.join()


def translate_resource_args(func):
"""
Decorator that converts Issue and Project resources to their keys when used as arguments.
Expand Down Expand Up @@ -1731,8 +1717,11 @@ def _get_json(self, path, params=None, base=JIRA_BASE_URL):
url = self._get_url(path, base)
r = self._session.get(url, params=params, headers=self._options['headers'])
raise_on_error(r)

r_json = json.loads(r.text)
try:
r_json = json.loads(r.text)
except ValueError as e:
logging.error("%s\n%s" % (e, r.text))
raise e
return r_json

def _find_for_resource(self, resource_cls, ids, expand=None):
Expand Down Expand Up @@ -1865,7 +1854,7 @@ def rename_user(self, old_user, new_user):
p = re.compile("type=\"hidden\" name=\"cannedScriptArgs_Hidden_output\" value=\"(.*?)\"\/>", re.MULTILINE | re.DOTALL)
m = p.search(r.content)
if m:
h = HTMLParser.HTMLParser()
h = html_parser.HTMLParser()
msg = h.unescape(m.group(1))
logging.info(msg)

Expand Down
4 changes: 4 additions & 0 deletions jira/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
import logging


class JIRAError(Exception):
Expand Down Expand Up @@ -47,6 +48,9 @@ def raise_on_error(r):
except ValueError:
error = r.text
raise JIRAError(r.status_code, error, r.url)
# for debugging weird errors on CI
if r.status_code != 200 or len(r.text) == 0:
logging.error("Got %s requesting %s\n--- body ---\n%s\n--- request headers ---\n%s\n---\n" % (r.status_code, r.url, r.text, r.headers))


def get_error_list(r):
Expand Down
15 changes: 8 additions & 7 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
"""

import re
import sys
import logging
import random
import pprint
import json

from six import iteritems, string_types, text_type
from six import print_ as print

from jira.exceptions import raise_on_error, get_error_list
from .utils import threaded_requests
from .exceptions import raise_on_error, get_error_list


class Resource(object):
Expand Down Expand Up @@ -194,8 +191,12 @@ def delete(self, params=None):
def _load(self, url, headers=None, params=None):
r = self._session.get(url, headers=headers, params=params)
raise_on_error(r)

self._parse_raw(json.loads(r.text))
try:
j = json.loads(r.text)
except ValueError as e:
logging.error("%s:\n%s" % (e, r.text))
raise e
self._parse_raw(j)

def _parse_raw(self, raw):
self.raw = raw
Expand Down
14 changes: 14 additions & 0 deletions jira/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
import threading


def threaded_requests(requests):
for fn, url, request_args in requests:
th = threading.Thread(
target=fn, args=(url,), kwargs=request_args, name=url,
)
th.start()

for th in threading.enumerate():
if th.name.startswith('http'):
th.join()
2 changes: 1 addition & 1 deletion jira/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into the jira module
__version__ = '0.34'
__version__ = '0.35'
3 changes: 3 additions & 0 deletions requirements-opt.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
ipython>=0.13
pytest-osxnotify
pytest-cache
unittest2
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ upload-dir = docs/build/html
[pytest]
norecursedirs = . .svn jira _build tmp* lib/third lib *.egg bin distutils build docs demo
python_files = *.py
addopts = -p no:xdist --ignore=setup.py --tb=long -rsxX -v --junitxml=reports --maxfail=3 --pep8 tests
addopts = -p no:xdist --ignore=setup.py --tb=long -rsxX -v --junitxml=reports --maxfail=10 --pep8 tests
# -n 1
# --maxfail=2 -n4
# -n4 runs up to 4 parallel procs
Expand Down
22 changes: 19 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand

NAME="jira"

class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
Expand All @@ -11,6 +12,19 @@ def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []

# if we have pytest-cache module we enable the test failures first mode
try:
import pytest_cache
self.pytest_args.append("--ff")
except ImportError:
pass

try:
import coveralls
self.pytest_args.append("--cov=%s" % NAME)
except ImportError:
pass

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
Expand All @@ -22,9 +36,9 @@ def run_tests(self):
errno = pytest.main(self.pytest_args)
sys.exit(errno)

exec(open('jira/version.py').read())
exec(open('%s/version.py' % NAME).read())
setup(
name='jira', # was jira-python
name=NAME,
version=__version__,
cmdclass = {'test': PyTest},
packages=find_packages(exclude=['tests', 'tools']),
Expand Down Expand Up @@ -52,15 +66,17 @@ def run_tests(self):
long_description=open("README.rst").read(),
author='Ben Speakmon',
author_email='ben.speakmon@gmail.com',
provides=['jira'],
provides=[NAME],
keywords='jira atlassian rest api',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Internet :: WWW/HTTP',
],
)

0 comments on commit 79e8dca

Please sign in to comment.