Skip to content
This repository
Browse code

Fix duh moment in handling pairs, add more tests

  • Loading branch information...
commit 5775c08a230ef04e68544f7ff6887d36f9e8c472 1 parent 5df8238
Harry Fuecks authored

Showing 1 changed file with 54 additions and 0 deletions. Show diff stats Hide diff stats

  1. +54 0 dammit/nullcache.py
54 dammit/nullcache.py
... ... @@ -0,0 +1,54 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +"""
  4 +For tests - a cache which doesn't remember
  5 +anything
  6 +"""
  7 +from cachemanager import namespacer
  8 +
  9 +class NullCache(object):
  10 + """
  11 + >>> nc = NullCache()
  12 + >>> 'foo' in nc
  13 + False
  14 + >>> nc['foo'] = 'bar'
  15 + >>> 'foo' in nc
  16 + False
  17 + >>> nc['foo'] == 'bar'
  18 + Traceback (most recent call last):
  19 + KeyError: '_foo'
  20 + >>> del nc['foo']
  21 + Traceback (most recent call last):
  22 + KeyError: '_foo'
  23 + """
  24 + def __init__(self):
  25 + self.namespace = ''
  26 +
  27 + def __len__(self):
  28 + raise Exception("Not implemented")
  29 +
  30 + @namespacer
  31 + def __contains__(self, key):
  32 + return False
  33 +
  34 + @namespacer
  35 + def __setitem__(self, key, val):
  36 + pass
  37 +
  38 + @namespacer
  39 + def __getitem__(self, key):
  40 + raise KeyError(key)
  41 +
  42 + @namespacer
  43 + def __delitem__(self, key):
  44 + raise KeyError(key)
  45 +
  46 + def __repr__(self):
  47 + return "NullCache"
  48 +
  49 +def _test():
  50 + import doctest
  51 + doctest.testmod()
  52 +
  53 +if __name__ == '__main__':
  54 + _test()

0 comments on commit 5775c08

Please sign in to comment.
Something went wrong with that request. Please try again.