raise coverage and remove unused odict
This commit is contained in:
parent
862f012ca0
commit
8b9403a9a4
@ -1,7 +1,7 @@
|
||||
"""
|
||||
This module implements the :class:`DispatchState` class
|
||||
"""
|
||||
from util import odict, Path
|
||||
from util import Path
|
||||
|
||||
class DispatchState(object):
|
||||
"""
|
||||
|
@ -8,62 +8,10 @@ MIT License
|
||||
import collections
|
||||
|
||||
__all__ = [
|
||||
'odict',
|
||||
'get_argspec', 'get_params_with_argspec', 'remove_argspec_params_from_params', 'method_matches_args',
|
||||
'Path'
|
||||
]
|
||||
|
||||
|
||||
class odict(dict):
|
||||
|
||||
def __init__(self, *args, **kw):
|
||||
self._ordering = []
|
||||
dict.__init__(self, *args, **kw)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
if key in self._ordering:
|
||||
self._ordering.remove(key)
|
||||
self._ordering.append(key)
|
||||
dict.__setitem__(self, key, value)
|
||||
|
||||
def keys(self):
|
||||
return self._ordering
|
||||
|
||||
def clear(self):
|
||||
self._ordering = []
|
||||
dict.clear(self)
|
||||
|
||||
def getitem(self, n):
|
||||
return self[self._ordering[n]]
|
||||
|
||||
# def __slice__(self, a, b=-1, n=1):
|
||||
# return self.values()[a:b:n]
|
||||
|
||||
def iteritems(self):
|
||||
for item in self._ordering:
|
||||
yield item, self[item]
|
||||
|
||||
def items(self):
|
||||
return [i for i in self.iteritems()]
|
||||
|
||||
def itervalues(self):
|
||||
for item in self._ordering:
|
||||
yield self[item]
|
||||
|
||||
def values(self):
|
||||
return [i for i in self.itervalues()]
|
||||
|
||||
def __delitem__(self, key):
|
||||
self._ordering.remove(key)
|
||||
dict.__delitem__(self, key)
|
||||
|
||||
def pop(self):
|
||||
item = self._ordering[-1]
|
||||
del self[item]
|
||||
|
||||
def __str__(self):
|
||||
return str(self.items())
|
||||
|
||||
from inspect import getargspec
|
||||
|
||||
_cached_argspecs = {}
|
||||
|
@ -34,6 +34,10 @@ class TestDispatchState:
|
||||
def test_use_path_info(self):
|
||||
state = DispatchState(self.request, self.dispatcher, path_info=['a', 'b'])
|
||||
assert state.path == ['a', 'b'], state.path
|
||||
|
||||
def test_ignore_parameters(self):
|
||||
state = DispatchState(self.request, self.dispatcher, {'a':1, 'z':5}, ignore_parameters=['z'])
|
||||
assert state.params == {'a':1}, state.params
|
||||
|
||||
def test_path_info_with_blanks(self):
|
||||
state = DispatchState(self.request, self.dispatcher, path_info=['', 'a', 'b', '',''])
|
||||
@ -73,4 +77,4 @@ class TestDispatchState:
|
||||
r.path_info = 'something.json'
|
||||
state = DispatchState(r, path_info='s1/s2')
|
||||
assert state.path == ['s1', 's2']
|
||||
|
||||
|
||||
|
@ -81,6 +81,10 @@ class MockSimpleDispatcher(RestDispatcher):
|
||||
def delete(self):
|
||||
pass
|
||||
|
||||
class MockMinimalRestDispatcher(RestDispatcher):
|
||||
def get_one(self):
|
||||
pass
|
||||
|
||||
class TestDispatcher:
|
||||
|
||||
def setup(self):
|
||||
@ -202,6 +206,20 @@ class TestEmbeddedRestDispatcher:
|
||||
assert state.controller.__class__.__name__ == 'MockDispatcher', state.controller
|
||||
assert state.params == {}, state.params
|
||||
|
||||
class TestMinimalRestDispatcher:
|
||||
|
||||
def setup(self):
|
||||
self.dispatcher = MockMinimalRestDispatcher()
|
||||
|
||||
def test_create(self):
|
||||
pass
|
||||
|
||||
def test_get_all_fallback_on_get_one(self):
|
||||
req = MockRequest('/')
|
||||
state = DispatchState(req)
|
||||
state = self.dispatcher._dispatch(state)
|
||||
assert state.method.__name__ == 'get_one'
|
||||
|
||||
class TestDispatcherWithArgs:
|
||||
|
||||
def setup(self):
|
||||
|
@ -2,73 +2,6 @@
|
||||
|
||||
from nose.tools import raises
|
||||
from crank.util import *
|
||||
|
||||
class TestOdict:
|
||||
|
||||
def setup(self):
|
||||
self.d = odict()
|
||||
|
||||
def test_create(self):
|
||||
pass
|
||||
|
||||
def test_set_item(self):
|
||||
self.d['a'] = 1
|
||||
assert self.d['a'] == 1
|
||||
|
||||
def test_keys(self):
|
||||
self.d['b'] = 1
|
||||
self.d['a'] = 1
|
||||
assert self.d.keys() == ['b', 'a']
|
||||
|
||||
def test_clear(self):
|
||||
self.d['b'] = 1
|
||||
self.d['a'] = 1
|
||||
self.d.keys() == ['b', 'a']
|
||||
self.d.clear()
|
||||
assert self.d.keys() == []
|
||||
|
||||
# def test_slice(self):
|
||||
# self.d['b'] = 2
|
||||
# self.d['a'] = 1
|
||||
# self.d[:1] == [2]
|
||||
|
||||
def test_iteritems(self):
|
||||
self.d['b'] = 2
|
||||
self.d['a'] = 1
|
||||
assert [i for i in self.d.iteritems()] == [('b',2), ('a',1)]
|
||||
|
||||
def test_items(self):
|
||||
self.d['b'] = 2
|
||||
self.d['a'] = 1
|
||||
assert self.d.items() == [('b',2), ('a',1)]
|
||||
|
||||
def test_values(self):
|
||||
self.d['b'] = 2
|
||||
self.d['a'] = 1
|
||||
assert self.d.values() == [2,1]
|
||||
|
||||
def test_itervalues(self):
|
||||
self.d['b'] = 2
|
||||
self.d['a'] = 1
|
||||
assert [i for i in self.d.itervalues()] == [2,1]
|
||||
|
||||
@raises(KeyError)
|
||||
def test_delete(self):
|
||||
self.d['b'] = 2
|
||||
del self.d['b']
|
||||
assert self.d._ordering == [], self.d._ordering
|
||||
self.d['b']
|
||||
|
||||
@raises(KeyError)
|
||||
def test_pop(self):
|
||||
self.d['b'] = 2
|
||||
self.d.pop()
|
||||
self.d['b']
|
||||
|
||||
def test__str__(self):
|
||||
self.d['b'] = 2
|
||||
assert str(self.d) == "[('b', 2)]", str(self.d)
|
||||
|
||||
from inspect import ArgSpec
|
||||
|
||||
def mock_f(self, a, b, c=None, d=50, *args, **kw):
|
||||
|
Loading…
x
Reference in New Issue
Block a user