【发布时间】:2019-12-12 01:26:59
【问题描述】:
我正在介绍使用unittest 模块对我的python 数据管道进行单元测试。
数据类对象示例:
class IsAvailable(Object)
employee_id: int = Property()
start_time: str = Property()
单元测试用例:
class TestIsAvailable(TestCase):
def setUp(self):
self.employee = pd.read_json('employee_leave.json', orient='records')
self.isAvailable = IsAvailable()
self.isAvailable.id = self.employee['start_time'][0]
def test_is_available_all_day_001(self):
assert self.isAvailable.start_time == pd.NaT
测试结果:
self = <tests.test_nodes.TestIsAvailable testMethod=test_is_available_all_day_001>
def test_is_available_all_day_001(self):
"""test employee is available all day on specific day of the week"""
> assert self.isAvailable.start_time == pd.NaT
E AssertionError: assert NaT == NaT
E + where NaT = <IsAvailable id=1>.start_time
E + where <IsAvailable id=1> = <tests.test_nodes.TestIsAvailable testMethod=test_is_available_all_day_001>.isAvailable
E + and NaT = pd.NaT
您如何测试数据类型?
【问题讨论】:
-
pd.NaT不是数据类型。相反,它表示 datetime dtype 的缺失值。如果您想检查 pandas 数据框中的缺失值,请查看以下答案:stackoverflow.com/a/49435999/189418
标签: python unit-testing python-unittest