From e8ea29496401bc618c96339d43ae5480abb52851 Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Sun, 5 Mar 2017 18:12:01 -0500 Subject: [PATCH] test negative indexes (closes #1119) --- tests/fields/fields.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/fields/fields.py b/tests/fields/fields.py index ed7baa2b..8e0da410 100644 --- a/tests/fields/fields.py +++ b/tests/fields/fields.py @@ -1173,6 +1173,14 @@ class FieldTest(MongoDBTestCase): post.reload() self.assertEqual(post.info, ['0', '1', '2', '3', 'a', '5']) + # __setitem__(index, value) with a negative index + reset_post() + post.info[-2] = 'a' + self.assertEqual(post.info, ['0', '1', '2', '3', 'a', '5']) + post.save() + post.reload() + self.assertEqual(post.info, ['0', '1', '2', '3', 'a', '5']) + # '__setitem__(slice(i, j), listB)' # aka 'listA[i:j] = listB' # aka 'setitem(listA, slice(i, j), listB)' @@ -1183,6 +1191,16 @@ class FieldTest(MongoDBTestCase): post.reload() self.assertEqual(post.info, ['0', 'h', 'e', 'l', 'l', 'o', '3', '4', '5']) + # '__setitem__(slice(i, j), listB)' with negative i and j + reset_post() + post.info[-5:-3] = ['h', 'e', 'l', 'l', 'o'] + self.assertEqual(post.info, ['0', 'h', 'e', 'l', 'l', 'o', '3', '4', '5']) + post.save() + post.reload() + self.assertEqual(post.info, ['0', 'h', 'e', 'l', 'l', 'o', '3', '4', '5']) + + # negative + # 'append' reset_post() post.info.append('h')