mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 05:17:59 +01:00
Add utils module
This commit is contained in:
parent
c350abe479
commit
306988dd36
2 changed files with 116 additions and 0 deletions
45
fimfarchive/utils.py
Normal file
45
fimfarchive/utils.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
"""
|
||||||
|
Various utilities.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fimfarchive, preserves stories from Fimfiction.
|
||||||
|
# Copyright (C) 2015 Joakim Soderlund
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'Empty',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyMeta(type):
|
||||||
|
"""
|
||||||
|
Meta-class for Empty.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __bool__(cls):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class Empty(metaclass=EmptyMeta):
|
||||||
|
"""
|
||||||
|
Unique placeholder similar to `None`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
return False
|
71
tests/test_utils.py
Normal file
71
tests/test_utils.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
"""
|
||||||
|
Utility tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fimfarchive, preserves stories from Fimfiction.
|
||||||
|
# Copyright (C) 2015 Joakim Soderlund
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
from fimfarchive.utils import Empty
|
||||||
|
|
||||||
|
|
||||||
|
class TestEmpty:
|
||||||
|
"""
|
||||||
|
Empty tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_empty_class_is_not_none(self):
|
||||||
|
"""
|
||||||
|
Tests `Empty` class is different from `None`.
|
||||||
|
"""
|
||||||
|
assert Empty is not None
|
||||||
|
assert Empty != None # noqa
|
||||||
|
|
||||||
|
def test_empty_class_evaluates_to_false(self):
|
||||||
|
"""
|
||||||
|
Tests `Empty` class evaluates to `False`.
|
||||||
|
"""
|
||||||
|
assert not Empty
|
||||||
|
|
||||||
|
def test_empty_class_is_empty(self):
|
||||||
|
"""
|
||||||
|
Tests `Empty` class can be identified.
|
||||||
|
"""
|
||||||
|
assert Empty is Empty
|
||||||
|
assert Empty == Empty
|
||||||
|
|
||||||
|
def test_empty_instance_evaluates_to_false(self):
|
||||||
|
"""
|
||||||
|
Tests `Empty` instance evaulates to `False`
|
||||||
|
"""
|
||||||
|
assert not Empty()
|
||||||
|
|
||||||
|
def test_empty_instance_is_unique(self):
|
||||||
|
"""
|
||||||
|
Tests `Empty` instances are unique.
|
||||||
|
"""
|
||||||
|
empty = Empty()
|
||||||
|
|
||||||
|
assert isinstance(empty, Empty)
|
||||||
|
assert empty is not Empty
|
||||||
|
assert empty != Empty
|
||||||
|
assert empty is not Empty()
|
||||||
|
assert empty != Empty()
|
||||||
|
assert empty is empty
|
||||||
|
assert empty == empty
|
Loading…
Reference in a new issue