<s> from helpers import unittest <EOL> import luigi <EOL> import luigi . notifications <EOL> luigi . notifications . DEBUG = True <EOL> class LinearSum ( luigi . Task ) : <EOL> lo = luigi . IntParameter ( ) <EOL> hi = luigi . IntParameter ( ) <EOL> def requires ( self ) : <EOL> if self . hi > self . lo : <EOL> return self . clone ( hi = self . hi - <NUM_LIT:1> ) <EOL> def run ( self ) : <EOL> if self . hi > self . lo : <EOL> self . s = self . requires ( ) . s + self . f ( self . hi - <NUM_LIT:1> ) <EOL> else : <EOL> self . s = <NUM_LIT:0> <EOL> self . complete = lambda : True <EOL> def complete ( self ) : <EOL> return False <EOL> def f ( self , x ) : <EOL> return x <EOL> class PowerSum ( LinearSum ) : <EOL> p = luigi . IntParameter ( ) <EOL> def f ( self , x ) : <EOL> return x ** self . p <EOL> class CloneTest ( unittest . TestCase ) : <EOL> def test_args ( self ) : <EOL> t = LinearSum ( lo = <NUM_LIT> , hi = <NUM_LIT> ) <EOL> self . assertEqual ( t . param_args , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . assertEqual ( t . param_kwargs , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } ) <EOL> def test_recursion ( self ) : <EOL> t = LinearSum ( lo = <NUM_LIT> , hi = <NUM_LIT> ) <EOL> luigi . build ( [ t ] , local_scheduler = True ) <EOL> self . assertEqual ( t . s , <NUM_LIT> + <NUM_LIT> + <NUM_LIT> ) <EOL> def test_inheritance ( self ) : <EOL> t = PowerSum ( lo = <NUM_LIT> , hi = <NUM_LIT> , p = <NUM_LIT:2> ) <EOL> luigi . build ( [ t ] , local_scheduler = True ) <EOL> self . assertEqual ( t . s , <NUM_LIT> ** <NUM_LIT:2> + <NUM_LIT> ** <NUM_LIT:2> + <NUM_LIT> ** <NUM_LIT:2> ) </s>
