方便在数据管道内测试数据的库。结果被推送到某种类型的消息队列中,供应用程序、持久性等使用。

dtest-framework的Python项目详细描述


dtest

CircleCIRequirements Status

方便在数据管道内测试数据的库。结果被推送到某种类型的消息队列中,供应用程序、持久性等使用。

支持的消息队列/流媒体平台

  • [X]拉比特MQ
  • []MQTT
  • []redis
  • []卡夫卡
  • []动觉

安装

pip3 install dtest-framework

单元测试

使用pytest设置测试

使用pip3 install -U pytest

安装pytest

使用根目录中的pytest运行测试。

圆ci

有一个.circleci/config.yml文件将针对python 3.6执行构建和单元测试。

快速启动

from dtest.dtest import Dtest
from hamcrest import *


# If publishing to a RabbitMQ queue, specify 'queue' \
# If publishing to a key-value store, specify 'kv-store' \
# Or specify both

connectionConfig = {
    "queue": {
        "host": "localhost",
        "username": "guest",
        "password": "guest",
        "exchange": "test.dtest",
        "exchange_type": "fanout"
    },
    "kv-store": {
        "api_url": "localhost:8080/api/",
        "retrieve_path": "getKeyValue/",
        "publish_path": "postKeyValue/"
    } 
}
metadata = {
    "description": "This is a test of the assertCondition",
    "topic": "test.dtest",
    "ruleSet": "Testing some random data",
    "dataSet": "random_data_set_123912731.csv"
}

dt = Dtest(connectionConfig, metadata)

dsQubert = [0,1]

dt.assert_that(dsQubert, has_length(2))
// True

dt.publish()
// Publishes test suite to MQ server


////////////////////////////////////////
// Store value in KV store for later use
dt.publishKeyValue('some-descriptor-dsQubert-length', len(dqQubert))

// Retrieve value from KV store to compare other files against
avg_count = dt.retrieveKeyValue('some-descriptor-dsQubert-length')

dt.assert_that(dsQubert, has_length(avg_count))

自定义处理程序

可以创建自定义消息队列和键值存储处理程序。根据需要实现从dtest.handler.MqHandlerdtest.handler.KvHandler继承的类。


class MqHandler:

    @classmethod
    def version(self): return "1.0"

    @abstractmethod
    def connect(self): raise NotImplementedError

    @abstractmethod
    def publishResults(self): raise NotImplementedError

    @abstractmethod
    def closeConnection(self): raise NotImplementedError


class KvHandler:

    @classmethod
    def version(self): return "1.0"

    @abstractmethod
    def retrieve(self): raise NotImplementedError

    @abstractmethod
    def publish(self): raise NotImplementedError

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
.net等效于Java的Swing TableModel?   java将具有相同标记的xml结构解组到不同的字段   JavaSpringDataGemFire:自定义过期示例   设计模式质疑java中工厂函数的使用   文本区域中的swing格式。JAVA   Java:IEEE双倍于IBM浮点   java解析微数据时,我得到的是空值   java如何配置Ebean生成SQLite代码   具有复合工厂或抽象工厂的java工厂   如何使用java中的POI在excel工作表中获取小计   Java中指向整数的指针   java每次都会得到一个新的随机数[Dice Simulator]   javalucene:多线程文档复制   Java不仅使用ArrayList,还创建它(泛型)