Repository: couchdb-mango
Updated Branches:
  refs/heads/2787-modify-testcases [created] 2793b9f50


Make testcases skip automatically when no text service

COUCHDB-2787


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/ba961dca
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/ba961dca
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/ba961dca

Branch: refs/heads/2787-modify-testcases
Commit: ba961dca9858f49e38e17590dc62f512b6630848
Parents: 1de64ea
Author: Tony Sun <tony....@cloudant.com>
Authored: Wed Sep 9 00:12:41 2015 -0700
Committer: Tony Sun <tony....@cloudant.com>
Committed: Wed Sep 9 15:13:11 2015 -0700

----------------------------------------------------------------------
 test/01-index-crud-test.py             | 22 +++++++++++-----------
 test/04-key-tests.py                   |  7 +++----
 test/05-index-selection-test.py        | 16 +++++++++-------
 test/06-basic-text-test.py             | 20 ++++----------------
 test/06-text-default-field-test.py     | 15 +++------------
 test/07-text-custom-field-list-test.py |  5 +----
 test/08-text-limit-test.py             |  5 +----
 test/09-text-sort-test.py              |  5 +----
 test/mango.py                          | 24 ++++++++++++++++--------
 9 files changed, 49 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/01-index-crud-test.py
----------------------------------------------------------------------
diff --git a/test/01-index-crud-test.py b/test/01-index-crud-test.py
index 24aa99d..a44e149 100644
--- a/test/01-index-crud-test.py
+++ b/test/01-index-crud-test.py
@@ -16,11 +16,6 @@ import mango
 import unittest
 
 class IndexCrudTests(mango.DbPerClass):
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-        super(KeyTests, klass).setUpClass()
-
     def test_bad_fields(self):
         bad_fields = [
             None,
@@ -228,7 +223,7 @@ class IndexCrudTests(mango.DbPerClass):
         else:
             raise AssertionError("bad index delete")
 
-    @unittest.skip
+    @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_create_text_idx(self):
         fields = [
             {"name":"stringidx", "type" : "string"},
@@ -247,7 +242,7 @@ class IndexCrudTests(mango.DbPerClass):
             return
         raise AssertionError("index not created")
 
-    @unittest.skip
+    @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_create_bad_text_idx(self):
         bad_fields = [
             True,
@@ -282,12 +277,17 @@ class IndexCrudTests(mango.DbPerClass):
         ret = self.db.create_index(fields, name="idx_03")
         assert ret is True
 
+        skip_add = 0
+
+        if mango.has_text_service():
+            skip_add = 1
+
         assert len(self.db.list_indexes(limit=2)) == 2
-        assert len(self.db.list_indexes(limit=5,skip=4)) == 2
-        assert len(self.db.list_indexes(skip=5)) == 1
-        assert len(self.db.list_indexes(skip=6)) == 0
+        assert len(self.db.list_indexes(limit=5,skip=4)) == 2 + skip_add
+        assert len(self.db.list_indexes(skip=5)) == 1 + skip_add
+        assert len(self.db.list_indexes(skip=6)) == 0 + skip_add
         assert len(self.db.list_indexes(skip=100)) == 0
-        assert len(self.db.list_indexes(limit=10000000)) == 6
+        assert len(self.db.list_indexes(limit=10000000)) == 6 + skip_add
 
         try:
             self.db.list_indexes(skip=-1)

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/04-key-tests.py
----------------------------------------------------------------------
diff --git a/test/04-key-tests.py b/test/04-key-tests.py
index 5174d0b..4956d46 100644
--- a/test/04-key-tests.py
+++ b/test/04-key-tests.py
@@ -53,14 +53,15 @@ TEST_DOCS = [
 ]
 
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class KeyTests(mango.DbPerClass):
     @classmethod
     def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
         super(KeyTests, klass).setUpClass()
         klass.db.save_docs(TEST_DOCS, w=3)
         klass.db.create_index(["type"], ddoc="view")
-        klass.db.create_text_index(ddoc="text")
+        if mango.has_text_service():
+            klass.db.create_text_index(ddoc="text")
 
     def run_check(self, query, check, fields=None, indexes=None):
         if indexes is None:
@@ -125,7 +126,6 @@ class KeyTests(mango.DbPerClass):
         for query in queries:
             self.run_check(query, check, indexes=["text"])
 
-    @unittest.skip
     def test_escape_period(self):
         query = {"name\\.first" : "Kvothe"}
         def check(docs):
@@ -138,7 +138,6 @@ class KeyTests(mango.DbPerClass):
             assert len(docs) == 0
         self.run_check(query, check_empty, indexes=["text"])
 
-    @unittest.skip
     def test_object_period(self):
         query = {"name.first" : "Master Elodin"}
         def check(docs):

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/05-index-selection-test.py
----------------------------------------------------------------------
diff --git a/test/05-index-selection-test.py b/test/05-index-selection-test.py
index 4ded668..eecaf17 100644
--- a/test/05-index-selection-test.py
+++ b/test/05-index-selection-test.py
@@ -19,7 +19,8 @@ class IndexSelectionTests(mango.UserDocsTests):
     @classmethod
     def setUpClass(klass):
         super(IndexSelectionTests, klass).setUpClass()
-        # user_docs.add_text_indexes(klass.db, {})
+        if mango.has_text_service():
+            user_docs.add_text_indexes(klass.db, {})
 
     def test_basic(self):
         resp = self.db.find({"name.last": "A last name"}, explain=True)
@@ -32,7 +33,7 @@ class IndexSelectionTests(mango.UserDocsTests):
             }, explain=True)
         assert resp["index"]["type"] == "json"
 
-    @unittest.skip
+    @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_with_text(self):
         resp = self.db.find({
                 "$text" : "Stephanie",
@@ -41,12 +42,12 @@ class IndexSelectionTests(mango.UserDocsTests):
             }, explain=True)
         assert resp["index"]["type"] == "text"
 
-    @unittest.skip
+    @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_no_view_index(self):
         resp = self.db.find({"name.first": "Ohai!"}, explain=True)
         assert resp["index"]["type"] == "text"
 
-    @unittest.skip
+    @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_with_or(self):
         resp = self.db.find({
                 "$or": [
@@ -74,13 +75,14 @@ class IndexSelectionTests(mango.UserDocsTests):
         assert resp["index"]["ddoc"] == ddocid
 
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class MultiTextIndexSelectionTests(mango.UserDocsTests):
     @classmethod
     def setUpClass(klass):
-        raise unittest.SkipTest('text index service is not available')
         super(MultiTextIndexSelectionTests, klass).setUpClass()
-        klass.db.create_text_index(ddoc="foo", analyzer="keyword")
-        klass.db.create_text_index(ddoc="bar", analyzer="email")
+        if mango.has_text_service():
+            klass.db.create_text_index(ddoc="foo", analyzer="keyword")
+            klass.db.create_text_index(ddoc="bar", analyzer="email")
 
     def test_view_ok_with_multi_text(self):
         resp = self.db.find({"name.last": "A last name"}, explain=True)

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/06-basic-text-test.py
----------------------------------------------------------------------
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index 72a3918..4024042 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -16,26 +16,21 @@ import unittest
 import user_docs
 import num_string_docs
 
-
+@unittest.skipIf(mango.has_text_service(), "text service exists")
 class TextIndexCheckTests(mango.DbPerClass):
 
     def test_create_text_index(self):
         body = json.dumps({
             'index': {
-                'fields': 'test'
             },
             'type': 'text'
         })
         resp = self.db.sess.post(self.db.path("_index"), data=body)
         assert resp.status_code == 503, resp
 
-
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class BasicTextTests(mango.UserDocsTextTests):
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-
     def test_simple(self):
         docs = self.db.find({"$text": "Stephanie"})
         assert len(docs) == 1
@@ -428,13 +423,9 @@ class BasicTextTests(mango.UserDocsTextTests):
 
     # test lucene syntax in $text
 
-
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class ElemMatchTests(mango.FriendDocsTextTests):
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-
     def test_elem_match_non_object(self):
         q = {"bestfriends":{
                 "$elemMatch":
@@ -564,12 +555,9 @@ class ElemMatchTests(mango.FriendDocsTextTests):
 
 
 # Test numeric strings for $text
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class NumStringTests(mango.NumStringDocsTextTests):
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-
     def test_floating_point_val(self):
         float_point_string = num_string_docs.DOCS[2]["number_string"]
         q = {"$text": float_point_string}

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/06-text-default-field-test.py
----------------------------------------------------------------------
diff --git a/test/06-text-default-field-test.py 
b/test/06-text-default-field-test.py
index f4aaf9a..3f86f0e 100644
--- a/test/06-text-default-field-test.py
+++ b/test/06-text-default-field-test.py
@@ -14,14 +14,11 @@ import mango
 import unittest
 
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class NoDefaultFieldTest(mango.UserDocsTextTests):
 
     DEFAULT_FIELD = False
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-
     def test_basic(self):
         docs = self.db.find({"$text": "Ramona"})
         # Or should this throw an error?
@@ -33,6 +30,7 @@ class NoDefaultFieldTest(mango.UserDocsTextTests):
         assert docs[0]["user_id"] == 9
 
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class NoDefaultFieldWithAnalyzer(mango.UserDocsTextTests):
 
     DEFAULT_FIELD = {
@@ -40,10 +38,6 @@ class NoDefaultFieldWithAnalyzer(mango.UserDocsTextTests):
         "analyzer": "keyword"
     }
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text not supported')
-
     def test_basic(self):
         docs = self.db.find({"$text": "Ramona"})
         assert len(docs) == 0
@@ -54,6 +48,7 @@ class NoDefaultFieldWithAnalyzer(mango.UserDocsTextTests):
         assert docs[0]["user_id"] == 9
 
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class DefaultFieldWithCustomAnalyzer(mango.UserDocsTextTests):
 
     DEFAULT_FIELD = {
@@ -61,10 +56,6 @@ class 
DefaultFieldWithCustomAnalyzer(mango.UserDocsTextTests):
         "analyzer": "keyword"
     }
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text not supported')
-
     def test_basic(self):
         docs = self.db.find({"$text": "Ramona"})
         assert len(docs) == 1

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/07-text-custom-field-list-test.py
----------------------------------------------------------------------
diff --git a/test/07-text-custom-field-list-test.py 
b/test/07-text-custom-field-list-test.py
index f060d79..f299ef7 100644
--- a/test/07-text-custom-field-list-test.py
+++ b/test/07-text-custom-field-list-test.py
@@ -14,12 +14,9 @@ import mango
 import unittest
 
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class CustomFieldsTest(mango.UserDocsTextTests):
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-
     FIELDS = [
         {"name": "favorites.[]", "type": "string"},
         {"name": "manager", "type": "boolean"},

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/08-text-limit-test.py
----------------------------------------------------------------------
diff --git a/test/08-text-limit-test.py b/test/08-text-limit-test.py
index 36bf4a9..191a110 100644
--- a/test/08-text-limit-test.py
+++ b/test/08-text-limit-test.py
@@ -14,12 +14,9 @@ import mango
 import limit_docs
 import unittest
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class LimitTests(mango.LimitDocsTextTests):
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service not available')
-
     def test_limit_field(self):
         q = {"$or": [{"user_id" : {"$lt" : 10}}, {"filtered_array.[]": 1}]}
         docs = self.db.find(q, limit=10)

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/09-text-sort-test.py
----------------------------------------------------------------------
diff --git a/test/09-text-sort-test.py b/test/09-text-sort-test.py
index 7bdf54a..ae36a6a 100644
--- a/test/09-text-sort-test.py
+++ b/test/09-text-sort-test.py
@@ -13,12 +13,9 @@
 import mango
 import unittest
 
+@unittest.skipUnless(mango.has_text_service(), "requires text service")
 class SortTests(mango.UserDocsTextTests):
 
-    @classmethod
-    def setUpClass(klass):
-        raise unittest.SkipTest('text index service is not available')
-
     def test_number_sort(self):
         q = {"age": {"$gt": 0}}
         docs = self.db.find(q, sort=["age:number"])

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/ba961dca/test/mango.py
----------------------------------------------------------------------
diff --git a/test/mango.py b/test/mango.py
index fa7d52c..0487557 100644
--- a/test/mango.py
+++ b/test/mango.py
@@ -14,6 +14,7 @@ import json
 import time
 import unittest
 import uuid
+import os
 
 import requests
 
@@ -26,6 +27,9 @@ import num_string_docs
 def random_db_name():
     return "mango_test_" + uuid.uuid4().hex
 
+def has_text_service():
+    return os.path.isfile(os.getcwd() + "/../src/mango_cursor.erl")
+
 
 class Database(object):
     def __init__(self, host, port, dbname, auth=None):
@@ -214,11 +218,12 @@ class UserDocsTextTests(DbPerClass):
     @classmethod
     def setUpClass(klass):
         super(UserDocsTextTests, klass).setUpClass()
-        user_docs.setup(
-                klass.db,
-                index_type="text",
-                default_field=klass.DEFAULT_FIELD,
-                fields=klass.FIELDS
+        if has_text_service():
+            user_docs.setup(
+                    klass.db,
+                    index_type="text",
+                    default_field=klass.DEFAULT_FIELD,
+                    fields=klass.FIELDS
             )
 
 
@@ -227,18 +232,21 @@ class FriendDocsTextTests(DbPerClass):
     @classmethod
     def setUpClass(klass):
         super(FriendDocsTextTests, klass).setUpClass()
-        friend_docs.setup(klass.db, index_type="text")
+        if has_text_service():
+            friend_docs.setup(klass.db, index_type="text")
 
 class LimitDocsTextTests(DbPerClass):
 
     @classmethod
     def setUpClass(klass):
         super(LimitDocsTextTests, klass).setUpClass()
-        limit_docs.setup(klass.db, index_type="text")
+        if has_text_service():
+            limit_docs.setup(klass.db, index_type="text")
 
 class NumStringDocsTextTests(DbPerClass):
 
     @classmethod
     def setUpClass(klass):
         super(NumStringDocsTextTests, klass).setUpClass()
-        num_string_docs.setup(klass.db, index_type="text")
+        if has_text_service():
+            num_string_docs.setup(klass.db, index_type="text")

Reply via email to