将TestSuite添加到扭曲的程序中

时间:2014-10-09 21:41:19

标签: python eclipse twisted

我正在尝试为我正在进行的http://github.com/DBrianKimmel/Pyhouse家庭自动化系统添加更多测试。我使用Eclipse(Luna)进行开发和测试。有相当数量的Python包,每个包含许多模块。一些包嵌套3或4深。我现在正试图让测试从一个模块开始,而不是一个模块。我已经阅读了python和扭曲的文档,但我无法让集合测试在Eclipse中工作。我很感激有关如何使这项工作的任何指示或参考。

澄清

Eclipse具有允许运行单元测试的功能。我完全在Eclipse中开发和测试,通常我在工作的地方打开4个或更多选项卡。一个是我正在处理的模块,另一个是该模块的单元测试。我经常需要对开发模块的引用,因此它们处于打开的选项卡中。我认为Eclipse对我的开发至关重要,因此最终的解决方案必须在Eclipse中运行。

我尝试了很多方法,最新的就是这个。这是模块测试:

# Import system type stuff
from twisted.trial import unittest

# Import PyMh files and modules.
from Modules.Families.Insteon import Insteon_utils

ADDR_DR_SLAVE_MSG = bytearray(b'\x16\xc9\xd0')
ADDR_DR_SLAVE_INT = 1493456
ADDR_NOOK_MSG = bytearray(b'\x17\xc2\x72')
ADDR_NOOK_INT = 1557106

MSG_50 = bytearray(b'\x02\x50\x16\xc9\xd0\x1b\x47\x81\x27\x09\x00')
MSG_62 = bytearray(b'\x02\x62\x17\xc2\x72\x0f\x19\x00\x06')

class C01_Conversions(unittest.TestCase):

    def setUp(self):
        self.inst = Insteon_utils
        pass

    def test_01_message2int(self):
        result = self.inst.message2int(MSG_50, 2)
        self.assertEqual(result, ADDR_DR_SLAVE_INT)
        result = self.inst.message2int(MSG_62, 2)
        self.assertEqual(result, ADDR_NOOK_INT)

    def test_02_int2message(self):
        l_msg = MSG_50
        result = self.inst.int2message(ADDR_DR_SLAVE_INT, l_msg, 2)
        self.assertEqual(result[2:5], ADDR_DR_SLAVE_MSG)
        l_msg = MSG_62
        result = self.inst.int2message(ADDR_NOOK_INT, l_msg, 2)
        self.assertEqual(result[2:5], ADDR_NOOK_MSG)

def suite():
    l_suite = unittest.TestSuite()
    l_suite.addTest(C01_Conversions('test_01_message2int', 'test_02_int2message'))
    return l_suite

这是聚合模块:

# Import system type stuff
from twisted.trial import unittest, reporter, runner

# Future modules that need importing
# Import PyMh files and modules.
# from Modules.Families.Insteon.test import \
#        test_Insteon_decoder, test_Insteon_device, test_Insteon_PLM, \
#        test_Insteon_utils, \
#        test_Insteon_xml
from Modules.Families.Insteon import test as I_test


class C99_Family(unittest.TestCase):

    def setUp(self):
        self.m_test = runner.TestLoader()

    def test_9999_Insteon(self):
        l_package = runner.TestLoader().loadPackage(I_test)
        l_ret = reporter.Reporter()
        l_package.run(l_ret)
        l_ret.done()
        print('9999 Insteon', l_ret)
        l_ret.printErrors()

0 个答案:

没有答案