<s> import glob <EOL> import docutils . core <EOL> import testtools <EOL> class TestTitles ( testtools . TestCase ) : <EOL> def _get_title ( self , section_tree ) : <EOL> section = { <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> for node in section_tree : <EOL> if node . tagname == '<STR_LIT:title>' : <EOL> section [ '<STR_LIT:name>' ] = node . rawsource <EOL> elif node . tagname == '<STR_LIT>' : <EOL> subsection = self . _get_title ( node ) <EOL> section [ '<STR_LIT>' ] . append ( subsection [ '<STR_LIT:name>' ] ) <EOL> return section <EOL> def _get_titles ( self , spec ) : <EOL> titles = { } <EOL> for node in spec : <EOL> if node . tagname == '<STR_LIT>' : <EOL> section = self . _get_title ( node ) <EOL> titles [ section [ '<STR_LIT:name>' ] ] = section [ '<STR_LIT>' ] <EOL> return titles <EOL> def _check_titles ( self , titles ) : <EOL> self . assertEqual ( <NUM_LIT:7> , len ( titles ) ) <EOL> problem = '<STR_LIT>' <EOL> self . assertIn ( problem , titles ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( titles [ problem ] ) ) <EOL> proposed = '<STR_LIT>' <EOL> self . assertIn ( proposed , titles ) <EOL> self . assertEqual ( <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> titles [ proposed ] ) <EOL> impl = '<STR_LIT>' <EOL> self . assertIn ( impl , titles ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( titles [ impl ] ) ) <EOL> self . assertIn ( '<STR_LIT>' , titles [ impl ] ) <EOL> self . assertIn ( '<STR_LIT>' , titles [ impl ] ) <EOL> deps = '<STR_LIT>' <EOL> self . assertIn ( deps , titles ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( titles [ deps ] ) ) <EOL> testing = '<STR_LIT>' <EOL> self . assertIn ( testing , titles ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( titles [ testing ] ) ) <EOL> docs = '<STR_LIT>' <EOL> self . assertIn ( docs , titles ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( titles [ docs ] ) ) <EOL> refs = '<STR_LIT>' <EOL> self . assertIn ( refs , titles ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( titles [ refs ] ) ) <EOL> def test_template ( self ) : <EOL> files = [ '<STR_LIT>' ] + glob . glob ( '<STR_LIT>' ) <EOL> for filename in files : <EOL> self . assertTrue ( filename . endswith ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> with open ( filename ) as f : <EOL> data = f . read ( ) <EOL> spec = docutils . core . publish_doctree ( data ) <EOL> titles = self . _get_titles ( spec ) <EOL> self . _check_titles ( titles ) </s>
