Component returns True if checked with bool()

https://github.com/collective/icalendar/issues/141
pull/179/head
Stanislav Laznicka 2016-01-21 16:20:24 +01:00
rodzic 18637a97ee
commit f1f4bc52db
2 zmienionych plików z 20 dodań i 0 usunięć

Wyświetl plik

@ -93,6 +93,21 @@ class Component(CaselessDict):
# """
# return name in not_compliant
def __bool__(self):
"""
Returns True, CaselessDict would return False if it had no items
"""
return True
# python 2 compatibility
__nonzero__ = __bool__
def is_empty(self):
"""
Returns True if Component has no items or subcomponents, else False
"""
return True if not (list(self.values()) + self.subcomponents) else False
#############################
# handling of property values

Wyświetl plik

@ -18,9 +18,14 @@ class TestCalComponent(unittest.TestCase):
c = Component()
c.name = 'VCALENDAR'
self.assertTrue(c)
self.assertTrue(c.is_empty())
# Every key defines a property.A property can consist of either a
# single item. This can be set with a single value...
c['prodid'] = '-//max m//icalendar.mxm.dk/'
self.assertFalse(c.is_empty())
self.assertEqual(
c,
Calendar({'PRODID': '-//max m//icalendar.mxm.dk/'})