Skip to content

Commit

Permalink
Tested setting categories with dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotsdl committed Mar 22, 2016
1 parent b5dfee4 commit 31c1134
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/datreant/core/limbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,18 @@ def __delitem__(self, category):
"""
self.remove(category)

def __eq__(self, other):
if isinstance(other, (Categories, dict)):
return dict(self) == dict(other)
else:
raise TypeError("Operands must be categories or dicts.")

def __req__(self, other):
if isinstance(other, (Categories, dict)):
return dict(self) == dict(other)
else:
raise TypeError("Operands must be categories or dicts.")

def __iter__(self):
return self._dict().__iter__()

Expand Down
23 changes: 23 additions & 0 deletions src/datreant/core/tests/test_treants.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,29 @@ def test_get_categories(self, treant):
assert treant.categories[{'leaves', 'bark'}] == {'leaves': 'many',
'bark': 'dark'}

def test_set_categories(self, treant, tmpdir):
a_dict = {'leaves': 'many', 'bark': 'dark'}

treant.categories = a_dict
assert treant.categories == a_dict

a_dict.update({'roots': 'shallow'})

assert treant.categories != a_dict
treant.categories = a_dict
assert a_dict == treant.categories

# test setting from other Treant's categories
with tmpdir.as_cwd():
s = dtr.Treant('sprout')

s.categories = {'shoes': False, 'shirt': False}

assert treant.categories != s.categories

treant.categories = s.categories
assert treant.categories == s.categories


class TestGroup(TestTreant):
"""Test Group-specific features.
Expand Down

0 comments on commit 31c1134

Please sign in to comment.