当前位置: 首页>>代码示例>>Python>>正文


Python version.at_least函数代码示例

本文整理汇总了Python中version.at_least函数的典型用法代码示例。如果您正苦于以下问题:Python at_least函数的具体用法?Python at_least怎么用?Python at_least使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了at_least函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_map_reduce

    def test_map_reduce(self):
        if not version.at_least(self.db.connection, (1, 1, 1)):
            raise SkipTest()

        db = self.db
        db.drop_collection("test")

        db.test.insert({"id": 1, "tags": ["dog", "cat"]})
        db.test.insert({"id": 2, "tags": ["cat"]})
        db.test.insert({"id": 3, "tags": ["mouse", "cat", "dog"]})
        db.test.insert({"id": 4, "tags": []})

        map = Code("function () {" "  this.tags.forEach(function(z) {" "    emit(z, 1);" "  });" "}")
        reduce = Code(
            "function (key, values) {"
            "  var total = 0;"
            "  for (var i = 0; i < values.length; i++) {"
            "    total += values[i];"
            "  }"
            "  return total;"
            "}"
        )
        result = db.test.map_reduce(map, reduce)
        self.assertEqual(3, result.find_one({"_id": "cat"})["value"])
        self.assertEqual(2, result.find_one({"_id": "dog"})["value"])
        self.assertEqual(1, result.find_one({"_id": "mouse"})["value"])

        full_result = db.test.map_reduce(map, reduce, full_response=True)
        self.assertEqual(6, full_result["counts"]["emit"])

        result = db.test.map_reduce(map, reduce, limit=2)
        self.assertEqual(2, result.find_one({"_id": "cat"})["value"])
        self.assertEqual(1, result.find_one({"_id": "dog"})["value"])
        self.assertEqual(None, result.find_one({"_id": "mouse"}))
开发者ID:hmarr,项目名称:mongo-python-driver,代码行数:34,代码来源:test_collection.py

示例2: test_distinct

    def test_distinct(self):
        if not version.at_least(self.db.connection(), (1, 1, 3, 1)):
            raise SkipTest()

        self.db.drop_collection("test")

        self.db.test.save({"a": 1})
        self.db.test.save({"a": 2})
        self.db.test.save({"a": 2})
        self.db.test.save({"a": 2})
        self.db.test.save({"a": 3})

        distinct = self.db.test.find({"a": {"$lt": 3}}).distinct("a")
        distinct.sort()

        self.assertEqual([1, 2], distinct)

        self.db.drop_collection("test")

        self.db.test.save({"a": {"b": "a"}, "c": 12})
        self.db.test.save({"a": {"b": "b"}, "c": 8})
        self.db.test.save({"a": {"b": "c"}, "c": 12})
        self.db.test.save({"a": {"b": "c"}, "c": 8})

        distinct = self.db.test.find({"c": 8}).distinct("a.b")
        distinct.sort()

        self.assertEqual(["b", "c"], distinct)
开发者ID:virtix,项目名称:mongo-python-driver,代码行数:28,代码来源:test_cursor.py

示例3: test_group_with_scope

    def test_group_with_scope(self):
        db = self.db
        db.drop_collection("test")
        db.test.save({"a": 1})
        db.test.save({"b": 1})

        reduce_function = "function (obj, prev) { prev.count += inc_value; }"

        self.assertEqual(2, db.test.group([], {}, {"count": 0},
                                          Code(reduce_function,
                                               {"inc_value": 1}))[0]['count'])
        self.assertEqual(4, db.test.group([], {}, {"count": 0},
                                          Code(reduce_function,
                                               {"inc_value": 2}))[0]['count'])

        self.assertEqual(1, db.test.group([], {}, {"count": 0},
                                          Code(reduce_function,
                                               {"inc_value": 0.5}))[0]['count'])

        if version.at_least(db.connection, (1, 1)):
            self.assertEqual(2, db.test.group([], {}, {"count": 0},
                                              Code(reduce_function,
                                                   {"inc_value": 1}),
                                              command=True)[0]['count'])

            self.assertEqual(4, db.test.group([], {}, {"count": 0},
                                              Code(reduce_function,
                                                   {"inc_value": 2}),
                                              command=True)[0]['count'])

            self.assertEqual(1, db.test.group([], {}, {"count": 0},
                                              Code(reduce_function,
                                                   {"inc_value": 0.5}),
                                              command=True)[0]['count'])
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:34,代码来源:test_collection.py

