Compatibility with python 3.2

Now all the python 2/3 compatibility code is in elasticsearch.compat
Fixes #52
This commit is contained in:
Honza Král
2014-02-21 16:59:13 +01:00
parent d4aca61a41
commit a54d7035bb
15 changed files with 49 additions and 45 deletions
@@ -9,6 +9,7 @@ from os.path import exists, join, dirname, pardir
import yaml
from elasticsearch import TransportError
from elasticsearch.compat import string_types
from ..test_cases import SkipTest
from . import ElasticTestCase, _get_version
@@ -42,11 +43,11 @@ class YamlTestCase(ElasticTestCase):
def _resolve(self, value):
# resolve variables
if isinstance(value, (type(u''), type(''))) and value.startswith('$'):
if isinstance(value, string_types) and value.startswith('$'):
value = value[1:]
self.assertIn(value, self._state)
value = self._state[value]
if isinstance(value, (type(u''), type(''))):
if isinstance(value, string_types):
value = value.strip()
return value
@@ -172,7 +173,7 @@ class YamlTestCase(ElasticTestCase):
value = self._lookup(path)
expected = self._resolve(expected)
if isinstance(expected, (type(''), type(u''))) and \
if isinstance(expected, string_types) and \
expected.startswith('/') and expected.endswith('/'):
expected = re.compile(expected[1:-1], re.VERBOSE)
self.assertTrue(expected.search(value))
@@ -2,6 +2,7 @@
from elasticsearch import Elasticsearch, MemcachedConnection, NotFoundError
from elasticsearch.transport import ADDRESS_RE
from elasticsearch.compat import u
from . import ElasticTestCase
from ..test_cases import SkipTest
@@ -34,8 +35,8 @@ class TestMemcachedConnection(ElasticTestCase):
self.assertEquals({"answer": 42}, self.mc_client.get("test_index", doc_type="test_type", id=1)["_source"])
def test_unicode(self):
self.mc_client.index("test_index", "test_type", {"answer": u"你好"}, id=u"你好")
self.assertEquals({"answer": u"你好"}, self.mc_client.get("test_index", doc_type="test_type", id=u"你好")["_source"])
self.mc_client.index("test_index", "test_type", {"answer": u("你好")}, id=u("你好"))
self.assertEquals({"answer": u("你好")}, self.mc_client.get("test_index", doc_type="test_type", id=u("你好"))["_source"])
def test_missing(self):
self.assertRaises(NotFoundError, self.mc_client.get, "test_index", doc_type="test_type", id=42)