summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2017-09-27 16:45:54 -0700
committerJoan Touzet <wohali@users.noreply.github.com>2017-09-27 19:45:54 -0400
commit355f0fc7b46c8c2d8d266517c9ebf6c11da0e7ea (patch)
tree14c48ec8f5a3a71b474ea1cb9f6de33dd1c311c8
parentc07f3f5ced25491f975c7bc552a6ffd263a425fd (diff)
downloadcouchdb-355f0fc7b46c8c2d8d266517c9ebf6c11da0e7ea.tar.gz
fix tests to be compatible for both python2 and python3 (#839)
We change syntax issues that make the tests incompatible for python3 but also ensure that it still runs using python2.
-rw-r--r--src/mango/test/01-index-crud-test.py21
-rw-r--r--src/mango/test/02-basic-find-test.py14
-rw-r--r--src/mango/test/05-index-selection-test.py10
-rw-r--r--src/mango/test/06-basic-text-test.py3
-rw-r--r--src/mango/test/07-text-custom-field-list-test.py4
-rw-r--r--src/mango/test/08-text-limit-test.py6
-rw-r--r--src/mango/test/09-text-sort-test.py4
-rw-r--r--src/mango/test/14-json-pagination.py4
-rw-r--r--src/mango/test/16-index-selectors.py2
-rw-r--r--src/mango/test/mango.py2
10 files changed, 32 insertions, 38 deletions
diff --git a/src/mango/test/01-index-crud-test.py b/src/mango/test/01-index-crud-test.py
index 6582020f5..617bfd523 100644
--- a/src/mango/test/01-index-crud-test.py
+++ b/src/mango/test/01-index-crud-test.py
@@ -35,7 +35,7 @@ class IndexCrudTests(mango.DbPerClass):
for fields in bad_fields:
try:
self.db.create_index(fields)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad create index")
@@ -54,7 +54,7 @@ class IndexCrudTests(mango.DbPerClass):
for bt in bad_types:
try:
self.db.create_index(["foo"], idx_type=bt)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400, (bt, e.response.status_code)
else:
raise AssertionError("bad create index")
@@ -70,13 +70,13 @@ class IndexCrudTests(mango.DbPerClass):
for bn in bad_names:
try:
self.db.create_index(["foo"], name=bn)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad create index")
try:
self.db.create_index(["foo"], ddoc=bn)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad create index")
@@ -207,7 +207,7 @@ class IndexCrudTests(mango.DbPerClass):
# Missing design doc
try:
self.db.delete_index("this_is_not_a_design_doc_id", "foo")
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 404
else:
raise AssertionError("bad index delete")
@@ -220,7 +220,7 @@ class IndexCrudTests(mango.DbPerClass):
ddocid = idx["ddoc"].split("/")[-1]
try:
self.db.delete_index(ddocid, "this_is_not_an_index_name")
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 404
else:
raise AssertionError("bad index delete")
@@ -228,7 +228,7 @@ class IndexCrudTests(mango.DbPerClass):
# Bad view type
try:
self.db.delete_index(ddocid, idx["name"], idx_type="not_a_real_type")
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 404
else:
raise AssertionError("bad index delete")
@@ -244,7 +244,6 @@ class IndexCrudTests(mango.DbPerClass):
for idx in self.db.list_indexes():
if idx["name"] != "text_idx_01":
continue
- print idx["def"]
assert idx["def"]["fields"] == [
{"stringidx": "string"},
{"booleanidx": "boolean"}
@@ -270,7 +269,7 @@ class IndexCrudTests(mango.DbPerClass):
for fields in bad_fields:
try:
self.db.create_text_index(fields=fields)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad create text index")
@@ -310,10 +309,10 @@ class IndexCrudTests(mango.DbPerClass):
try:
self.db.list_indexes(skip=-1)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 500
try:
self.db.list_indexes(limit=0)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 500
diff --git a/src/mango/test/02-basic-find-test.py b/src/mango/test/02-basic-find-test.py
index 699166e28..a8725ffa8 100644
--- a/src/mango/test/02-basic-find-test.py
+++ b/src/mango/test/02-basic-find-test.py
@@ -30,7 +30,7 @@ class BasicFindTests(mango.UserDocsTests):
for bs in bad_selectors:
try:
self.db.find(bs)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
@@ -49,7 +49,7 @@ class BasicFindTests(mango.UserDocsTests):
for bl in bad_limits:
try:
self.db.find({"int":{"$gt":2}}, limit=bl)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
@@ -68,7 +68,7 @@ class BasicFindTests(mango.UserDocsTests):
for bs in bad_skips:
try:
self.db.find({"int":{"$gt":2}}, skip=bs)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
@@ -88,7 +88,7 @@ class BasicFindTests(mango.UserDocsTests):
for bs in bad_sorts:
try:
self.db.find({"int":{"$gt":2}}, sort=bs)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
@@ -108,7 +108,7 @@ class BasicFindTests(mango.UserDocsTests):
for bf in bad_fields:
try:
self.db.find({"int":{"$gt":2}}, fields=bf)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
@@ -126,7 +126,7 @@ class BasicFindTests(mango.UserDocsTests):
for br in bad_rs:
try:
self.db.find({"int":{"$gt":2}}, r=br)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
@@ -142,7 +142,7 @@ class BasicFindTests(mango.UserDocsTests):
for bc in bad_conflicts:
try:
self.db.find({"int":{"$gt":2}}, conflicts=bc)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad find")
diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py
index ee0d604c3..1cc210382 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -77,7 +77,7 @@ class IndexSelectionTests(mango.UserDocsTests):
def test_no_valid_sort_index(self):
try:
self.db.find({"_id": {"$gt": None}}, sort=["name"], return_raw=True)
- except Exception, e:
+ except Exception as e:
self.assertEqual(e.response.status_code, 400)
else:
raise AssertionError("bad find")
@@ -87,7 +87,7 @@ class IndexSelectionTests(mango.UserDocsTests):
ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f"
try:
self.db.find({}, use_index=ddocid)
- except Exception, e:
+ except Exception as e:
self.assertEqual(e.response.status_code, 400)
else:
raise AssertionError("bad find")
@@ -145,7 +145,7 @@ class IndexSelectionTests(mango.UserDocsTests):
}
try:
self.db.find(selector, use_index=ddocid)
- except Exception, e:
+ except Exception as e:
self.assertEqual(e.response.status_code, 400)
else:
raise AssertionError("did not reject bad use_index")
@@ -159,7 +159,7 @@ class IndexSelectionTests(mango.UserDocsTests):
}
try:
self.db.find(selector, use_index=ddocid, sort=[{"manager":"desc"}])
- except Exception, e:
+ except Exception as e:
self.assertEqual(e.response.status_code, 400)
else:
raise AssertionError("did not reject bad use_index")
@@ -250,7 +250,7 @@ class MultiTextIndexSelectionTests(mango.UserDocsTests):
def test_multi_text_index_is_error(self):
try:
self.db.find({"$text": "a query"}, explain=True)
- except Exception, e:
+ except Exception as e:
self.assertEqual(e.response.status_code, 400)
def test_use_index_works(self):
diff --git a/src/mango/test/06-basic-text-test.py b/src/mango/test/06-basic-text-test.py
index 7f5ce6345..c02950c46 100644
--- a/src/mango/test/06-basic-text-test.py
+++ b/src/mango/test/06-basic-text-test.py
@@ -64,7 +64,6 @@ class BasicTextTests(mango.UserDocsTextTests):
# Nested Level
docs = self.db.find({"favorites.0.2": "Python"})
- print len(docs)
assert len(docs) == 1
for d in docs:
assert "Python" in d["favorites"][0][2]
@@ -451,14 +450,12 @@ class ElemMatchTests(mango.FriendDocsTextTests):
}
}
docs = self.db.find(q)
- print len(docs)
assert len(docs) == 1
assert docs[0]["bestfriends"] == ["Wolverine", "Cyclops"]
q = {"results": {"$elemMatch": {"$gte": 80, "$lt": 85}}}
docs = self.db.find(q)
- print len(docs)
assert len(docs) == 1
assert docs[0]["results"] == [82, 85, 88]
diff --git a/src/mango/test/07-text-custom-field-list-test.py b/src/mango/test/07-text-custom-field-list-test.py
index 50a5c0522..a43e33003 100644
--- a/src/mango/test/07-text-custom-field-list-test.py
+++ b/src/mango/test/07-text-custom-field-list-test.py
@@ -56,7 +56,7 @@ class CustomFieldsTest(mango.UserDocsTextTests):
try:
self.db.find({"selector": {"$or": [{"favorites": "Ruby"},
{"favorites.0":"Ruby"}]}})
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
def test_in_with_array(self):
@@ -82,7 +82,7 @@ class CustomFieldsTest(mango.UserDocsTextTests):
vals = ["Random Garbage", 52, {"Versions": {"Alpha": "Beta"}}]
try:
self.db.find({"favorites": {"$in": vals}})
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
def test_nin_with_array(self):
diff --git a/src/mango/test/08-text-limit-test.py b/src/mango/test/08-text-limit-test.py
index 191a1108a..4bc87b4b9 100644
--- a/src/mango/test/08-text-limit-test.py
+++ b/src/mango/test/08-text-limit-test.py
@@ -47,7 +47,6 @@ class LimitTests(mango.LimitDocsTextTests):
def test_limit_field5(self):
q = {"age": {"$exists": True}}
docs = self.db.find(q, limit=250)
- print len(docs)
assert len(docs) == 75
for d in docs:
assert d["age"] < 100
@@ -78,7 +77,7 @@ class LimitTests(mango.LimitDocsTextTests):
q = {"$or": [{"user_id" : {"$lt" : 100}}, {"filtered_array.[]": 1}]}
try:
self.db.find(q, limit=-1)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("Should have thrown error for negative limit")
@@ -87,7 +86,7 @@ class LimitTests(mango.LimitDocsTextTests):
q = {"$or": [{"user_id" : {"$lt" : 100}}, {"filtered_array.[]": 1}]}
try:
self.db.find(q, skip=-1)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("Should have thrown error for negative skip")
@@ -102,7 +101,6 @@ class LimitTests(mango.LimitDocsTextTests):
def run_bookmark_check(self, size):
- print size
q = {"age": {"$gt": 0}}
seen_docs = set()
bm = None
diff --git a/src/mango/test/09-text-sort-test.py b/src/mango/test/09-text-sort-test.py
index ae36a6a33..1c5557227 100644
--- a/src/mango/test/09-text-sort-test.py
+++ b/src/mango/test/09-text-sort-test.py
@@ -43,7 +43,7 @@ class SortTests(mango.UserDocsTextTests):
q = {"email": {"$gt": None}}
try:
self.db.find(q, sort=["email"])
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("Should have thrown error for sort")
@@ -79,7 +79,7 @@ class SortTests(mango.UserDocsTextTests):
{"age": "34"}]}
try:
self.db.find(q, sort=["age"])
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("Should have thrown error for sort")
diff --git a/src/mango/test/14-json-pagination.py b/src/mango/test/14-json-pagination.py
index ddac15662..ea06e0a2a 100644
--- a/src/mango/test/14-json-pagination.py
+++ b/src/mango/test/14-json-pagination.py
@@ -159,7 +159,7 @@ class PaginateJsonDocs(mango.DbPerClass):
def test_bad_bookmark(self):
try:
self.db.find({"_id": {"$gt": 0}}, bookmark="bad-bookmark")
- except Exception, e:
+ except Exception as e:
resp = e.response.json()
assert resp["error"] == "invalid_bookmark"
assert resp["reason"] == "Invalid bookmark value: \"bad-bookmark\""
@@ -171,7 +171,7 @@ class PaginateJsonDocs(mango.DbPerClass):
bookmark = 'g2wAAAABaANkABFub2RlMUBjb3VjaGRiLm5ldGwAAAACYQBiP____2poAkY_8AAAAAAAAGEHag'
try:
self.db.find({"_id": {"$gt": 0}}, bookmark=bookmark)
- except Exception, e:
+ except Exception as e:
resp = e.response.json()
assert resp["error"] == "invalid_bookmark"
assert e.response.status_code == 400
diff --git a/src/mango/test/16-index-selectors.py b/src/mango/test/16-index-selectors.py
index cc83251c9..3ce659ecf 100644
--- a/src/mango/test/16-index-selectors.py
+++ b/src/mango/test/16-index-selectors.py
@@ -143,7 +143,7 @@ class IndexSelectorJson(mango.DbPerClass):
selector = {"location": {"$gte": "FRA"}}
try:
self.db.create_index(["location"], selector=selector)
- except Exception, e:
+ except Exception as e:
assert e.response.status_code == 400
else:
raise AssertionError("bad index creation")
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index 342d5fdc8..a275a23d0 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -44,7 +44,7 @@ class Database(object):
return "http://{}:{}/{}".format(self.host, self.port, self.dbname)
def path(self, parts):
- if isinstance(parts, (str, unicode)):
+ if isinstance(parts, ("".__class__, u"".__class__)):
parts = [parts]
return "/".join([self.url] + parts)