<s> import os <EOL> import pkg_resources <EOL> import shutil <EOL> import subprocess <EOL> import tempfile <EOL> import time <EOL> try : <EOL> import httplib <EOL> except ImportError : <EOL> import http . client as httplib <EOL> from pyramid . scaffolds . tests import TemplateTest <EOL> class SubstanceDTemplateTest ( TemplateTest ) : <EOL> def install ( self , tmpl_name ) : <EOL> try : <EOL> self . old_cwd = os . getcwd ( ) <EOL> self . directory = tempfile . mkdtemp ( ) <EOL> self . make_venv ( self . directory ) <EOL> os . chdir ( pkg_resources . get_distribution ( '<STR_LIT>' ) . location ) <EOL> subprocess . check_call ( <EOL> [ os . path . join ( self . directory , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> os . chdir ( self . directory ) <EOL> subprocess . check_call ( [ '<STR_LIT>' , '<STR_LIT>' , tmpl_name , '<STR_LIT>' ] ) <EOL> os . chdir ( '<STR_LIT>' ) <EOL> py = os . path . join ( self . directory , '<STR_LIT>' , '<STR_LIT>' ) <EOL> subprocess . check_call ( [ py , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> subprocess . check_call ( [ py , '<STR_LIT>' , '<STR_LIT:test>' ] ) <EOL> pserve = os . path . join ( self . directory , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for ininame , hastoolbar in ( ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) ) : <EOL> proc = subprocess . Popen ( [ pserve , ininame ] ) <EOL> try : <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> proc . poll ( ) <EOL> if proc . returncode is not None : <EOL> raise RuntimeError ( '<STR_LIT>' % ininame ) <EOL> conn = httplib . HTTPConnection ( '<STR_LIT>' ) <EOL> conn . request ( '<STR_LIT:GET>' , '<STR_LIT:/>' ) <EOL> resp = conn . getresponse ( ) <EOL> assert resp . status == <NUM_LIT:200> , ininame <EOL> data = resp . read ( ) <EOL> toolbarchunk = b'<STR_LIT>' <EOL> if hastoolbar : <EOL> assert toolbarchunk in data , ininame <EOL> else : <EOL> assert not toolbarchunk in data , ininame <EOL> finally : <EOL> proc . terminate ( ) <EOL> finally : <EOL> shutil . rmtree ( self . directory ) <EOL> os . chdir ( self . old_cwd ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test = SubstanceDTemplateTest ( ) <EOL> test . install ( '<STR_LIT>' ) </s>
