Skip to content

Commit d6051d4

Browse files
committed
Up test coverage + fix exceptions
1 parent 32b72c2 commit d6051d4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

jsonstore/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __get_obj(self, full_path):
136136
path.append(step)
137137
try:
138138
obj = obj[step]
139-
except AttributeError:
139+
except KeyError:
140140
raise KeyError('.'.join(path))
141141
return obj
142142

@@ -151,7 +151,7 @@ def __setitem__(self, name, value):
151151

152152
def __getitem__(self, key):
153153
obj = self.__get_obj(key)
154-
if obj is self:
154+
if obj is self._data:
155155
raise KeyError
156156
return deepcopy(obj)
157157

jsonstore/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ def test_has_values(self):
109109

110110
self.assertFalse('foo' in self.store)
111111

112+
def test_empty_key(self):
113+
with self.assertRaises(KeyError):
114+
self.store['']
115+
116+
def test_empty_store(self):
117+
store_file = mktemp()
118+
with open(store_file, 'wb') as f:
119+
f.write(b"")
120+
JsonStore(f.name)
121+
112122
def test_assign_cycle(self):
113123
test_list = []
114124
test_dict = {}

0 commit comments

Comments
 (0)