我正在尝试编写一个单元测试用例,下面是原始函数的部分代码:
def disk_space(something, otherthing):
"""
Comments
"""
dir_map = something['dir_map']
for dir, expected_free_gb in dir_map.items():
try:
result = os.statvfs(dir)
block_size = result.f_frsize
avail_blocks = result.f_bavail
giga = 1024 * 1024 * 1024
free_size = avail_blocks * block_size / giga
if free_size >= float(expected_free_gb):
print "No need to clear space"
else:
print "Clear some space"
单元测试功能:
@patch('os.statvfs', return_value=posix.statvfs_result(f_frsize=4096, f_bavail=2599495))
def test_disk_space(self, os_statvfs):
something
something
现在,如果我在posix.statvfs_result
数据类型中返回值,它会给出错误:
TypeError: Required argument 'sequence' (pos 1) not found
如果我给return_value=(f_frsize=4096, f_bavail=2599495)
它说:
str() is not having f_frsize.
使用下面的函数
这些值与下面的字段相对应,因此请相应地进行更改。另外,请注意,值应位于双大括号内
相关问题 更多 >
编程相关推荐