mirror of
https://github.com/caronc/apprise.git
synced 2025-06-26 04:31:57 +02:00
Apprise and AppriseConfig truth value support added (#155)
This commit is contained in:
parent
011fbc9b5f
commit
1047f36c6e
@ -519,6 +519,20 @@ class Apprise(object):
|
|||||||
# If we reach here, then we indexed out of range
|
# If we reach here, then we indexed out of range
|
||||||
raise IndexError('list index out of range')
|
raise IndexError('list index out of range')
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
"""
|
||||||
|
Allows the Apprise object to be wrapped in an Python 3.x based 'if
|
||||||
|
statement'. True is returned if at least one service has been loaded.
|
||||||
|
"""
|
||||||
|
return len(self) > 0
|
||||||
|
|
||||||
|
def __nonzero__(self):
|
||||||
|
"""
|
||||||
|
Allows the Apprise object to be wrapped in an Python 2.x based 'if
|
||||||
|
statement'. True is returned if at least one service has been loaded.
|
||||||
|
"""
|
||||||
|
return len(self) > 0
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""
|
"""
|
||||||
Returns an iterator to each of our servers loaded. This includes those
|
Returns an iterator to each of our servers loaded. This includes those
|
||||||
|
@ -276,6 +276,20 @@ class AppriseConfig(object):
|
|||||||
"""
|
"""
|
||||||
return self.configs[index]
|
return self.configs[index]
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
"""
|
||||||
|
Allows the Apprise object to be wrapped in an Python 3.x based 'if
|
||||||
|
statement'. True is returned if at least one service has been loaded.
|
||||||
|
"""
|
||||||
|
return True if self.configs else False
|
||||||
|
|
||||||
|
def __nonzero__(self):
|
||||||
|
"""
|
||||||
|
Allows the Apprise object to be wrapped in an Python 2.x based 'if
|
||||||
|
statement'. True is returned if at least one service has been loaded.
|
||||||
|
"""
|
||||||
|
return True if self.configs else False
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""
|
"""
|
||||||
Returns an iterator to our config list
|
Returns an iterator to our config list
|
||||||
|
@ -68,6 +68,10 @@ def test_apprise():
|
|||||||
# no items
|
# no items
|
||||||
assert(len(a) == 0)
|
assert(len(a) == 0)
|
||||||
|
|
||||||
|
# Apprise object can also be directly tested with 'if' keyword
|
||||||
|
# No entries results in a False response
|
||||||
|
assert(not a)
|
||||||
|
|
||||||
# Create an Asset object
|
# Create an Asset object
|
||||||
asset = AppriseAsset(theme='default')
|
asset = AppriseAsset(theme='default')
|
||||||
|
|
||||||
@ -85,6 +89,10 @@ def test_apprise():
|
|||||||
# 2 servers loaded
|
# 2 servers loaded
|
||||||
assert(len(a) == 2)
|
assert(len(a) == 2)
|
||||||
|
|
||||||
|
# Apprise object can also be directly tested with 'if' keyword
|
||||||
|
# At least one entry results in a True response
|
||||||
|
assert(a)
|
||||||
|
|
||||||
# We can retrieve our URLs this way:
|
# We can retrieve our URLs this way:
|
||||||
assert(len(a.urls()) == 2)
|
assert(len(a.urls()) == 2)
|
||||||
|
|
||||||
|
@ -55,6 +55,10 @@ def test_apprise_config(tmpdir):
|
|||||||
# There are no servers loaded
|
# There are no servers loaded
|
||||||
assert len(ac) == 0
|
assert len(ac) == 0
|
||||||
|
|
||||||
|
# Object can be directly checked as a boolean; response is False
|
||||||
|
# when there are no entries loaded
|
||||||
|
assert not ac
|
||||||
|
|
||||||
# lets try anyway
|
# lets try anyway
|
||||||
assert len(ac.servers()) == 0
|
assert len(ac.servers()) == 0
|
||||||
|
|
||||||
@ -83,6 +87,10 @@ def test_apprise_config(tmpdir):
|
|||||||
# One configuration file should have been found
|
# One configuration file should have been found
|
||||||
assert len(ac) == 1
|
assert len(ac) == 1
|
||||||
|
|
||||||
|
# Object can be directly checked as a boolean; response is True
|
||||||
|
# when there is at least one entry
|
||||||
|
assert ac
|
||||||
|
|
||||||
# We should be able to read our 3 servers from that
|
# We should be able to read our 3 servers from that
|
||||||
assert len(ac.servers()) == 3
|
assert len(ac.servers()) == 3
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user