Skip to content

Commit f4d3601

Browse files
committed
Mention and test use of slices
1 parent 91e7563 commit f4d3601

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ Basics
4141
# the key is split on '.'s and works on dictionaries
4242
del store['a_dictionary.dict-list']
4343
store['a_dictionary.new_value'] = "old value"
44+
# you can also use the syntactic sugar for tuple keys (explicit lists work too)
4445
assert store['a_dictionary', 'new_value'] == "old value"
45-
assert store['a_list', 1] == 2
46+
# you can traverse lists too
47+
assert store['a_list', -1] == 3
48+
# you can use slices in lists
49+
assert len(store['a_list', 1:]) == 2
4650
4751
# deep copies are made when assigning values
4852
my_list = ['fun']

jsonstore/tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,13 @@ def test_nested_dict_helper(self):
170170
def test_nested_getitem(self):
171171
self.store["list"] = [
172172
{
173-
"key": [None, "value"]
173+
"key": [None, "value", "last"]
174174
}
175175
]
176176
assert self.store["list", 0, "key", 1] == "value"
177-
assert self.store[["list", 0, "key", 1]] == "value"
177+
assert self.store[["list", 0, "key", -1]] == "last"
178178
self.assertRaises(TypeError, self._getitem("list.0.key.1"))
179+
assert len(self.store["list", 0, "key", 1:]) == 2
179180

180181
def test_del(self):
181182
self.store.key = None

0 commit comments

Comments
 (0)