You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wo...@apache.org on 2017/09/27 23:45:56 UTC

[couchdb] branch master updated: fix tests to be compatible for both python2 and python3 (#839)

This is an automated email from the ASF dual-hosted git repository.

wohali pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 355f0fc  fix tests to be compatible for both python2 and python3 (#839)
355f0fc is described below

commit 355f0fc7b46c8c2d8d266517c9ebf6c11da0e7ea
Author: Tony Sun <to...@gmail.com>
AuthorDate: Wed Sep 27 16:45:54 2017 -0700

    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.
---
 src/mango/test/01-index-crud-test.py             | 21 ++++++++++-----------
 src/mango/test/02-basic-find-test.py             | 14 +++++++-------
 src/mango/test/05-index-selection-test.py        | 10 +++++-----
 src/mango/test/06-basic-text-test.py             |  3 ---
 src/mango/test/07-text-custom-field-list-test.py |  4 ++--
 src/mango/test/08-text-limit-test.py             |  6 ++----
 src/mango/test/09-text-sort-test.py              |  4 ++--
 src/mango/test/14-json-pagination.py             |  4 ++--
 src/mango/test/16-index-selectors.py             |  2 +-
 src/mango/test/mango.py                          |  2 +-
 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 6582020..617bfd5 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 699166e..a8725ff 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 ee0d604..1cc2103 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 7f5ce63..c02950c 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 50a5c05..a43e330 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 191a110..4bc87b4 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 ae36a6a..1c55572 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 ddac156..ea06e0a 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 cc83251..3ce659e 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 342d5fd..a275a23 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)
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].