Skip to content

Commit

Permalink
Fix #134: enforce contract that *args must be pairs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Sep 24, 2014
1 parent a077d7d commit 0e625da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def from_path(cls, *args, **kwargs):
:rtype: :class:`gcloud.datastore.key.Key`
:returns: a new `Key` instance
"""
if len(args) % 2:
raise ValueError('Must pass an even number of args.')

path = []
items = iter(args)

Expand Down
11 changes: 5 additions & 6 deletions gcloud/datastore/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ def test_from_path_empty(self):
self.assertEqual(key.path(), [{'kind': ''}])

def test_from_path_single_element(self):
# See https://github.com/GoogleCloudPlatform/gcloud-python/issues/134
key = self._getTargetClass().from_path('abc')
self.assertEqual(key.dataset(), None)
self.assertEqual(key.namespace(), None)
self.assertEqual(key.kind(), '') # XXX s.b. 'abc'?
self.assertEqual(key.path(), [{'kind': ''}]) # XXX s.b. 'abc'?
self.assertRaises(ValueError, self._getTargetClass().from_path, 'abc')

def test_from_path_three_elements(self):
self.assertRaises(ValueError, self._getTargetClass().from_path,
'abc', 'def', 'ghi')

def test_from_path_two_elements_second_string(self):
key = self._getTargetClass().from_path('abc', 'def')
Expand Down

0 comments on commit 0e625da

Please sign in to comment.