Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't crash on python -OO, where docstrings are None. Fix #88.

Add nose to tests_require so we can skip tests in python 2.6.
  • Loading branch information...
commit 7cd5cd08ba1d3260ead41b0efdaa398c2b60106c 1 parent 99cbb43
@erikrose erikrose authored
Showing with 32 additions and 25 deletions.
  1. +21 −21 pyelasticsearch/client.py
  2. +7 −0 pyelasticsearch/tests.py
  3. +4 −4 setup.py
View
42 pyelasticsearch/client.py
@@ -41,27 +41,27 @@ def docs_for_kwarg(p):
return '\n :arg %s: See the ES docs.' % p
doc = method.__doc__
-
- # Handle the case where there are no :arg declarations to key off:
- if '\n :arg' not in doc:
- first_param, params = params[0], params[1:]
- doc = doc.replace('\n (Insert es_kwargs here.)',
- docs_for_kwarg(first_param))
-
- for p in params:
- if ('\n :arg %s: ' % p) not in doc:
- # Find the last documented arg so we can put our generated docs
- # after it. No need to explicitly compile this; the regex cache
- # should serve.
- insertion_point = re.search(
- r' :arg (.*?)(?=\n+ (?:$|[^: ]))',
- doc,
- re.MULTILINE | re.DOTALL).end()
-
- doc = ''.join([doc[:insertion_point],
- docs_for_kwarg(p),
- doc[insertion_point:]])
- method.__doc__ = doc
+ if doc is not None: # It's none under python -OO.
+ # Handle the case where there are no :arg declarations to key off:
+ if '\n :arg' not in doc:
+ first_param, params = params[0], params[1:]
+ doc = doc.replace('\n (Insert es_kwargs here.)',
+ docs_for_kwarg(first_param))
+
+ for p in params:
+ if ('\n :arg %s: ' % p) not in doc:
+ # Find the last documented arg so we can put our generated docs
+ # after it. No need to explicitly compile this; the regex cache
+ # should serve.
+ insertion_point = re.search(
+ r' :arg (.*?)(?=\n+ (?:$|[^: ]))',
+ doc,
+ re.MULTILINE | re.DOTALL).end()
+
+ doc = ''.join([doc[:insertion_point],
+ docs_for_kwarg(p),
+ doc[insertion_point:]])
+ method.__doc__ = doc
def es_kwargs(*args_to_convert):
View
7 pyelasticsearch/tests.py
@@ -9,6 +9,7 @@
import six
from mock import patch
+from nose import SkipTest
import requests
# Test that __all__ is sufficient:
@@ -622,6 +623,9 @@ def some_method(foo, bar, query_params=None):
It's neat.
"""
+ if some_method.__doc__ is None:
+ raise SkipTest("This test doesn't work under python -OO.")
+
# Make sure it adds (only) the undocumented args and preserves anything
# that comes after the args block:
self.assertEqual(
@@ -649,6 +653,9 @@ def some_method(foo, bar, query_params=None):
:arg degook: Whether to remove the gook
"""
+ if some_method.__doc__ is None:
+ raise SkipTest("This test doesn't work under python -OO.")
+
self.assertEqual(
some_method.__doc__,
"""
View
8 setup.py
@@ -49,14 +49,14 @@ def find_version(file_path):
requires=[ # Needed?
'six',
'requests(>=1.0,<2.0)',
- 'simplejson(>=2.1.0)'
+ 'simplejson(>=2.1.0)',
],
install_requires=[
- 'six',
'requests>=1.0,<2.0',
- 'simplejson>=2.1.0'
+ 'simplejson>=2.1.0',
+ 'six'
],
- tests_require=['mock'],
+ tests_require=['mock', 'nose>=1.2.1'],
test_suite='pyelasticsearch.tests',
url='http://github.com/rhec/pyelasticsearch'
)
Please sign in to comment.
Something went wrong with that request. Please try again.