很抱歉再打扰你们,但我自己无法解决这个问题。 我需要用几个函数的输出进行单元测试。我的(简化)函数看起来像这样:
def myfunc1(input1,input2,input3):
# processing the inputs
...
# new values are then saved in dictionaries
mat = {'mat1': mat1, 'mat2': mat2, 'mat3': mat3}
kat = {'kat1': kat1, 'kat2': kat2, 'kat3': kat3}
# and are returned
return mat, kat
def myfunc2(input4,input5,input6):
# processing the inputs
...
# new values are then saved in dictionaries
tra = {'tra1': tra1, 'tra2': tra2, 'tra3': tra3}
lala = {'lala1': lala1, 'lala2': lala2, 'lala3': lala3}
# and are returned
return tra, lala
我现在如何测试以下内容?
编辑: 这将是我的单元测试脚本的第一种方法(:
import unittest
from funcscript import *
# my example
class myTests(unittest.TestCase):
# test whether the size of the first dimension of two dictionary elements are the same
def test_comparing(self):
self.assertEqual(**WHAT TO DO HERE?**,**AND HERE?**, msg ='')
if __name__ == "__main__":
unittest.main()
答案 0 :(得分:0)
mat.values()
作为尺寸
def test_func1_and_func2(self):
mat, kat = myfunc1(a, b, c)
tra, lala = myfunc2(e, f, g)
self.assertEqual(set(mat.values()), set(tra.values()))
self.assertEqual(set(kat.values()), set(lala.values()))