跳转到主要内容

自动在临时目录中设置Cassandra实例,并在测试后销毁它

项目描述

testing.cassandra 自动在临时目录中设置Cassandra实例,并在测试后销毁它

https://travis-ci.org/tk0miya/testing.cassandra.svg?branch=master https://coveralls.io/repos/tk0miya/testing.cassandra/badge.png?branch=master https://codeclimate.com/github/tk0miya/testing.cassandra/badges/gpa.svg

安装

使用easy_install(或pip)

$ easy_install testing.cassandra

并且 testing.cassandra 需要 Cassandra 服务器。

用法

使用 testing.cassandra.Cassandra 创建 Cassandra 实例

import pycassa
import testing.cassandra

# Launch new Cassandra server
with testing.cassandra.Cassandra as cassandra:
    conn = pycassa.pool.ConnectionPool('test', cassandra.server_list())
    #
    # do any tests using Cassandra...
    #

# Cassandra server is terminated here

testing.cassandra 会自动在 /usr/local/ 中搜索 Cassandra 文件。如果您将 Cassandra 安装到其他目录,请设置 cassandra_home 关键字

# uses a copy of specified data directory of Cassandra.
cassandra = testing.cassandra.Cassandra(copy_data_from='/path/to/your/database')

testing.cassandra.Cassandra 在实例化时执行 cassandra。在删除 Cassandra 对象时,它会终止 Cassandra 实例并删除临时目录。

如果您想要包含列族和任何应用程序固定件的数据库,请使用 copy_data_from 关键字

# uses a copy of specified data directory of Cassandra.
cassandra = testing.cassandra.Cassandra(copy_data_from='/path/to/your/database')

您可以使用 cassandra_yaml 关键字指定 Cassandra 的参数

# boot Cassandra server listens on 12345 port
cassandra = testing.cassandra.Cassandra(cassandra_yaml={'rpc_port': 12345})

例如,您可以在 setUp() 方法上为每个测试用例设置新的 Cassandra 服务器

import unittest
import testing.cassandra

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.cassandra = testing.cassandra.Cassandra()

    def tearDown(self):
        self.cassandra.stop()

要求

  • Cassandra 1.1, 1.2, 2.0, 2.1, 2.2

  • Python 2.6, 2.7

  • pycassa

  • PyYAML

许可

Apache License 2.0

历史

1.2.0 (2016-02-03)

  • 添加到服务器调用超时

  • 支持Homebrew

  • 支持Cassandra 2.x

  • 使用 $CASSANDRA_HOME 指定搜索 Cassandra 主目录

  • 依赖 testing.common.database

1.1.4 (2015-04-06)

  • 修复错误

    • 在析构函数中不要调用 os.getpid()(如果不需要的话)

    • 使用绝对路径指定 which 命令

1.1.3 (2014-06-19)

  • 在终止 Cassandra 时添加超时

  • 修复错误

1.1.2 (2014-06-11)

  • 修复在 py3 中捕获 SIGINT 时引发 ImportError 的问题

1.1.1 (2013-12-06)

  • 支持 Cassandra 2.0.x

  • 修复 Cassandra#stop() 导致 OSError(在对象析构时)的问题

1.1.0 (2013-12-06)

  • 支持Cassandra 1.2.x

  • 支持Python 2.6

  • 添加cassandra.skipIfNotInstalled装饰器

  • 更改行为:Cassandra#stop() 清理工作目录

  • 修复如果Cassandra未启动则不删除工作目录的问题

1.0.0 (2013-10-17)

  • 第一个版本

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

testing.cassandra-1.2.0.tar.gz (9.0 kB 查看哈希值)

上传时间

构建分发

testing.cassandra-1.2.0-py2.py3-none-any.whl (7.9 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持