def test_hash_improper_list(self): input = Map({ ImproperList([1, 2, 3], 1000): b"xxx" }) self.assertEquals( (input, ""), decode(encode(input)) ) self.assertEquals( input[ImproperList([1, 2, 3], 1000)], b"xxx")
def test_comparison(self): improper = ImproperList([1, 2, 3], "tail") self.assertEqual(improper, improper) self.assertEqual(improper, ImproperList([1, 2, 3], "tail")) self.assertNotEqual(improper, ImproperList([1, 2, 3], "tail2")) self.assertNotEqual(improper, ImproperList([1, 2], "tail"))
def test_improper_list(self): improper = ImproperList([1, 2, 3], "tail") self.assertEqual(ImproperList, type(improper)) self.assertEqual([1, 2, 3], list(improper)) self.assertEqual("tail", improper.tail) self.assertEqual("ImproperList([1, 2, 3], 'tail')", repr(improper))
def test_encode_improper_list(self): self.assertEqual("\x83l\0\0\0\1h\0h\0", encode(ImproperList([()], ()))) self.assertEqual("\x83l\0\0\0\1a\0a\1", encode(ImproperList([0], 1)))
def test_immutable(self): m = ImproperList([1, 2, 3], 100) self.assertRaises(MutationError, m.append, 1) self.assertRaises(MutationError, setattr, m, "x", 1)