<s> from nose . tools import eq_ <EOL> from nose . tools import ok_ <EOL> from disco . core import result_iterator <EOL> from inferno . lib . rule import InfernoRule <EOL> from inferno . lib . rule import Keyset <EOL> from inferno . lib . disco_ext import sorted_iterator <EOL> class TestInfernoRule ( object ) : <EOL> def test_keysets ( self ) : <EOL> rule = InfernoRule ( <EOL> key_parts = [ '<STR_LIT:id>' ] , <EOL> value_parts = [ '<STR_LIT:count>' ] , <EOL> table = '<STR_LIT>' , <EOL> column_mappings = { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> keysets = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT:id>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT:count>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } } <EOL> eq_ ( rule . params . keysets , keysets ) <EOL> rule = InfernoRule ( <EOL> keysets = { <EOL> '<STR_LIT>' : Keyset ( <EOL> key_parts = [ '<STR_LIT>' ] , <EOL> value_parts = [ '<STR_LIT>' ] , <EOL> column_mappings = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> table = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : Keyset ( <EOL> key_parts = [ '<STR_LIT>' ] , <EOL> value_parts = [ '<STR_LIT>' ] , <EOL> column_mappings = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> table = '<STR_LIT>' ) } ) <EOL> keysets = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> } <EOL> eq_ ( rule . params . keysets , keysets ) <EOL> def test_parts_preprocess ( self ) : <EOL> def foo ( parts , params ) : <EOL> parts [ '<STR_LIT:bar>' ] = <NUM_LIT:1> <EOL> yield parts <EOL> rule = InfernoRule ( parts_preprocess = [ foo ] ) <EOL> eq_ ( rule . params . parts_preprocess , [ foo ] ) <EOL> actual = rule . params . parts_preprocess [ <NUM_LIT:0> ] ( { '<STR_LIT:hello>' : '<STR_LIT>' } , None ) <EOL> eq_ ( list ( actual ) , [ { '<STR_LIT:bar>' : <NUM_LIT:1> , '<STR_LIT:hello>' : '<STR_LIT>' } ] ) <EOL> def test_keyset_parts_preprocess ( self ) : <EOL> def foo ( parts , params ) : <EOL> parts [ '<STR_LIT:bar>' ] = <NUM_LIT:1> <EOL> yield parts <EOL> rule = InfernoRule ( <EOL> keysets = { <EOL> '<STR_LIT>' : Keyset ( parts_preprocess = [ foo ] ) , <EOL> } ) <EOL> funcs = rule . params . keysets [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> eq_ ( funcs , [ foo ] ) <EOL> actual = funcs [ <NUM_LIT:0> ] ( { '<STR_LIT:hello>' : '<STR_LIT>' } , None ) <EOL> eq_ ( list ( actual ) , [ { '<STR_LIT:bar>' : <NUM_LIT:1> , '<STR_LIT:hello>' : '<STR_LIT>' } ] ) <EOL> def test_field_transforms ( self ) : <EOL> def upper ( val ) : <EOL> return val . upper ( ) <EOL> rule = InfernoRule ( field_transforms = { '<STR_LIT:hello>' : upper } ) <EOL> eq_ ( rule . params . field_transforms , { '<STR_LIT:hello>' : upper } ) <EOL> def test_result_iterator ( self ) : <EOL> rule = InfernoRule ( ) <EOL> eq_ ( rule . result_iterator , sorted_iterator ) <EOL> rule = InfernoRule ( sort = True ) <EOL> eq_ ( rule . result_iterator , sorted_iterator ) <EOL> rule = InfernoRule ( sort = False ) <EOL> eq_ ( rule . result_iterator , result_iterator ) <EOL> def test_source_tags ( self ) : <EOL> rule = InfernoRule ( source_tags = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> eq_ ( rule . source_tags , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> rule = InfernoRule ( source_tags = [ ] ) <EOL> eq_ ( rule . source_tags , [ ] ) <EOL> rule = InfernoRule ( source_tags = '<STR_LIT>' ) <EOL> eq_ ( rule . source_tags , [ '<STR_LIT>' ] ) <EOL> rule = InfernoRule ( source_tags = None ) <EOL> eq_ ( rule . source_tags , [ ] ) <EOL> def test_kwargs ( self ) : <EOL> rule = InfernoRule ( some_extra_param = '<STR_LIT>' ) <EOL> eq_ ( rule . params . some_extra_param , '<STR_LIT>' ) <EOL> def test_str ( self ) : <EOL> rule = InfernoRule ( name = '<STR_LIT>' ) <EOL> eq_ ( str ( rule ) , '<STR_LIT>' ) </s>
