mongodol.add_ons

Add-ons https://github.com/i2mint/mongodol/issues/3

class mongodol.add_ons.Addons[source]

A collection of add-on methods. Addons can’t (and is not meant to) be instantiated. It’s just to group add-on functions (meant to be injected in stores) in one place

mongodol.add_ons.add_clear_method(store, *, clear_method=<function Addons.clear>, validator=<function _clear_method_injection_validator>)[source]

Add a clear method to a store that doesn’t have one

Parameters:
  • store

  • clear_method

Returns:

>>> from dol.util import has_enabled_clear_method
>>> from mongodol.base import MongoCollectionPersister
>>> from mongodol.tests import data, populated_pymongo_collection
>>>
>>> whole_store = MongoCollectionPersister(populated_pymongo_collection(data.feature_cube))
>>> whole_length_before_clear = len(whole_store)
>>> assert whole_length_before_clear == 7
>>> reds = MongoCollectionPersister(whole_store.mgc, filter={'color': 'red'})
>>> n_reds = len(reds)
>>> assert n_reds == 4

reds doesn’t have a clear method

>>> assert not has_enabled_clear_method(reds)

So let’s give it one

>>> reds_with_clear = add_clear_method(reds)
>>> assert has_enabled_clear_method(reds_with_clear)

And it’s one that works too!

>>> r = reds_with_clear.clear()
>>> assert len(reds_with_clear) == 0

It’s the data that was deleted, not just the view. See what reds and whole_store say:

>>> assert len(reds) == 0
>>> assert len(whole_store) == whole_length_before_clear - n_reds == 3
mongodol.add_ons.has_exactly_one_non_defaulted_input(func)[source]

Return True iff function has exactly one argument without defaults

mongodol.add_ons.number_of_non_defaulted_arguments(func)[source]

Return the number of arguments that don’t have defaults in it’s signature