我正在尝试编写一种方法的单元测试用例,该方法返回一个整数,该整数指示节点列表中的第一个元素和最后一个元素。当我运行它时,使用伪数据,测试失败,但是值相同,数据类型也是如此。我想念什么?
原始方法
create table myTable as select distinct AtypeId
,cast(from_unixtime(t.timestamp) as date) as date
,t.id
,t.marketid
from File1 LATERAL VIEW explode(eventlist) exploded_table as t
order by AtypeId,date;
create table myTable2 as select distinct AtypeId
,date
,C
,id
,marketid
from myTable
inner join File2
on oldID=id;
测试方法
def foo(transitions):
sources = set(transitions["from"])
destinations = set(transitions["to"])
# Find Start
# <Code to Find Start>
# Find End
end = destinations - sources
if bool(end):
end = list(end)
else:
end = list(destinations)
end.sort(reverse=True)
end = end[0]
return start, end
输出:
def test_foo_end(self):
dummy_end = 4
dummy_transitions = pd.read_csv("TestData/Transitions.csv", index_col=0)
test_end = foo(dummy_transitions)
print(type(dummy_end))
print(type(test_end))
self.assertEqual(self, test_end, dummy_end)
答案 0 :(得分:1)
self.assertEqual(self, test_end, dummy_end)
是错误的。使用
self.assertEqual(test_end, dummy_end, "some descriptive message")
否则,您最终将self
与test_end
进行比较,而后者始终为假。
您得到的输出也准确地说明了这一点:
AssertionError: <__main__.ModelProcessorTests
testMethod=test_find_boundaries_end> != 4 : 4
显示“ AssertionError”,然后使用{p>来打印a != b: c
a
是冗长的词条<__main__.ModelProcessorTests testMethod=test_find_boundaries_end>
(原为self
),b
为4
(原为test_end
)和c
是您给出的消息(dummy_end
的值为4
)。