Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'read.': 0.03; 'interfaces': 0.04; 'guido': 0.05; 'explicit': 0.07; 'importerror:': 0.07; 'subject: -- ': 0.07; 'sys': 0.07; '__name__': 0.09; 'inserts': 0.09; 'rossum': 0.09; 'setup.py': 0.09; 'subject:command': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "'__main__':": 0.16; 'developing,': 0.16; 'filename:fname piece:signature': 0.16; 'finney': 0.16; 'itself,': 0.16; 'modules,': 0.16; 'path.': 0.16; 'received:72.5': 0.16; 'received:72.5.230': 0.16; 'received:sender1.zohomail.com': 0.16; 'received:zohomail.com': 0.16; 'script,': 0.16; 'set-up': 0.16; 'subject: \n ': 0.16; 'subject:projects': 0.16; 'url:thread': 0.16; 'url:weblogs': 0.16; 'w/o': 0.16; 'subject:python': 0.16; 'apps': 0.16; 'wrote:': 0.18; 'app': 0.19; 'module': 0.19; 'command': 0.22; 'import': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'example.': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; 'subject:/': 0.26; 'asking': 0.27; 'van': 0.27; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'wonder': 0.29; 'absolute': 0.30; "i'm": 0.30; "skip:' 10": 0.31; 'usually': 0.31; 'parameters.': 0.31; 'writes:': 0.31; 'file': 0.32; 'front': 0.32; 'run': 0.32; 'running': 0.33; '(most': 0.33; 'fri,': 0.33; 'skip:# 10': 0.33; 'subject:the': 0.34; 'subject:from': 0.34; 'advice': 0.35; 'test': 0.35; 'but': 0.35; "i'll": 0.36; 'similar': 0.36; 'project': 0.37; 'clear': 0.37; 'ben': 0.38; 'nov': 0.38; 'recent': 0.39; 'how': 0.40; 'from:charset:utf-8': 0.61; 'content-disposition:inline': 0.62; 'more': 0.64; 'within': 0.65; 'license': 0.66; 'url:jsp': 0.68; '8bit%:21': 0.69; 'manner': 0.72; 'article': 0.77; 'adapted': 0.84; 'discrete': 0.84; 'subject:Testing': 0.84; '2013': 0.98 Date: Fri, 1 Nov 2013 06:10:43 +0200 From: =?utf-8?B?R8O2a3R1xJ8=?= Kayaalp To: Ben Finney Subject: Re: Testing python command line apps -- Running from within the projects w/o installing References: <20131031201207.GA9547@proxima.centauri> <7w1u310zz4.fsf@benfinney.id.au> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OgqxwSJOaUobr8KG" Content-Disposition: inline In-Reply-To: <7w1u310zz4.fsf@benfinney.id.au> User-Agent: Mutt/1.5.21 (2010-09-15) X-Zoho-Virus-Status: 1 X-ZohoMailClient: External Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383279056 news.xs4all.nl 15865 [2001:888:2000:d::a6]:54313 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58237 --OgqxwSJOaUobr8KG Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 01, 2013 at 10:42:23AM +1100, Ben Finney wrote: > G=C3=B6ktu=C4=9F Kayaalp writes: > > > I'm using python to write command line apps from time to time. I > > wonder *what is the conventional way to test-run these apps from > > within the project itself, while developing, without installing*. > > [So] the advice for testing the program's main module specialises to: Keep > the body of =E2=80=9Cif __name__ =3D=3D '__main__':=E2=80=9D to an absolu= te minimum. Put all > of the set-up and process-end functionality into discrete functions with > discrete purposes, clear return values, and explicit parameters. This is usually the way I write my modules, and I do test my command line interfaces in a manner similar to your example. But what I was asking is how to actually run these programs within a command shell session and test them in a more *tangible* fashion: (app) ~/app% ls scripts/ app/ tests/ setup.py LICENSE README (app) ~/app% cat scripts/app #!/usr/bin/env python from app import main; import sys if __name__ =3D=3D '__main__': exit(main.main(sys.argv[1:])) (app) ~/app% scripts/app -CMdargs -- testdata.txt Traceback (most recent call last): File "app", line 1, in from app import main; import sys ImportError: no module named 'app' I write a secondary script, 'app_tester', which is similar to 'app', but before running app.main.main, it inserts ~/app to the front of sys.path. What I want to find out is how to achieve this w/o having a secondary script that manipulates the path. > This is adapted from an article by Guido van Rossum > . I'll definitely give this a read. > [...] cheers, g=C3=B6ktu=C4=9F --OgqxwSJOaUobr8KG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) iQIcBAEBAgAGBQJScynCAAoJEMWnx0cuRfJTPocP/iGXs14YhxiixzwIN3lbU2OY YQ0aW9ecN6g1hZJxpmr4hTgdJtXaSG6drMK9RHbIM8V2o/xlQHqH3GNdgZyF3OvX B4kKXloQ1wNddZmhoZGQ19XB/vLu22bboCxq78fpws+wq5Xj3yDBJtxgqozOz+fD P2AqpFPqNAN6mRiprTxjOoF1y3zVXKLgNRmJGnigrIFwGHFAOLKOnDHBxaut9bT7 0IQXH2E6O7xksx0UyXb7ohdRh2rlTmTyCrFIdRN7ZuEWucXM/34BEdu3I+uRgGBI 9fZofou/uM+kyzAJP2V03hnRuPeLwdPn8W45zdSS52+BKlWancQ7RSbi8RMlVxmu 83RHVDdZvyv/hN0CQb8/I9FgRMWoQ69DLOMD8jfeUR6UFtvj6kOPJdsYwpV7Ep5F Um8Abgt6xS037u53VMgZ9NpYW4vPR49dofVC19+e2aesoXzVK3ZoQS4KvgamoNli +nQlpIZ99xmTCDwfFjuiMUj+bUvGeYfr0KUH77CDeHpo9NID2QFw2dg3KNEKSjhv fY7U6mossayXji03c+reNiHeQk5dXei6zzuTMMrmeNnxAHdBiR3Ob9IDaIysrazn ER13YkZ/21Vxujxog3I8k3iqxw9anAjlAa/8A191d6REnBmwNwNJyQtonWTUmKsz WmtoV6Y7ZWlOYd73O1ED =nJJc -----END PGP SIGNATURE----- --OgqxwSJOaUobr8KG--