Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #134: document / enforce Key.from_path contract #185

Merged
merged 2 commits into from
Sep 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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