Improved tests

This commit is contained in:
Syrus Akbary 2015-11-13 19:28:40 -08:00
parent 5282627537
commit dfc2bc4ac3
6 changed files with 28 additions and 4 deletions

View File

@ -31,7 +31,7 @@ class LazyMap(object):
return self.__next__()
def __getitem__(self, key):
item = self._origin.__getitem__(key)
item = self._origin[key]
if isinstance(key, slice):
return LazyMap(item, self._map)
return self._map(item)

View File

View File

@ -0,0 +1,23 @@
from py.test import raises
from ..lazymap import LazyMap
def test_lazymap():
data = list(range(10))
lm = LazyMap(data, lambda x: 2 * x)
assert len(lm) == 10
assert lm[1] == 2
assert isinstance(lm[1:4], LazyMap)
assert lm.append == data.append
assert repr(lm) == '<LazyMap [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>'
def test_lazymap_iter():
data = list(range(2))
lm = LazyMap(data, lambda x: 2 * x)
iter_lm = iter(lm)
assert iter_lm.next() == 0
assert iter_lm.next() == 2
with raises(StopIteration):
iter_lm.next()

View File

@ -1,8 +1,9 @@
import collections
from graphene.utils.misc import enum_to_graphql_enum
from graphql.core.type import GraphQLEnumType
from ..misc import enum_to_graphql_enum
item = collections.namedtuple('type', 'name value')

View File

@ -1,6 +1,6 @@
from py.test import raises
from graphene.utils import ProxySnakeDict
from ..proxy_snake_dict import ProxySnakeDict
def test_proxy_snake_dict():

View File

@ -1,4 +1,4 @@
from graphene.utils import to_camel_case, to_snake_case
from ..str_converters import to_camel_case, to_snake_case
def test_snake_case():