diff --git a/fimfarchive/mappers.py b/fimfarchive/mappers.py new file mode 100644 index 0000000..df44e25 --- /dev/null +++ b/fimfarchive/mappers.py @@ -0,0 +1,43 @@ +""" +Mappers for Fimfarchive. +""" + + +# +# 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 . +# + + +class Mapper: + """ + Callable which maps something to something else. + """ + + def __call__(self, *args, **kwargs): + raise NotImplementedError() + + +class StaticMapper(Mapper): + """ + Returns the supplied value for any call. + """ + + def __init__(self, value=None): + self.value = value + + def __call__(self, *args, **kwargs): + return self.value diff --git a/tests/test_mappers.py b/tests/test_mappers.py new file mode 100644 index 0000000..9b36280 --- /dev/null +++ b/tests/test_mappers.py @@ -0,0 +1,68 @@ +""" +Mapper 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 . +# + + +import pytest + +from fimfarchive.mappers import StaticMapper + + +class TestStaticMapper: + """ + StaticMapper tests. + """ + + @pytest.fixture + def value(self): + """ + Returns a unique instance. + """ + return object() + + def test_value(self, value): + """ + Tests returns the supplied value. + """ + mapper = StaticMapper(value) + assert mapper() is value + + def test_default_value(self): + """ + Tests `None` is returned by default. + """ + mapper = StaticMapper() + assert mapper() is None + + def test_args(self, value): + """ + Tests callable ignores args. + """ + mapper = StaticMapper(value) + assert mapper(1, 2, 3) is value + + def test_kwargs(self, value): + """ + Tests callable ignores kwargs. + """ + mapper = StaticMapper(value) + assert mapper(a=1, b=2) is value