Best Python code snippet using ATX
test_newrelic.py
Source:test_newrelic.py  
...165            if name.startswith('httpd-') and name.endswith('.gz'):166                os.remove(os.path.join(os.environ['TMPDIR'], name))167            if name.startswith('php-') and name.endswith('.gz'):168                os.remove(os.path.join(os.environ['TMPDIR'], name))169    def assert_exists(self, *args):170        eq_(True, os.path.exists(os.path.join(*args)),171            "Does not exists: %s" % os.path.join(*args))172class TestCompileNewRelicWithPHP(BaseCompileNewRelic):173    def setUp(self):174        BaseCompileNewRelic.initialize(self, 'app-1')175    def tearDown(self):176        BaseCompileNewRelic.cleanup(self)177    def test_compile_httpd_with_newrelic(self):178        os.environ['NEWRELIC_LICENSE'] = 'JUNK_LICENSE'179        os.environ['VCAP_APPLICATION'] = json.dumps({180            'name': 'app-name-1'181        })182        bp = BuildPack({183            'BUILD_DIR': self.build_dir,184            'CACHE_DIR': self.cache_dir,185        }, '.')186        # simulate clone, makes debugging easier187        os.rmdir(bp.bp_dir)188        shutil.copytree('.', bp.bp_dir,189                        ignore=shutil.ignore_patterns("binaries",190                                                      "env",191                                                      "tests"))192        # set php & web server193        optsFile = os.path.join(bp.bp_dir, 'defaults', 'options.json')194        self._set_php(optsFile, 'php')195        self._set_web_server(optsFile, 'httpd')196        try:197            output = ''198            output = bp._compile()199            outputLines = output.split('\n')200            eq_(22, len([l for l in outputLines201                         if l.startswith('Downloaded')]))202            eq_(2, len([l for l in outputLines if l.startswith('Installing')]))203            eq_(True, outputLines[-1].startswith('Finished:'))204            # Test scripts and config205            self.assert_exists(self.build_dir, 'start.sh')206            with open(os.path.join(self.build_dir, 'start.sh')) as start:207                lines = [line.strip() for line in start.readlines()]208                eq_(5, len(lines))209                eq_('export PYTHONPATH=$HOME/.bp/lib', lines[0])210                eq_('$HOME/.bp/bin/rewrite "$HOME/httpd/conf"', lines[1])211                eq_('$HOME/.bp/bin/rewrite "$HOME/php/etc"', lines[2])212                eq_('$HOME/.bp/bin/rewrite "$HOME/.env"', lines[3])213                eq_('$HOME/.bp/bin/start', lines[4])214            # Check scripts and bp are installed215            self.assert_exists(self.build_dir, '.bp', 'bin', 'rewrite')216            self.assert_exists(self.build_dir, '.bp', 'lib')217            bpu_path = os.path.join(self.build_dir, '.bp', 'lib',218                                    'build_pack_utils')219            eq_(22, len(os.listdir(bpu_path)))220            self.assert_exists(bpu_path, 'utils.py')221            self.assert_exists(bpu_path, 'process.py')222            # Check env and procs files223            self.assert_exists(self.build_dir, '.env')224            self.assert_exists(self.build_dir, '.procs')225            with open(os.path.join(self.build_dir, '.env')) as env:226                lines = [line.strip() for line in env.readlines()]227                eq_(2, len(lines))228                eq_('HTTPD_SERVER_ADMIN=dan@mikusa.com', lines[0])229                eq_('LD_LIBRARY_PATH=@LD_LIBRARY_PATH:@HOME/php/lib',230                    lines[1])231            with open(os.path.join(self.build_dir, '.procs')) as procs:232                lines = [line.strip() for line in procs.readlines()]233                eq_(3, len(lines))234                eq_('httpd: $HOME/httpd/bin/apachectl -f '235                    '"$HOME/httpd/conf/httpd.conf" -k start -DFOREGROUND',236                    lines[0])237                eq_('php-fpm: $HOME/php/sbin/php-fpm -p "$HOME/php/etc" -y '238                    '"$HOME/php/etc/php-fpm.conf" -c "$HOME/php/etc"', lines[1])239                eq_('php-fpm-logs: tail -F $HOME/../logs/php-fpm.log',240                    lines[2])241            # Check htdocs and config242            self.assert_exists(self.build_dir, 'htdocs')243            self.assert_exists(self.build_dir, '.bp-config')244            self.assert_exists(self.build_dir, '.bp-config', 'options.json')245            # Test HTTPD246            self.assert_exists(self.build_dir)247            self.assert_exists(self.build_dir, 'httpd')248            self.assert_exists(self.build_dir, 'httpd', 'conf')249            self.assert_exists(self.build_dir, 'httpd', 'conf', 'httpd.conf')250            self.assert_exists(self.build_dir, 'httpd', 'conf', 'extra')251            self.assert_exists(self.build_dir, 'httpd', 'conf',252                               'extra', 'httpd-modules.conf')253            self.assert_exists(self.build_dir, 'httpd', 'conf',254                               'extra', 'httpd-remoteip.conf')255            self.assert_exists(self.build_dir, 'httpd', 'modules',256                               'mod_authz_core.so')257            self.assert_exists(self.build_dir, 'httpd', 'modules',258                               'mod_authz_host.so')259            self.assert_exists(self.build_dir, 'httpd', 'modules',260                               'mod_dir.so')261            self.assert_exists(self.build_dir, 'httpd', 'modules',262                               'mod_env.so')263            self.assert_exists(self.build_dir, 'httpd', 'modules',264                               'mod_log_config.so')265            self.assert_exists(self.build_dir, 'httpd', 'modules',266                               'mod_mime.so')267            self.assert_exists(self.build_dir, 'httpd', 'modules',268                               'mod_mpm_event.so')269            self.assert_exists(self.build_dir, 'httpd', 'modules',270                               'mod_proxy.so')271            self.assert_exists(self.build_dir, 'httpd', 'modules',272                               'mod_proxy_fcgi.so')273            self.assert_exists(self.build_dir, 'httpd', 'modules',274                               'mod_reqtimeout.so')275            self.assert_exists(self.build_dir, 'httpd', 'modules',276                               'mod_unixd.so')277            self.assert_exists(self.build_dir, 'httpd', 'modules',278                               'mod_remoteip.so')279            # Test PHP280            self.assert_exists(self.build_dir, 'php')281            self.assert_exists(self.build_dir, 'php', 'etc')282            self.assert_exists(self.build_dir, 'php', 'etc', 'php-fpm.conf')283            self.assert_exists(self.build_dir, 'php', 'etc', 'php.ini')284            self.assert_exists(self.build_dir, 'php', 'sbin', 'php-fpm')285            self.assert_exists(self.build_dir, 'php', 'bin')286            self.assert_exists(self.build_dir, 'php', 'lib', 'php',287                               'extensions', 'no-debug-non-zts-20100525',288                               'bz2.so')289            self.assert_exists(self.build_dir, 'php', 'lib', 'php',290                               'extensions', 'no-debug-non-zts-20100525',291                               'zlib.so')292            self.assert_exists(self.build_dir, 'php', 'lib', 'php',293                               'extensions', 'no-debug-non-zts-20100525',294                               'curl.so')295            self.assert_exists(self.build_dir, 'php', 'lib', 'php',296                               'extensions', 'no-debug-non-zts-20100525',297                               'mcrypt.so')298            # Test NewRelic299            self.assert_exists(self.build_dir, 'newrelic')300            self.assert_exists(self.build_dir, 'newrelic', 'daemon',301                               'newrelic-daemon.x64')302            self.assert_exists(self.build_dir, 'newrelic', 'agent', 'x64',303                               'newrelic-20100525.so')304            with open(os.path.join(self.build_dir,305                                   'php', 'etc', 'php.ini'), 'rt') as php_ini:306                lines = php_ini.readlines()307            extn_path = '@{HOME}/newrelic/agent/x64/newrelic-20100525.so'308            eq_(True, lines.index('extension=%s\n' % extn_path) >= 0)309            eq_(True, lines.index('[newrelic]\n') >= 0)310            eq_(True, lines.index('newrelic.license=JUNK_LICENSE\n') >= 0)311            eq_(True, lines.index('newrelic.appname=app-name-1\n') >= 0)312        except Exception, e:313            print str(e)314            if hasattr(e, 'output'):315                print e.output316            if output:317                print output318            raise319        finally:320            if os.path.exists(bp.bp_dir):321                shutil.rmtree(bp.bp_dir)322class TestCompileNewRelicWithHHVM(BaseCompileNewRelic):323    def setUp(self):324        BaseCompileNewRelic.initialize(self, 'app-1')325    def tearDown(self):326        BaseCompileNewRelic.cleanup(self)327    def test_compile_httpd_with_newrelic(self):328        os.environ['NEWRELIC_LICENSE'] = 'JUNK_LICENSE'329        os.environ['VCAP_APPLICATION'] = json.dumps({330            'name': 'app-name-1'331        })332        bp = BuildPack({333            'BUILD_DIR': self.build_dir,334            'CACHE_DIR': self.cache_dir,335        }, '.')336        # simulate clone, makes debugging easier337        os.rmdir(bp.bp_dir)338        shutil.copytree('.', bp.bp_dir,339                        ignore=shutil.ignore_patterns("binaries",340                                                      "env",341                                                      "tests"))342        # set php & web server343        optsFile = os.path.join(bp.bp_dir, 'defaults', 'options.json')344        self._set_php(optsFile, 'hhvm')345        self._set_web_server(optsFile, 'httpd')346        try:347            output = ''348            output = bp._compile()349            outputLines = output.split('\n')350            eq_(16, len([l for l in outputLines351                         if l.startswith('Downloaded')]))352            eq_(2, len([l for l in outputLines if l.startswith('Installing')]))353            eq_(True, outputLines[-1].startswith('Finished:'))354            # Test scripts and config355            self.assert_exists(self.build_dir, 'start.sh')356            with open(os.path.join(self.build_dir, 'start.sh')) as start:357                lines = [line.strip() for line in start.readlines()]358                eq_(5, len(lines))359                eq_('export PYTHONPATH=$HOME/.bp/lib', lines[0])360                eq_('$HOME/.bp/bin/rewrite "$HOME/httpd/conf"', lines[1])361                eq_('$HOME/.bp/bin/rewrite "$HOME/.env"', lines[2])362                eq_('$HOME/.bp/bin/rewrite "$HOME/hhvm/etc"', lines[3])363                eq_('$HOME/.bp/bin/start', lines[4])364            # Check scripts and bp are installed365            self.assert_exists(self.build_dir, '.bp', 'bin', 'rewrite')366            self.assert_exists(self.build_dir, '.bp', 'lib')367            bpu_path = os.path.join(self.build_dir, '.bp', 'lib',368                                    'build_pack_utils')369            eq_(22, len(os.listdir(bpu_path)))370            self.assert_exists(bpu_path, 'utils.py')371            self.assert_exists(bpu_path, 'process.py')372            # Check env and procs files373            self.assert_exists(self.build_dir, '.env')374            self.assert_exists(self.build_dir, '.procs')375            with open(os.path.join(self.build_dir, '.env')) as env:376                lines = [line.strip() for line in env.readlines()]377                eq_(2, len(lines))378                eq_('HTTPD_SERVER_ADMIN=dan@mikusa.com', lines[0])379                eq_('LD_LIBRARY_PATH=@LD_LIBRARY_PATH:@HOME/hhvm',380                    lines[1])381            with open(os.path.join(self.build_dir, '.procs')) as procs:382                lines = [line.strip() for line in procs.readlines()]383                eq_(2, len(lines))384                eq_('httpd: $HOME/httpd/bin/apachectl -f '385                    '"$HOME/httpd/conf/httpd.conf" -k start -DFOREGROUND',386                    lines[0])387                eq_('hhvm: $HOME/hhvm/hhvm --mode server -c '388                    '$HOME/hhvm/etc/config.hdf', lines[1])389            # Check htdocs and config390            self.assert_exists(self.build_dir, 'htdocs')391            self.assert_exists(self.build_dir, '.bp-config')392            self.assert_exists(self.build_dir, '.bp-config', 'options.json')393            # Test HTTPD394            self.assert_exists(self.build_dir)395            self.assert_exists(self.build_dir, 'httpd')396            self.assert_exists(self.build_dir, 'httpd', 'conf')397            self.assert_exists(self.build_dir, 'httpd', 'conf', 'httpd.conf')398            self.assert_exists(self.build_dir, 'httpd', 'conf', 'extra')399            self.assert_exists(self.build_dir, 'httpd', 'conf',400                               'extra', 'httpd-modules.conf')401            self.assert_exists(self.build_dir, 'httpd', 'conf',402                               'extra', 'httpd-remoteip.conf')403            self.assert_exists(self.build_dir, 'httpd', 'modules',404                               'mod_authz_core.so')405            self.assert_exists(self.build_dir, 'httpd', 'modules',406                               'mod_authz_host.so')407            self.assert_exists(self.build_dir, 'httpd', 'modules',408                               'mod_dir.so')409            self.assert_exists(self.build_dir, 'httpd', 'modules',410                               'mod_env.so')411            self.assert_exists(self.build_dir, 'httpd', 'modules',412                               'mod_log_config.so')413            self.assert_exists(self.build_dir, 'httpd', 'modules',414                               'mod_mime.so')415            self.assert_exists(self.build_dir, 'httpd', 'modules',416                               'mod_mpm_event.so')417            self.assert_exists(self.build_dir, 'httpd', 'modules',418                               'mod_proxy.so')419            self.assert_exists(self.build_dir, 'httpd', 'modules',420                               'mod_proxy_fcgi.so')421            self.assert_exists(self.build_dir, 'httpd', 'modules',422                               'mod_reqtimeout.so')423            self.assert_exists(self.build_dir, 'httpd', 'modules',424                               'mod_unixd.so')425            self.assert_exists(self.build_dir, 'httpd', 'modules',426                               'mod_remoteip.so')427            # Test PHP428            self.assert_exists(self.build_dir, 'hhvm')429            self.assert_exists(self.build_dir, 'hhvm', 'hhvm')430            self.assert_exists(self.build_dir, 'hhvm', 'etc', 'config.hdf')431            self.assert_exists(self.build_dir, 'hhvm', 'libmemcached.so.11')432            self.assert_exists(self.build_dir, 'hhvm', 'libevent-1.4.so.2.2.0')433            self.assert_exists(self.build_dir, 'hhvm', 'libevent-1.4.so.2')434            self.assert_exists(self.build_dir, 'hhvm',435                               'libboost_system.so.1.55.0')436            self.assert_exists(self.build_dir, 'hhvm',437                               'libc-client.so.2007e.0')438            self.assert_exists(self.build_dir, 'hhvm', 'libstdc++.so.6')439            self.assert_exists(self.build_dir, 'hhvm', 'libMagickWand.so.2')440            self.assert_exists(self.build_dir, 'hhvm', 'libicui18n.so.48')441            # Test NewRelic (should not be installed with HHVM)442            eq_(False,443                os.path.exists(os.path.join(self.build_dir, 'newrelic')))444        except Exception, e:445            print str(e)446            if hasattr(e, 'output'):447                print e.output448            if output:449                print output450            raise451        finally:452            if os.path.exists(bp.bp_dir):...test_compile.py
Source:test_compile.py  
...33            if name.startswith('nginx-') and name.endswith('.gz'):34                os.remove(os.path.join(os.environ['TMPDIR'], name))35            if name.startswith('php-') and name.endswith('.gz'):36                os.remove(os.path.join(os.environ['TMPDIR'], name))37    def assert_exists(self, *args):38        eq_(True, os.path.exists(os.path.join(*args)),39            "Does not exists: %s" % os.path.join(*args))40class TestCompile(BaseTestCompile):41    def setUp(self):42        BaseTestCompile.initialize(self, 'app-1')43    def tearDown(self):44        BaseTestCompile.cleanup(self)45    def test_setup(self):46        eq_(True, os.path.exists(self.build_dir))47        eq_(False, os.path.exists(self.cache_dir))48        eq_(True, os.path.exists(os.path.join(self.build_dir, 'htdocs')))49    def test_compile_httpd(self):50        bp = BuildPack({51            'BUILD_DIR': self.build_dir,52            'CACHE_DIR': self.cache_dir53        }, '.')54        # simulate clone, makes debugging easier55        os.rmdir(bp.bp_dir)56        shutil.copytree('.', bp.bp_dir,57                        ignore=shutil.ignore_patterns("binaries",58                                                      "env",59                                                      "tests"))60        # set web server61        self.set_web_server(os.path.join(bp.bp_dir,62                                         'defaults',63                                         'options.json'),64                            'httpd')65        try:66            output = ''67            output = bp._compile()68            outputLines = output.split('\n')69            eq_(21, len([l for l in outputLines70                         if l.startswith('Downloaded')]))71            eq_(2, len([l for l in outputLines if l.startswith('Installing')]))72            eq_(True, outputLines[-1].startswith('Finished:'))73            # Test scripts and config74            self.assert_exists(self.build_dir, 'start.sh')75            with open(os.path.join(self.build_dir, 'start.sh')) as start:76                lines = [line.strip() for line in start.readlines()]77                eq_(5, len(lines))78                eq_('export PYTHONPATH=$HOME/.bp/lib', lines[0])79                eq_('$HOME/.bp/bin/rewrite "$HOME/httpd/conf"', lines[1])80                eq_('$HOME/.bp/bin/rewrite "$HOME/php/etc"', lines[2])81                eq_('$HOME/.bp/bin/rewrite "$HOME/.env"', lines[3])82                eq_('$HOME/.bp/bin/start', lines[4])83            # Check scripts and bp are installed84            self.assert_exists(self.build_dir, '.bp', 'bin', 'rewrite')85            self.assert_exists(self.build_dir, '.bp', 'lib')86            bpu_path = os.path.join(self.build_dir, '.bp', 'lib',87                                    'build_pack_utils')88            eq_(22, len(os.listdir(bpu_path)))89            self.assert_exists(bpu_path, 'utils.py')90            self.assert_exists(bpu_path, 'process.py')91            # Check env and procs files92            self.assert_exists(self.build_dir, '.env')93            self.assert_exists(self.build_dir, '.procs')94            with open(os.path.join(self.build_dir, '.env')) as env:95                lines = [line.strip() for line in env.readlines()]96                eq_(2, len(lines))97                eq_('HTTPD_SERVER_ADMIN=dan@mikusa.com', lines[0])98                eq_('LD_LIBRARY_PATH=@LD_LIBRARY_PATH:@HOME/php/lib',99                    lines[1])100            with open(os.path.join(self.build_dir, '.procs')) as procs:101                lines = [line.strip() for line in procs.readlines()]102                eq_(3, len(lines))103                eq_('httpd: $HOME/httpd/bin/apachectl -f '104                    '"$HOME/httpd/conf/httpd.conf" -k start -DFOREGROUND',105                    lines[0])106                eq_('php-fpm: $HOME/php/sbin/php-fpm -p "$HOME/php/etc" -y '107                    '"$HOME/php/etc/php-fpm.conf" -c "$HOME/php/etc"', lines[1])108                eq_('php-fpm-logs: tail -F $HOME/../logs/php-fpm.log',109                    lines[2])110            # Check htdocs and config111            self.assert_exists(self.build_dir, 'htdocs')112            self.assert_exists(self.build_dir, '.bp-config')113            self.assert_exists(self.build_dir, '.bp-config', 'options.json')114            # Test HTTPD115            self.assert_exists(self.build_dir)116            self.assert_exists(self.build_dir, 'httpd')117            self.assert_exists(self.build_dir, 'httpd', 'conf')118            self.assert_exists(self.build_dir, 'httpd', 'conf', 'httpd.conf')119            self.assert_exists(self.build_dir, 'httpd', 'conf', 'extra')120            self.assert_exists(self.build_dir, 'httpd', 'conf',121                               'extra', 'httpd-modules.conf')122            self.assert_exists(self.build_dir, 'httpd', 'conf',123                               'extra', 'httpd-remoteip.conf')124            self.assert_exists(self.build_dir, 'httpd', 'modules',125                               'mod_authz_core.so')126            self.assert_exists(self.build_dir, 'httpd', 'modules',127                               'mod_authz_host.so')128            self.assert_exists(self.build_dir, 'httpd', 'modules',129                               'mod_dir.so')130            self.assert_exists(self.build_dir, 'httpd', 'modules',131                               'mod_env.so')132            self.assert_exists(self.build_dir, 'httpd', 'modules',133                               'mod_log_config.so')134            self.assert_exists(self.build_dir, 'httpd', 'modules',135                               'mod_mime.so')136            self.assert_exists(self.build_dir, 'httpd', 'modules',137                               'mod_mpm_event.so')138            self.assert_exists(self.build_dir, 'httpd', 'modules',139                               'mod_proxy.so')140            self.assert_exists(self.build_dir, 'httpd', 'modules',141                               'mod_proxy_fcgi.so')142            self.assert_exists(self.build_dir, 'httpd', 'modules',143                               'mod_reqtimeout.so')144            self.assert_exists(self.build_dir, 'httpd', 'modules',145                               'mod_unixd.so')146            self.assert_exists(self.build_dir, 'httpd', 'modules',147                               'mod_remoteip.so')148            self.assert_exists(self.build_dir, 'httpd', 'modules',149                               'mod_rewrite.so')150            # Test PHP151            self.assert_exists(self.build_dir, 'php')152            self.assert_exists(self.build_dir, 'php', 'etc')153            self.assert_exists(self.build_dir, 'php', 'etc', 'php-fpm.conf')154            self.assert_exists(self.build_dir, 'php', 'etc', 'php.ini')155            self.assert_exists(self.build_dir, 'php', 'sbin', 'php-fpm')156            self.assert_exists(self.build_dir, 'php', 'bin')157            self.assert_exists(self.build_dir, 'php', 'lib', 'php',158                               'extensions', 'no-debug-non-zts-20100525',159                               'bz2.so')160            self.assert_exists(self.build_dir, 'php', 'lib', 'php',161                               'extensions', 'no-debug-non-zts-20100525',162                               'zlib.so')163            self.assert_exists(self.build_dir, 'php', 'lib', 'php',164                               'extensions', 'no-debug-non-zts-20100525',165                               'curl.so')166            self.assert_exists(self.build_dir, 'php', 'lib', 'php',167                               'extensions', 'no-debug-non-zts-20100525',168                               'mcrypt.so')169        except Exception, e:170            print str(e)171            if hasattr(e, 'output'):172                print e.output173            if output:174                print output175            raise176        finally:177            if os.path.exists(bp.bp_dir):178                shutil.rmtree(bp.bp_dir)179    def test_compile_nginx(self):180        bp = BuildPack({181            'BUILD_DIR': self.build_dir,182            'CACHE_DIR': self.cache_dir183        }, '.')184        # simulate clone, makes debugging easier185        os.rmdir(bp.bp_dir)186        shutil.copytree('.', bp.bp_dir,187                        ignore=shutil.ignore_patterns("binaries",188                                                      "env",189                                                      "tests"))190        # set web server191        self.set_web_server(os.path.join(bp.bp_dir,192                                         'defaults',193                                         'options.json'),194                            'nginx')195        try:196            output = ''197            output = bp._compile()198            # Test Output199            outputLines = output.split('\n')200            eq_(7, len([l for l in outputLines if l.startswith('Downloaded')]))201            eq_(2, len([l for l in outputLines if l.startswith('Installing')]))202            eq_(True, outputLines[-1].startswith('Finished:'))203            # Test scripts and config204            self.assert_exists(self.build_dir, 'start.sh')205            with open(os.path.join(self.build_dir, 'start.sh')) as start:206                lines = [line.strip() for line in start.readlines()]207                eq_(5, len(lines))208                eq_('export PYTHONPATH=$HOME/.bp/lib', lines[0])209                eq_('$HOME/.bp/bin/rewrite "$HOME/nginx/conf"', lines[1])210                eq_('$HOME/.bp/bin/rewrite "$HOME/php/etc"', lines[2])211                eq_('$HOME/.bp/bin/rewrite "$HOME/.env"', lines[3])212                eq_('$HOME/.bp/bin/start', lines[4])213            # Check scripts and bp are installed214            self.assert_exists(self.build_dir, '.bp', 'bin', 'rewrite')215            self.assert_exists(self.build_dir, '.bp', 'lib')216            bpu_path = os.path.join(self.build_dir, '.bp', 'lib',217                                    'build_pack_utils')218            eq_(22, len(os.listdir(bpu_path)))219            self.assert_exists(bpu_path, 'utils.py')220            self.assert_exists(bpu_path, 'process.py')221            # Check env and procs files222            self.assert_exists(self.build_dir, '.env')223            self.assert_exists(self.build_dir, '.procs')224            with open(os.path.join(self.build_dir, '.env')) as env:225                lines = [line.strip() for line in env.readlines()]226                eq_(1, len(lines))227                eq_('LD_LIBRARY_PATH=@LD_LIBRARY_PATH:@HOME/php/lib',228                    lines[0])229            with open(os.path.join(self.build_dir, '.procs')) as procs:230                lines = [line.strip() for line in procs.readlines()]231                eq_(3, len(lines))232                eq_('nginx: $HOME/nginx/sbin/nginx -c '233                    '"$HOME/nginx/conf/nginx.conf"', lines[0])234                eq_('php-fpm: $HOME/php/sbin/php-fpm -p "$HOME/php/etc" -y '235                    '"$HOME/php/etc/php-fpm.conf" -c "$HOME/php/etc"', lines[1])236                eq_('php-fpm-logs: tail -F $HOME/../logs/php-fpm.log',237                    lines[2])238            # Test htdocs & config239            self.assert_exists(self.build_dir, 'htdocs')240            self.assert_exists(self.build_dir, '.bp-config')241            self.assert_exists(self.build_dir, '.bp-config', 'options.json')242            # Test NGINX243            self.assert_exists(self.build_dir)244            self.assert_exists(self.build_dir, 'nginx')245            self.assert_exists(self.build_dir, 'nginx', 'conf')246            self.assert_exists(self.build_dir, 'nginx', 'conf',247                               'fastcgi_params')248            self.assert_exists(self.build_dir, 'nginx', 'conf',249                               'http-logging.conf')250            self.assert_exists(self.build_dir, 'nginx', 'conf',251                               'http-defaults.conf')252            self.assert_exists(self.build_dir, 'nginx', 'conf',253                               'http-php.conf')254            self.assert_exists(self.build_dir, 'nginx', 'conf',255                               'mime.types')256            self.assert_exists(self.build_dir, 'nginx', 'conf',257                               'nginx-defaults.conf')258            self.assert_exists(self.build_dir, 'nginx', 'conf',259                               'nginx-workers.conf')260            self.assert_exists(self.build_dir, 'nginx', 'conf',261                               'nginx.conf')262            self.assert_exists(self.build_dir, 'nginx', 'conf',263                               'server-defaults.conf')264            self.assert_exists(self.build_dir, 'nginx', 'conf',265                               'server-locations.conf')266            self.assert_exists(self.build_dir, 'nginx', 'logs')267            self.assert_exists(self.build_dir, 'nginx', 'sbin')268            self.assert_exists(self.build_dir, 'nginx', 'sbin', 'nginx')269            with open(os.path.join(self.build_dir,270                                   'nginx',271                                   'conf',272                                   'http-php.conf')) as fin:273                data = fin.read()274                eq_(-1, data.find('#{PHP_FPM_LISTEN}'))275                eq_(-1, data.find('{TMPDIR}'))276            # Test PHP277            self.assert_exists(self.build_dir, 'php')278            self.assert_exists(self.build_dir, 'php', 'etc')279            self.assert_exists(self.build_dir, 'php', 'etc', 'php-fpm.conf')280            self.assert_exists(self.build_dir, 'php', 'etc', 'php.ini')281            self.assert_exists(self.build_dir, 'php', 'sbin', 'php-fpm')282            self.assert_exists(self.build_dir, 'php', 'bin')283            self.assert_exists(self.build_dir, 'php', 'lib', 'php',284                               'extensions', 'no-debug-non-zts-20100525',285                               'bz2.so')286            self.assert_exists(self.build_dir, 'php', 'lib', 'php',287                               'extensions', 'no-debug-non-zts-20100525',288                               'zlib.so')289            self.assert_exists(self.build_dir, 'php', 'lib', 'php',290                               'extensions', 'no-debug-non-zts-20100525',291                               'curl.so')292            self.assert_exists(self.build_dir, 'php', 'lib', 'php',293                               'extensions', 'no-debug-non-zts-20100525',294                               'mcrypt.so')295        except Exception, e:296            print str(e)297            if hasattr(e, 'output'):298                print e.output299            if output:300                print output301            raise302        finally:303            if os.path.exists(bp.bp_dir):304                shutil.rmtree(bp.bp_dir)305class TestCompileStandAlone(BaseTestCompile):306    def setUp(self):307        BaseTestCompile.initialize(self, 'app-5')308    def tearDown(self):309        BaseTestCompile.cleanup(self)310    def test_compile_stand_alone(self):311        bp = BuildPack({312            'BUILD_DIR': self.build_dir,313            'CACHE_DIR': self.cache_dir314        }, '.')315        # simulate clone, makes debugging easier316        os.rmdir(bp.bp_dir)317        shutil.copytree('.', bp.bp_dir,318                        ignore=shutil.ignore_patterns("binaries",319                                                      "env",320                                                      "tests"))321        # set web server & php version322        optsFile = os.path.join(bp.bp_dir, 'defaults', 'options.json')323        self.set_web_server(optsFile, 'none')324        self.set_php_version(optsFile, '5.4.27')325        try:326            output = ''327            output = bp._compile()328            # Test Output329            outputLines = output.split('\n')330            eq_(6, len([l for l in outputLines if l.startswith('Downloaded')]))331            eq_(1, len([l for l in outputLines if l.startswith('No Web')]))332            eq_(1, len([l for l in outputLines333                        if l.startswith('Installing PHP')]))334            eq_(1, len([l for l in outputLines if l.find('php-cli') >= 0]))335            eq_(True, outputLines[-1].startswith('Finished:'))336            # Test scripts and config337            self.assert_exists(self.build_dir, 'start.sh')338            with open(os.path.join(self.build_dir, 'start.sh')) as start:339                lines = [line.strip() for line in start.readlines()]340                eq_(4, len(lines))341                eq_('export PYTHONPATH=$HOME/.bp/lib', lines[0])342                eq_('$HOME/.bp/bin/rewrite "$HOME/php/etc"', lines[1])343                eq_('$HOME/.bp/bin/rewrite "$HOME/.env"', lines[2])344                eq_('$HOME/.bp/bin/start', lines[3])345            # Check scripts and bp are installed346            self.assert_exists(self.build_dir, '.bp', 'bin', 'rewrite')347            self.assert_exists(self.build_dir, '.bp', 'lib')348            bpu_path = os.path.join(self.build_dir, '.bp', 'lib',349                                    'build_pack_utils')350            eq_(22, len(os.listdir(bpu_path)))351            self.assert_exists(bpu_path, 'utils.py')352            self.assert_exists(bpu_path, 'process.py')353            # Check env and procs files354            self.assert_exists(self.build_dir, '.env')355            self.assert_exists(self.build_dir, '.procs')356            with open(os.path.join(self.build_dir, '.env')) as env:357                lines = [line.strip() for line in env.readlines()]358                eq_(1, len(lines))359                eq_('LD_LIBRARY_PATH=@LD_LIBRARY_PATH:@HOME/php/lib',360                    lines[0])361            with open(os.path.join(self.build_dir, '.procs')) as procs:362                lines = [line.strip() for line in procs.readlines()]363                eq_(1, len(lines))364                eq_('php-app: $HOME/php/bin/php -c "$HOME/php/etc" '365                    'app.php', lines[0])366            # Test PHP367            self.assert_exists(self.build_dir, 'php')368            self.assert_exists(self.build_dir, 'php', 'etc')369            self.assert_exists(self.build_dir, 'php', 'etc', 'php.ini')370            self.assert_exists(self.build_dir, 'php', 'bin')371            self.assert_exists(self.build_dir, 'php', 'bin', 'php')372            self.assert_exists(self.build_dir, 'php', 'bin', 'phar.phar')373            self.assert_exists(self.build_dir, 'php', 'lib', 'php',374                               'extensions', 'no-debug-non-zts-20100525',375                               'bz2.so')376            self.assert_exists(self.build_dir, 'php', 'lib', 'php',377                               'extensions', 'no-debug-non-zts-20100525',378                               'zlib.so')379            self.assert_exists(self.build_dir, 'php', 'lib', 'php',380                               'extensions', 'no-debug-non-zts-20100525',381                               'curl.so')382            self.assert_exists(self.build_dir, 'php', 'lib', 'php',383                               'extensions', 'no-debug-non-zts-20100525',384                               'mcrypt.so')385        except Exception, e:386            print str(e)387            if hasattr(e, 'output'):388                print e.output389            if output:390                print output391            raise392        finally:393            if os.path.exists(bp.bp_dir):...test_compile_helpers.py
Source:test_compile_helpers.py  
...25            if name.startswith('httpd-') and name.endswith('.gz'):26                os.remove(os.path.join(os.environ['TMPDIR'], name))27            if name.startswith('php-') and name.endswith('.gz'):28                os.remove(os.path.join(os.environ['TMPDIR'], name))29    def assert_exists(self, *args):30        eq_(True, os.path.exists(os.path.join(*args)),31            "Does not exists: %s" % os.path.join(*args))32    @with_setup(setup=setUp, teardown=tearDown)33    def test_setup_if_htdocs_exists(self):34        shutil.copytree('tests/data/app-1', self.build_dir)35        setup_htdocs_if_it_doesnt_exist(utils.FormattedDict({36            'BUILD_DIR': self.build_dir37        }))38        self.assert_exists(self.build_dir, 'htdocs')39        self.assert_exists(self.build_dir, 'htdocs', 'index.php')40        self.assert_exists(self.build_dir, 'htdocs', 'info.php')41        self.assert_exists(self.build_dir, 'htdocs',42                           'technical-difficulties1.jpg')43        self.assert_exists(self.build_dir, '.bp-config')44        self.assert_exists(self.build_dir, '.bp-config', 'options.json')45        self.assert_exists(self.build_dir, '.bp-config', 'httpd', 'extra',46                           'httpd-remoteip.conf')47        eq_(2, len(os.listdir(self.build_dir)))48        eq_(3, len(os.listdir(os.path.join(self.build_dir, 'htdocs'))))49    @with_setup(setup=setUp, teardown=tearDown)50    def test_setup_if_htdocs_does_not_exist(self):51        shutil.copytree('tests/data/app-2', self.build_dir)52        setup_htdocs_if_it_doesnt_exist(utils.FormattedDict({53            'BUILD_DIR': self.build_dir54        }))55        self.assert_exists(self.build_dir, 'htdocs')56        self.assert_exists(self.build_dir, 'htdocs', 'index.php')57        self.assert_exists(self.build_dir, 'htdocs', 'info.php')58        self.assert_exists(self.build_dir, 'htdocs',59                           'technical-difficulties1.jpg')60        self.assert_exists(self.build_dir, '.bp-config')61        self.assert_exists(self.build_dir, '.bp-config', 'options.json')62        self.assert_exists(self.build_dir, '.bp-config', 'httpd', 'extra',63                           'httpd-remoteip.conf')64        eq_(2, len(os.listdir(self.build_dir)))65        eq_(3, len(os.listdir(os.path.join(self.build_dir, 'htdocs'))))66    @with_setup(setup=setUp, teardown=tearDown)67    def test_setup_if_htdocs_does_not_exist_with_extensions(self):68        shutil.copytree('tests/data/app-4', self.build_dir)69        setup_htdocs_if_it_doesnt_exist(utils.FormattedDict({70            'BUILD_DIR': self.build_dir71        }))72        self.assert_exists(self.build_dir, 'htdocs')73        self.assert_exists(self.build_dir, 'htdocs', 'index.php')74        self.assert_exists(self.build_dir, 'htdocs', 'info.php')75        self.assert_exists(self.build_dir, 'htdocs',76                           'technical-difficulties1.jpg')77        self.assert_exists(self.build_dir, '.bp-config')78        self.assert_exists(self.build_dir, '.bp-config', 'options.json')79        self.assert_exists(self.build_dir, '.bp-config', 'httpd', 'extra',80                           'httpd-remoteip.conf')81        self.assert_exists(self.build_dir, '.bp')82        self.assert_exists(self.build_dir, '.bp', 'logs')83        self.assert_exists(self.build_dir, '.bp', 'logs', 'some.log')84        self.assert_exists(self.build_dir, '.extensions')85        self.assert_exists(self.build_dir, '.extensions', 'some-ext')86        self.assert_exists(self.build_dir, '.extensions', 'some-ext',87                           'extension.py')88        eq_(4, len(os.listdir(self.build_dir)))89        eq_(3, len(os.listdir(os.path.join(self.build_dir, 'htdocs'))))90    def test_setup_if_htdocs_with_stand_alone_app(self):91        shutil.copytree('tests/data/app-5', self.build_dir)92        setup_htdocs_if_it_doesnt_exist(utils.FormattedDict({93            'BUILD_DIR': self.build_dir,94            'WEB_SERVER': 'none'95        }))96        self.assert_exists(self.build_dir, 'app.php')97        eq_(1, len(os.listdir(self.build_dir)))98    def test_convert_php_extensions_54(self):99        ctx = {100            'PHP_VERSION': '5.4.x',101            'PHP_EXTENSIONS': ['mod1', 'mod2', 'mod3'],102            'ZEND_EXTENSIONS': ['zmod1', 'zmod2']103        }104        convert_php_extensions(ctx)105        eq_('extension=mod1.so\nextension=mod2.so\nextension=mod3.so',106            ctx['PHP_EXTENSIONS'])107        eq_('zend_extension="@HOME/php/lib/php/extensions/'108            'no-debug-non-zts-20100525/zmod1.so"\n'109            'zend_extension="@HOME/php/lib/php/extensions/'110            'no-debug-non-zts-20100525/zmod2.so"',...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
