<s> import unittest <EOL> from pledger . parser import Parser <EOL> from pledger . directive import * <EOL> from pledger . ledger_processor import LedgerProcessor <EOL> class ProcessorStub ( object ) : <EOL> def __init__ ( self , root ) : <EOL> self . account = root <EOL> self . included = [ ] <EOL> def add_account_prefix ( self , prefix ) : <EOL> self . account = self . account [ prefix ] <EOL> def remove_account_prefix ( self ) : <EOL> self . account = self . account . parent <EOL> def include ( self , filename ) : <EOL> self . included . append ( filename ) <EOL> class DirectiveTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . parser = Parser ( ) <EOL> self . processor = ProcessorStub ( self . parser . accounts ) <EOL> def testDirectiveRegistry ( self ) : <EOL> self . assertEqual ( AccountDirective , Directive . directives [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( Directive . directives . get ( '<STR_LIT>' ) ) <EOL> def testUnsupportedDirective ( self ) : <EOL> with self . assertRaises ( UnsupportedDirective ) as cm : <EOL> self . parser . parse_directive ( "<STR_LIT>" ) <EOL> self . assertRegexpMatches ( str ( cm . exception ) , "<STR_LIT>" ) <EOL> def testAccountDirective ( self ) : <EOL> directive = AccountDirective ( "<STR_LIT>" ) <EOL> self . assertIsNone ( self . processor . account . name ) <EOL> directive . execute ( self . processor ) <EOL> self . assertEqual ( "<STR_LIT>" , self . processor . account . name ) <EOL> def testEndAccountDirective ( self ) : <EOL> directive = EndAccountDirective ( ) <EOL> self . processor . add_account_prefix ( "<STR_LIT>" ) <EOL> directive . execute ( self . processor ) <EOL> self . assertIsNone ( self . processor . account . name ) <EOL> def testIncludeDirective ( self ) : <EOL> directive = IncludeDirective ( "<STR_LIT>" ) <EOL> self . assertEqual ( [ ] , self . processor . included ) <EOL> directive . execute ( self . processor ) <EOL> self . assertEqual ( [ "<STR_LIT>" ] , self . processor . included ) <EOL> def testDirectiveParsing ( self ) : <EOL> directive = self . parser . parse_directive ( "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" , directive . filename ) </s>
