<s> import os <EOL> from nose . tools import eq_ <EOL> from inferno . lib . lookup_rules import get_rules <EOL> from inferno . lib . lookup_rules import get_rule_modules <EOL> from inferno . lib . lookup_rules import get_rules_by_name <EOL> class TestGetRulesByName ( object ) : <EOL> def setUp ( self ) : <EOL> here = os . path . dirname ( __file__ ) <EOL> self . rules_dir = os . path . join ( here , '<STR_LIT:..>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_empty_name ( self ) : <EOL> self . _assert_get_rules_by_name ( '<STR_LIT>' , [ ] ) <EOL> def test_unknown_module ( self ) : <EOL> name = '<STR_LIT>' <EOL> self . _assert_get_rules_by_name ( name , [ ] ) <EOL> def test_unknown_rule ( self ) : <EOL> name = '<STR_LIT>' <EOL> self . _assert_get_rules_by_name ( name , [ ] ) <EOL> def test_unknown_keyset ( self ) : <EOL> name = '<STR_LIT>' <EOL> self . _assert_get_rules_by_name ( name , [ ] ) <EOL> def test_automatic_module ( self ) : <EOL> name = '<STR_LIT>' <EOL> expected = [ <EOL> [ '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , [ '<STR_LIT>' ] ] ] <EOL> self . _assert_get_rules_by_name ( name , expected ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = False ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = True ) <EOL> def test_automatic_module_rule ( self ) : <EOL> name = '<STR_LIT>' <EOL> expected = [ [ '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ] ] <EOL> self . _assert_get_rules_by_name ( name , expected ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = False ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = True ) <EOL> def test_automatic_module_rule_keyset ( self ) : <EOL> name = '<STR_LIT>' <EOL> expected = [ [ '<STR_LIT>' , [ '<STR_LIT>' ] ] ] <EOL> self . _assert_get_rules_by_name ( name , expected ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = False ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = True ) <EOL> def test_manual_module ( self ) : <EOL> name = '<STR_LIT>' <EOL> expected = [ <EOL> [ '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , [ '<STR_LIT>' ] ] ] <EOL> self . _assert_get_rules_by_name ( name , [ ] ) <EOL> self . _assert_get_rules_by_name ( name , [ ] , immediate = False ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = True ) <EOL> def test_manual_module_rule ( self ) : <EOL> name = '<STR_LIT>' <EOL> expected = [ [ '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ] ] <EOL> self . _assert_get_rules_by_name ( name , [ ] ) <EOL> self . _assert_get_rules_by_name ( name , [ ] , immediate = False ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = True ) <EOL> def test_manual_module_rule_keyset ( self ) : <EOL> name = '<STR_LIT>' <EOL> expected = [ [ '<STR_LIT>' , [ '<STR_LIT>' ] ] ] <EOL> self . _assert_get_rules_by_name ( name , [ ] ) <EOL> self . _assert_get_rules_by_name ( name , [ ] , immediate = False ) <EOL> self . _assert_get_rules_by_name ( name , expected , immediate = True ) <EOL> def _assert_get_rules_by_name ( self , name , expected , immediate = None ) : <EOL> if immediate is None : <EOL> rules = get_rules_by_name ( name , self . rules_dir ) <EOL> else : <EOL> rules = get_rules_by_name ( name , self . rules_dir , immediate ) <EOL> actual = [ [ rule . name , rule . params . keysets . keys ( ) ] for rule in rules ] <EOL> for rule in actual : <EOL> rule [ <NUM_LIT:1> ] . sort ( ) <EOL> eq_ ( actual , expected ) <EOL> class TestLookupRules ( object ) : <EOL> def setUp ( self ) : <EOL> here = os . path . dirname ( __file__ ) <EOL> self . rules_dir = os . path . join ( here , '<STR_LIT:..>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_get_rule_modules ( self ) : <EOL> actual = sorted ( get_rule_modules ( self . rules_dir ) ) <EOL> expected = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> eq_ ( actual , expected ) <EOL> def test_get_automatic_rules ( self ) : <EOL> rules = get_rules ( self . rules_dir ) <EOL> actual = sorted ( [ rule . name for rule in rules ] ) <EOL> expected = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> eq_ ( actual , expected ) </s>
