Refactor and add tests for plugins.py

Improvement to the tests currently being run on ``plugins.py``

related #644 
This initialization can be skipped if you use `defaultdict`.
```python
>>> from collections import defaultdict
>>> d = defaultdict(lambda: defaultdict(int))
>>> d['foo']['bar'] += 1
```
or using a partial instead of lambda, a bit nicer
```python
>>> from collections import defaultdict
>>> from functools import partial
>>> d = defaultdict(partial(defaultdict, int))
>>> d['foo']['bar'] += 1
```