Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 比较两个看似相同的索引器时AssertEqual失败_Python_Unit Testing_Dynamic Arrays - Fatal编程技术网

Python 比较两个看似相同的索引器时AssertEqual失败

Python 比较两个看似相同的索引器时AssertEqual失败,python,unit-testing,dynamic-arrays,Python,Unit Testing,Dynamic Arrays,我有一个DynamicCarray课程,如下所示。(我只介绍了相关的方法,其余的可以从中查看) 当我运行测试时,我希望self.a.\uu getitem\uuuu0)抛出indexer('0超出范围'),我看不出断言失败的原因?唯一的区别是self.a.uuu getitem\uuuuu(0)将生成indexer({}超出范围)。format(0)),在我看来,它与indexer('0超出范围') 我试着运行下面的代码,看看字符串本身是否有任何不同 if '{} is out of b

我有一个DynamicCarray课程,如下所示。(我只介绍了相关的方法,其余的可以从中查看)

当我运行测试时,我希望
self.a.\uu getitem\uuuu0)
抛出
indexer('0超出范围')
,我看不出断言失败的原因?唯一的区别是
self.a.uuu getitem\uuuuu(0)
将生成
indexer({}超出范围)。format(0))
,在我看来,它与
indexer('0超出范围')

我试着运行下面的代码,看看字符串本身是否有任何不同

    if '{} is out of bounds'.format(0) == '0 is out of bounds':
        print('str equal')
    if '{} is out of bounds'.format(0).__len__() == '0 is out of bounds'.__len__():
        print('len equal')
    if IndexError('{} is out of bounds'.format(0)) == IndexError('0 is out of bounds'):
        print('IndexError equal')
并确认只有第三份if声明没有打印

下面是控制台的照片


提前谢谢。欢迎有建设性的批评和反馈。

例外情况不能与
assertEqual
相比

with self.assertRaises(IndexError, msg='0 is out of bounds'):
    self.a[0]
异常必须
raise
ed才能捕获。
您正在返回
索引器

raise IndexError('{} is out of bounds'.format(k))

IndexError()==IndexError()
在我的系统(Python 2.7)上返回False-我想在执行上没有
\uuuuuuueq\uuueq()
方法。您需要做一些类似于比较异常的字符串表示的事情。
with self.assertRaises(IndexError, msg='0 is out of bounds'):
    self.a[0]
raise IndexError('{} is out of bounds'.format(k))