You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2015/09/11 18:13:56 UTC
[1/3] couchdb-mango git commit: Make testcases skip automatically
when no text service
Repository: couchdb-mango
Updated Branches:
refs/heads/master 1de64eabb -> 87faac11d
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/master
Commit: ba961dca9858f49e38e17590dc62f512b6630848
Parents: 1de64ea
Author: Tony Sun <to...@cloudant.com>
Authored: Wed Sep 9 00:12:41 2015 -0700
Committer: Tony Sun <to...@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")
[2/3] couchdb-mango git commit: Use hypothesis instead of random
values for num_string tests
Posted by to...@apache.org.
Use hypothesis instead of random values for num_string tests
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/2793b9f5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/2793b9f5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/2793b9f5
Branch: refs/heads/master
Commit: 2793b9f50561dd4d9a271ce66aad29d7bfbad942
Parents: ba961dc
Author: Tony Sun <to...@cloudant.com>
Authored: Wed Sep 9 15:10:21 2015 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Wed Sep 9 15:13:37 2015 -0700
----------------------------------------------------------------------
test/06-basic-text-test.py | 60 ++++++++++++++++++++++++++++-------------
test/README.md | 1 +
test/literal_gen.py | 49 ---------------------------------
test/num_string_docs.py | 49 ---------------------------------
4 files changed, 43 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2793b9f5/test/06-basic-text-test.py
----------------------------------------------------------------------
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index 4024042..53e9159 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -14,7 +14,10 @@ import json
import mango
import unittest
import user_docs
+import copy
import num_string_docs
+from hypothesis import given, assume
+import hypothesis.strategies as st
@unittest.skipIf(mango.has_text_service(), "text service exists")
class TextIndexCheckTests(mango.DbPerClass):
@@ -556,30 +559,51 @@ class ElemMatchTests(mango.FriendDocsTextTests):
# Test numeric strings for $text
@unittest.skipUnless(mango.has_text_service(), "requires text service")
-class NumStringTests(mango.NumStringDocsTextTests):
+class NumStringTests(mango.DbPerClass):
- def test_floating_point_val(self):
- float_point_string = num_string_docs.DOCS[2]["number_string"]
- q = {"$text": float_point_string}
- docs = self.db.find(q)
- assert len(docs) == 1
- assert docs[0]["number_string"] == float_point_string
-
- def test_hex_floating_point_val(self):
- hex_float_point_string = num_string_docs.DOCS[3]["number_string"]
- q = {"$text": hex_float_point_string}
- docs = self.db.find(q)
- assert len(docs) == 1
- assert docs[0]["number_string"] == hex_float_point_string
+ @classmethod
+ def setUpClass(klass):
+ super(NumStringTests, klass).setUpClass()
+ klass.db.recreate()
+ klass.db.create_text_index()
def test_nan_val(self):
+ doc = {"number_NaN": "NaN"}
+ self.db.save_doc(doc)
q = {"$text": "NaN"}
docs = self.db.find(q)
- assert len(docs) == 1
- assert docs[0]["number_string"] == "NaN"
+ print docs
+ assert docs[0]["number_NaN"] == "NaN"
def test_infinity_val(self):
+ doc = {"number_Infinity": "Infinity"}
+ self.db.save_doc(doc)
q = {"$text": "Infinity"}
docs = self.db.find(q)
- assert len(docs) == 1
- assert docs[0]["number_string"] == "Infinity"
+ assert docs[0]["number_Infinity"] == "Infinity"
+
+ @given(float_point_string=st.floats().map(str))
+ def test_floating_point_val(self,float_point_string):
+ assume(float_point_string!="nan")
+ doc = {"number_string": float_point_string}
+ self.db.save_doc(doc)
+ q = {"$text": float_point_string}
+ docs = self.db.find(q)
+ if len(docs) == 1:
+ assert docs[0]["number_string"] == float_point_string
+ if len(docs) == 2:
+ if docs[0]["number_string"] != float_point_string:
+ assert docs[1]["number_string"] == float_point_string
+
+ @given(f=st.floats())
+ def test_floating_point_val(self,f):
+ hex_float_point_string = f.hex()
+ doc = {"number_string": hex_float_point_string}
+ self.db.save_doc(doc)
+ q = {"$text": hex_float_point_string}
+ docs = self.db.find(q)
+ if len(docs) == 1:
+ assert docs[0]["number_string"] == hex_float_point_string
+ if len(docs) == 2:
+ if docs[0]["number_string"] != hex_float_point_string:
+ assert docs[1]["number_string"] == hex_float_point_string
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2793b9f5/test/README.md
----------------------------------------------------------------------
diff --git a/test/README.md b/test/README.md
index 17abf23..ed9e0fc 100644
--- a/test/README.md
+++ b/test/README.md
@@ -8,4 +8,5 @@ To run these, do this in the top level directory:
$ virtualenv venv
$ source venv/bin/activate
$ pip install nose requests
+ $ pip install hypothesis
$ nosetests
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2793b9f5/test/literal_gen.py
----------------------------------------------------------------------
diff --git a/test/literal_gen.py b/test/literal_gen.py
deleted file mode 100644
index cf46017..0000000
--- a/test/literal_gen.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-import random
-from string import digits, hexdigits
-
-def joiner(*items):
- return ''.join(item() for item in items)
-
-def roll(item, n1, n2=None):
- n2 = n2 or n1
- return lambda: ''.join(item() for _ in xrange(random.randint(n1, n2)))
-
-def rand(collection):
- return lambda: random.choice(collection)
-
-def floating_point_literal():
- return joiner(roll(rand(' '), 0, 2),
- roll(rand('+-'), 0, 1),
- roll(rand(digits), 2, 20),
- rand('.'),
- roll(rand(digits), 2, 20),
- roll(rand('eE'), 1, 1),
- roll(rand('+-'), 0, 1),
- roll(rand(digits), 2, 20),
- roll(rand('fF'), 0, 1),
- roll(rand(' '), 0, 2))
-
-def hex_floating_point_literal():
- return joiner(roll(rand(' '), 0, 2),
- rand('0'),
- roll(rand('xX'), 1, 1),
- roll(rand(hexdigits), 1, 6),
- rand('.'),
- roll(rand(hexdigits), 1, 7),
- roll(rand('pP'), 1, 1),
- roll(rand('+-'), 0, 1),
- roll(rand(digits), 1, 4),
- roll(rand('fFdD'), 0, 1),
- roll(rand(' '), 0, 2))
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2793b9f5/test/num_string_docs.py
----------------------------------------------------------------------
diff --git a/test/num_string_docs.py b/test/num_string_docs.py
deleted file mode 100644
index f900120..0000000
--- a/test/num_string_docs.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-import copy
-import literal_gen
-
-
-def setup(db, index_type="view"):
- db.recreate()
- DOCS[2]["number_string"] = literal_gen.floating_point_literal()
- DOCS[3]["number_string"] = literal_gen.hex_floating_point_literal()
- db.save_docs(copy.deepcopy(DOCS))
- if index_type == "view":
- add_view_indexes(db)
- elif index_type == "text":
- add_text_indexes(db)
-
-
-def add_text_indexes(db):
- db.create_text_index()
-
-
-DOCS = [
- {
- "_id": "55118b87283f8f2901c59663",
- "number_string": "NaN"
- },
- {
- "_id": "55118b873c98123d69bff407",
- "number_string": "Infinity"
- },
- {
- "_id": "55118b87b4e99951e6fbe5c4",
- "number_string": "filler"
- },
- {
- "_id": "55118b87bc21952536ef00da",
- "number_string": "filler"
- }
-]
\ No newline at end of file
[3/3] couchdb-mango git commit: Shorten tests
Posted by to...@apache.org.
Shorten tests
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/87faac11
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/87faac11
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/87faac11
Branch: refs/heads/master
Commit: 87faac11d7c5c0fd99d5d0eae4d6263ab965d694
Parents: 2793b9f
Author: Tony Sun <to...@cloudant.com>
Authored: Thu Sep 10 11:34:45 2015 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Fri Sep 11 09:14:54 2015 -0700
----------------------------------------------------------------------
.travis.yml | 2 +-
Makefile | 1 +
test/06-basic-text-test.py | 54 ++++++++++++-----------------------------
test/mango.py | 9 -------
4 files changed, 18 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/87faac11/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 04fdb33..2c6b2f0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,7 @@ before_install:
- cp -R ../src ./src/mango
- make
- cd ..
- - couchdb/dev/run -n 1 --with-admin-party-please &
+ - couchdb/dev/run -n 1 --admin=testuser:testpass &
- sleep 10
before_script:
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/87faac11/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 8c136c1..1b2a504 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,7 @@ test:
# target: pip-install - Installs requires Python packages
pip-install:
pip install nose requests
+ pip install hypothesis
.PHONY: venv
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/87faac11/test/06-basic-text-test.py
----------------------------------------------------------------------
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index 53e9159..28c495a 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -14,9 +14,8 @@ import json
import mango
import unittest
import user_docs
-import copy
-import num_string_docs
-from hypothesis import given, assume
+import math
+from hypothesis import given, assume, example
import hypothesis.strategies as st
@unittest.skipIf(mango.has_text_service(), "text service exists")
@@ -565,45 +564,24 @@ class NumStringTests(mango.DbPerClass):
def setUpClass(klass):
super(NumStringTests, klass).setUpClass()
klass.db.recreate()
- klass.db.create_text_index()
+ if mango.has_text_service():
+ klass.db.create_text_index()
- def test_nan_val(self):
- doc = {"number_NaN": "NaN"}
- self.db.save_doc(doc)
- q = {"$text": "NaN"}
- docs = self.db.find(q)
- print docs
- assert docs[0]["number_NaN"] == "NaN"
-
- def test_infinity_val(self):
- doc = {"number_Infinity": "Infinity"}
- self.db.save_doc(doc)
- q = {"$text": "Infinity"}
- docs = self.db.find(q)
- assert docs[0]["number_Infinity"] == "Infinity"
-
- @given(float_point_string=st.floats().map(str))
- def test_floating_point_val(self,float_point_string):
- assume(float_point_string!="nan")
- doc = {"number_string": float_point_string}
- self.db.save_doc(doc)
- q = {"$text": float_point_string}
- docs = self.db.find(q)
- if len(docs) == 1:
- assert docs[0]["number_string"] == float_point_string
- if len(docs) == 2:
- if docs[0]["number_string"] != float_point_string:
- assert docs[1]["number_string"] == float_point_string
+ # not available for python 2.7.x
+ def isFinite(num):
+ not (math.isinf(num) or math.isnan(num))
- @given(f=st.floats())
+ @given(f=st.floats().filter(isFinite).map(str)
+ | st.floats().map(lambda f: f.hex()))
+ @example('NaN')
+ @example('Infinity')
def test_floating_point_val(self,f):
- hex_float_point_string = f.hex()
- doc = {"number_string": hex_float_point_string}
+ doc = {"number_string": f}
self.db.save_doc(doc)
- q = {"$text": hex_float_point_string}
+ q = {"$text": f}
docs = self.db.find(q)
if len(docs) == 1:
- assert docs[0]["number_string"] == hex_float_point_string
+ assert docs[0]["number_string"] == f
if len(docs) == 2:
- if docs[0]["number_string"] != hex_float_point_string:
- assert docs[1]["number_string"] == hex_float_point_string
+ if docs[0]["number_string"] != f:
+ assert docs[1]["number_string"] == f
http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/87faac11/test/mango.py
----------------------------------------------------------------------
diff --git a/test/mango.py b/test/mango.py
index 0487557..5ca8367 100644
--- a/test/mango.py
+++ b/test/mango.py
@@ -21,7 +21,6 @@ import requests
import friend_docs
import user_docs
import limit_docs
-import num_string_docs
def random_db_name():
@@ -242,11 +241,3 @@ class LimitDocsTextTests(DbPerClass):
super(LimitDocsTextTests, klass).setUpClass()
if has_text_service():
limit_docs.setup(klass.db, index_type="text")
-
-class NumStringDocsTextTests(DbPerClass):
-
- @classmethod
- def setUpClass(klass):
- super(NumStringDocsTextTests, klass).setUpClass()
- if has_text_service():
- num_string_docs.setup(klass.db, index_type="text")