示例4: test_count_with_fields

    def test_count_with_fields(self):
        self.db.test.remove({})
        self.db.test.save({"x": 1})

        if not version.at_least(self.db.connection(), (1, 1, 3, -1)):
            for _ in self.db.test.find({}, ["a"]):
                self.fail()

            self.assertEqual(0, self.db.test.find({}, ["a"]).count())
        else:
            self.assertEqual(1, self.db.test.find({}, ["a"]).count())
开发者ID:virtix,项目名称:mongo-python-driver,代码行数:11,代码来源:test_cursor.py

示例5: test_max_scan

    def test_max_scan(self):
        if not version.at_least(self.db.connection, (1, 5, 1)):
            raise SkipTest()

        self.db.drop_collection("test")
        for _ in range(100):
            self.db.test.insert({})

        self.assertEqual(100, len(list(self.db.test.find())))
        self.assertEqual(50, len(list(self.db.test.find(max_scan=50))))
        self.assertEqual(50, len(list(self.db.test.find()
                                      .max_scan(90).max_scan(50))))
开发者ID:ixc,项目名称:mongo-python-driver,代码行数:12,代码来源:test_cursor.py

示例6: test_safe_remove

    def test_safe_remove(self):
        db = self.db
        db.drop_collection("test")
        db.create_collection("test", {"capped": True, "size": 1000})

        db.test.insert({"x": 1})
        self.assertEqual(1, db.test.count())

        db.test.remove({"x": 1})
        self.assertEqual(1, db.test.count())

        if version.at_least(db.connection, (1, 1, 3, -1)):
            self.assertRaises(OperationFailure, db.test.remove, {"x": 1}, safe=True)
        else:  # Just test that it doesn't blow up
            db.test.remove({"x": 1}, safe=True)
开发者ID:hmarr,项目名称:mongo-python-driver,代码行数:15,代码来源:test_collection.py

示例7: test_multi_update

    def test_multi_update(self):
        db = self.db
        if not version.at_least(db.connection, (1, 1, 3, -1)):
            raise SkipTest()

        db.drop_collection("test")

        db.test.save({"x": 4, "y": 3})
        db.test.save({"x": 5, "y": 5})
        db.test.save({"x": 4, "y": 4})

        db.test.update({"x": 4}, {"$set": {"y": 5}}, multi=True)

        self.assertEqual(3, db.test.count())
        for doc in db.test.find():
            self.assertEqual(5, doc["y"])
开发者ID:hmarr,项目名称:mongo-python-driver,代码行数:16,代码来源:test_collection.py

示例8: test_safe_update

    def test_safe_update(self):
        db = self.db
        v113minus = version.at_least(db.connection, (1, 1, 3, -1))

        db.drop_collection("test")
        db.test.create_index("x", unique=True)

        db.test.insert({"x": 5})
        id = db.test.insert({"x": 4})

        db.test.update({"_id": id}, {"$inc": {"x": 1}})
        if v113minus:
            self.assert_(db.error()["err"].startswith("E11001"))
        else:
            self.assert_(db.error()["err"].startswith("E12011"))

        self.assertRaises(OperationFailure, db.test.update, {"_id": id}, {"$inc": {"x": 1}}, safe=True)
开发者ID:hmarr,项目名称:mongo-python-driver,代码行数:17,代码来源:test_collection.py

