<s> import itertools <EOL> import operator <EOL> import mock <EOL> import pytest <EOL> import six <EOL> from okcupyd import util <EOL> @ util . curry <EOL> def crazy ( a , self ) : <EOL> return a + self . starter <EOL> class HasCurryMethods ( object ) : <EOL> def __init__ ( self , starter ) : <EOL> self . starter = starter <EOL> self . on_instance = crazy <EOL> @ util . curry <EOL> def curry ( self , x , y = <NUM_LIT:0> ) : <EOL> return self . starter * x * y <EOL> on_class = crazy ( <NUM_LIT:1> ) <EOL> def test_curry_method_behavior ( ) : <EOL> assert HasCurryMethods ( <NUM_LIT:2> ) . curry ( y = <NUM_LIT:2> ) ( <NUM_LIT:1> ) == <NUM_LIT:4> <EOL> hpm = HasCurryMethods ( <NUM_LIT:2> ) <EOL> assert hpm . on_instance ( <NUM_LIT:2> , hpm ) == <NUM_LIT:4> <EOL> assert hpm . on_class ( ) == <NUM_LIT:3> <EOL> def test_curry_with_kwargs_taking_function ( ) : <EOL> @ util . curry <EOL> def kwarg_taking_function ( arg , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:k>' ] = arg <EOL> return kwargs <EOL> assert kwarg_taking_function ( a = <NUM_LIT> ) ( <NUM_LIT:2> ) == { '<STR_LIT:k>' : <NUM_LIT:2> , '<STR_LIT:a>' : <NUM_LIT> } <EOL> def test_curry_cache_behavior_problems ( ) : <EOL> class CurryCacheTest ( object ) : <EOL> def func ( self , a = <NUM_LIT:1> ) : <EOL> return <NUM_LIT:2> + a <EOL> test = util . curry ( func ) <EOL> def func ( self ) : <EOL> return <NUM_LIT:1> <EOL> instance = CurryCacheTest ( ) <EOL> assert instance . func ( ) == <NUM_LIT:1> <EOL> assert instance . test ( ) == <NUM_LIT:3> <EOL> assert instance . func ( ) == <NUM_LIT:1> <EOL> assert instance . test is not instance . test <EOL> assert instance . func is not instance . func <EOL> class CurryCacheTest2 ( object ) : <EOL> def func ( self , a = <NUM_LIT:1> ) : <EOL> return <NUM_LIT:2> + a <EOL> test = util . curry ( func , cache_name = '<STR_LIT:test>' ) <EOL> @ util . curry ( cache_name = True ) <EOL> def func ( self ) : <EOL> return <NUM_LIT:1> <EOL> instance = CurryCacheTest2 ( ) <EOL> assert instance . func ( ) == <NUM_LIT:1> <EOL> assert instance . test ( ) == <NUM_LIT:3> <EOL> assert instance . func ( ) == <NUM_LIT:1> <EOL> assert instance . test is instance . test <EOL> assert instance . func is instance . func <EOL> def test_get_cached_properties ( ) : <EOL> class PropClass ( object ) : <EOL> def __init__ ( self ) : <EOL> self . count = <NUM_LIT:0> <EOL> @ util . cached_property <EOL> def count_prop ( self ) : <EOL> self . count += <NUM_LIT:1> <EOL> return self . count <EOL> @ util . cached_property <EOL> def other_prop ( self ) : <EOL> return <NUM_LIT:4> <EOL> instance = PropClass ( ) <EOL> assert [ '<STR_LIT>' , '<STR_LIT>' ] == list ( map ( operator . itemgetter ( <NUM_LIT:0> ) , <EOL> util . cached_property . get_cached_properties ( instance ) ) ) <EOL> assert instance . count_prop == <NUM_LIT:1> <EOL> util . cached_property . bust_caches ( instance ) <EOL> assert instance . count_prop == <NUM_LIT:2> <EOL> def test_overwrite_kwarg ( ) : <EOL> @ util . curry <EOL> def test ( k , a = <NUM_LIT:0> , b = <NUM_LIT:0> ) : <EOL> return k + a + b <EOL> assert test ( a = <NUM_LIT:4> ) ( a = <NUM_LIT:1> ) ( <NUM_LIT:1> ) == <NUM_LIT:2> <EOL> def test_fetchable_teeing ( ) : <EOL> fetcher = mock . Mock ( fetch = lambda : itertools . count ( <NUM_LIT:5> ) ) <EOL> fetchable = util . Fetchable ( fetcher ) <EOL> first = iter ( fetchable ) <EOL> second = iter ( fetchable ) <EOL> assert next ( first ) == <NUM_LIT:5> <EOL> assert next ( second ) == <NUM_LIT:5> <EOL> third = iter ( fetchable ) <EOL> assert next ( third ) == <NUM_LIT:5> <EOL> assert next ( third ) == <NUM_LIT:6> <EOL> assert next ( third ) == <NUM_LIT:7> <EOL> assert next ( first ) == <NUM_LIT:6> <EOL> assert next ( second ) == <NUM_LIT:6> <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> assert next ( iter ( fetchable ) ) == <NUM_LIT:5> <EOL> def test_fetchable_step ( ) : <EOL> fetcher = mock . Mock ( fetch = lambda : itertools . count ( <NUM_LIT:5> ) ) <EOL> fetchable = util . Fetchable ( fetcher ) <EOL> assert fetchable [ : <NUM_LIT:10> : <NUM_LIT:3> ] == [ i for i in range ( <NUM_LIT:5> , <NUM_LIT:100> ) ] [ : <NUM_LIT:10> : <NUM_LIT:3> ] <EOL> assert fetchable [ : <NUM_LIT:30> : <NUM_LIT:5> ] == [ i for i in range ( <NUM_LIT:5> , <NUM_LIT:100> ) ] [ : <NUM_LIT:30> : <NUM_LIT:5> ] <EOL> def test_fetchable_get_item ( ) : <EOL> call_counter = mock . Mock ( ) <EOL> def fetch ( ) : <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> yield i <EOL> call_counter ( ) <EOL> fetcher = mock . Mock ( fetch = fetch ) <EOL> fetchable = util . Fetchable ( fetcher ) <EOL> assert fetchable [ : <NUM_LIT:2> ] == [ <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> assert fetchable [ : <NUM_LIT:3> ] == [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert fetchable [ <NUM_LIT:3> ] == <NUM_LIT:3> <EOL> assert call_counter . call_count == <NUM_LIT:0> <EOL> assert fetchable [ <NUM_LIT:9> ] == <NUM_LIT:4> <EOL> assert call_counter . call_count == <NUM_LIT:1> <EOL> assert fetchable [ <NUM_LIT:2> : <NUM_LIT:3> ] == [ <NUM_LIT:2> ] <EOL> assert fetchable [ : ] == fetchable [ : ] <EOL> assert len ( fetchable [ : ] ) == <NUM_LIT:15> <EOL> assert fetchable [ : <NUM_LIT> ] == fetchable [ : ] <EOL> assert fetchable [ <NUM_LIT> : ] == [ ] <EOL> assert fetchable [ <NUM_LIT> : <NUM_LIT> ] == [ ] <EOL> with pytest . raises ( IndexError ) : <EOL> fetchable [ <NUM_LIT> ] <EOL> def test_negative_indexing ( ) : <EOL> def fetch ( ) : <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT:1> <EOL> fetcher = mock . Mock ( fetch = fetch ) <EOL> fetchable = util . Fetchable ( fetcher ) <EOL> assert fetchable [ - <NUM_LIT:1> ] == <NUM_LIT:1> <EOL> assert fetchable [ - <NUM_LIT:2> : ] == [ <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> assert fetchable [ <NUM_LIT> : ] == [ ] <EOL> def test_bool_on_fetchable ( ) : <EOL> fetcher = mock . Mock ( fetch = lambda : ( i for i in range ( <NUM_LIT:0> ) ) ) <EOL> fetchable = util . Fetchable ( fetcher ) <EOL> assert not fetchable <EOL> fetcher = mock . Mock ( fetch = lambda : ( i for i in range ( <NUM_LIT:1> ) ) ) <EOL> fetchable = util . Fetchable ( fetcher ) <EOL> assert fetchable <EOL> def test_curry_on_classmethod ( ) : <EOL> class TestClass ( object ) : <EOL> @ classmethod <EOL> @ util . curry <EOL> def test ( cls , arg , optional = <NUM_LIT:3> ) : <EOL> return optional + arg <EOL> assert TestClass . test ( optional = <NUM_LIT:1> ) ( <NUM_LIT:2> ) == <NUM_LIT:3> <EOL> assert TestClass ( ) . test ( optional = <NUM_LIT:3> ) ( <NUM_LIT:2> ) == <NUM_LIT:5> <EOL> def test_decorate_all ( ) : <EOL> def add_two ( function ) : <EOL> def wrap ( * args , ** kwargs ) : <EOL> return function ( * args , ** kwargs ) + <NUM_LIT:2> <EOL> return wrap <EOL> class Test ( six . with_metaclass ( util . decorate_all ( add_two ) ) ) : <EOL> def one ( self ) : <EOL> return <NUM_LIT:1> <EOL> def two ( self ) : <EOL> return <NUM_LIT:2> <EOL> assert Test ( ) . one ( ) == <NUM_LIT:3> <EOL> assert Test ( ) . two ( ) == <NUM_LIT:4> <EOL> def test_staticmethod_decorate_all ( ) : <EOL> class Test ( six . with_metaclass ( util . decorate_all ( staticmethod ) ) ) : <EOL> def test ( ) : <EOL> return <NUM_LIT:1> <EOL> def test2 ( a , b ) : <EOL> return a + b <EOL> assert Test . test ( ) == <NUM_LIT:1> <EOL> assert Test . test2 ( <NUM_LIT:1> , <NUM_LIT:1> ) == <NUM_LIT:2> <EOL> def test_classmethods_still_classmethods_with_staticmethod_decorate_all ( ) : <EOL> class Test ( six . with_metaclass ( util . decorate_all ( staticmethod ) ) ) : <EOL> @ classmethod <EOL> def a_classmethod ( cls ) : <EOL> return <NUM_LIT:2> <EOL> def test ( ) : <EOL> return <NUM_LIT:1> <EOL> assert Test . test ( ) == <NUM_LIT:1> <EOL> assert Test . a_classmethod ( ) == <NUM_LIT:2> </s>
