[devtools] 'dict_values' object does not support indexing
fromsiximportPY2fromunittestimportTestCasefromtempfileimportNamedTemporaryFileimportos.pathasospfromlogilab.common.shellutilsimporttempdirfromcubicwebimportBinaryclassBinaryTC(TestCase):deftest_init(self):Binary()Binary(b'toto')Binary(bytearray(b'toto'))ifPY2:Binary(buffer('toto'))else:Binary(memoryview(b'toto'))withself.assertRaises((AssertionError,TypeError)):# TypeError is raised by BytesIO if python runs with -OBinary(u'toto')deftest_write(self):b=Binary()b.write(b'toto')b.write(bytearray(b'toto'))ifPY2:b.write(buffer('toto'))else:b.write(memoryview(b'toto'))withself.assertRaises((AssertionError,TypeError)):# TypeError is raised by BytesIO if python runs with -Ob.write(u'toto')deftest_gzpickle_roundtrip(self):old=(u'foo',b'bar',42,{})new=Binary.zpickle(old).unzpickle()self.assertEqual(old,new)self.assertIsNot(old,new)deftest_from_file_to_file(self):withtempdir()asdpath:fpath=osp.join(dpath,'binary.bin')withopen(fpath,'wb')asfobj:Binary(b'binaryblob').to_file(fobj)bobj=Binary.from_file(fpath)self.assertEqual(bobj.getvalue(),b'binaryblob')if__name__=='__main__':fromunittestimportmainmain()