Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58237

Re: Testing python command line apps -- Running from within the projects w/o installing

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 <self@gkayaalp.com>
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 Göktuğ Kayaalp <self@gkayaalp.com>
To Ben Finney <ben+python@benfinney.id.au>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1907.1383279056.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Nov 01, 2013 at 10:42:23AM +1100, Ben Finney wrote:
> Göktuğ Kayaalp <self@gkayaalp.com> 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 “if __name__ == '__main__':” to an absolute 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__ == '__main__': exit(main.main(sys.argv[1:]))
    (app) ~/app% scripts/app -CMdargs -- testdata.txt
    Traceback (most recent call last):
      File "app", line 1, in <module>
        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
> <URL:http://www.artima.com/weblogs/viewpost.jsp?thread=4829>.

I'll definitely give this a read.

> [...]

cheers,
	göktuğ

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Testing python command line apps -- Running from within the projects w/o installing Göktuğ Kayaalp <self@gkayaalp.com> - 2013-11-01 06:10 +0200

csiph-web