示例9: test_duplicate_key_error

    def test_duplicate_key_error(self):
        db = self.db
        db.drop_collection("test")

        db.test.create_index("x", unique=True)

        db.test.insert({"_id": 1, "x": 1}, safe=True)
        db.test.insert({"_id": 2, "x": 2}, safe=True)

        expected_error = OperationFailure
        if version.at_least(db.connection, (1, 3)):
            expected_error = DuplicateKeyError

        self.assertRaises(expected_error,
                          db.test.insert, {"_id": 1}, safe=True)
        self.assertRaises(expected_error,
                          db.test.insert, {"x": 1}, safe=True)

        self.assertRaises(expected_error,
                          db.test.save, {"x": 2}, safe=True)
        self.assertRaises(expected_error,
                          db.test.update, {"x": 1}, {"$inc": {"x": 1}}, safe=True)
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:22,代码来源:test_collection.py

示例10: test_count_with_limit_and_skip

    def test_count_with_limit_and_skip(self):
        if not version.at_least(self.db.connection(), (1, 1, 4, -1)):
            raise SkipTest()

        def check_len(cursor, length):
            self.assertEqual(len(list(cursor)), cursor.count(True))
            self.assertEqual(length, cursor.count(True))

        self.db.drop_collection("test")
        for i in range(100):
            self.db.test.save({"i": i})

        check_len(self.db.test.find(), 100)

        check_len(self.db.test.find().limit(10), 10)
        check_len(self.db.test.find().limit(110), 100)

        check_len(self.db.test.find().skip(10), 90)
        check_len(self.db.test.find().skip(110), 0)

        check_len(self.db.test.find().limit(10).skip(10), 10)
        check_len(self.db.test.find()[10:20], 10)
        check_len(self.db.test.find().limit(10).skip(95), 5)
        check_len(self.db.test.find()[95:105], 5)
开发者ID:virtix,项目名称:mongo-python-driver,代码行数:24,代码来源:test_cursor.py

示例11: test_group

    def test_group(self):
        db = self.db
        db.drop_collection("test")

        def group_checker(args, expected, with_command=True):
            eval = db.test.group(*args)
            self.assertEqual(eval, expected)

            if with_command:
                cmd = db.test.group(*args, **{"command": True})
                self.assertEqual(cmd, expected)


        args = [[], {},
                {"count": 0},
                "function (obj, prev) { prev.count++; }"]
        expected = []
        group_checker(args, expected)

        db.test.save({"a": 2})
        db.test.save({"b": 5})
        db.test.save({"a": 1})

        args = [[], {},
                {"count": 0},
                "function (obj, prev) { prev.count++; }"]
        expected = [{'count': 3}]
        group_checker(args, expected)

        args = [[],
                {"a": {"$gt": 1}},
                {"count": 0},
                "function (obj, prev) { prev.count++; }"]
        expected = [{'count': 1}]
        group_checker(args, expected)

        db.test.save({"a": 2, "b": 3})

        args = [["a"], {},
                {"count": 0},
                "function (obj, prev) { prev.count++; }"]
        # NOTE maybe we can't count on this ordering being right
        expected = [{"a": 2, "count": 2},
                    {"a": None, "count": 1},
                    {"a": 1, "count": 1}]
        group_checker(args, expected)

        # modifying finalize
        args = [["a"], {},
                {"count": 0},
                "function (obj, prev) { prev.count++; }",
                "function(obj){obj.count++;}"]
        expected = [{"a": 2, "count": 3},
                    {"a": None, "count": 2},
                    {"a": 1, "count": 2}]
        group_checker(args, expected, with_command=version.at_least(db.connection(), (1, 1)))

        # returning finalize
        args = [["a"], {},
                {"count": 0},
                "function (obj, prev) { prev.count++; }",
                "function(obj){ return obj.count;}"]
        expected = [2, # a:2
                    1, # a:None
                    1] # a:1
        group_checker(args, expected, with_command=version.at_least(db.connection(), (1, 1)))

        self.assertRaises(OperationFailure, db.test.group, [], {}, {}, "5 ++ 5")
        self.assertRaises(OperationFailure, db.test.group, [], {}, {}, "5 ++ 5", command=True)
开发者ID:drg,项目名称:mongo-python-driver,代码行数:69,代码来源:test_collection.py


注:本文中的version.at_least函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。