473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Testing functions via command line

There must be a couple of lines that will replace the following:
>From the shell command line I wanted to send data to a specific
function inside my module and execute that function in order to test
it separately from the rest of the module. I know pdb will allow me to
insert data into a running process, but this particular function
requires several long steps beforehand.

My command line:

myprog.py --test removefromcue "myargs" ### removefromcue is
my function inside myprog.py
main()
....
try:
opts, args = getopt.getopt(sys.argv[1:], "t:", ["--test="])
except getopt.GetoptError:
for o, a in opts:
if o in "-t":
myfunc = a
myargs = args
test(myfunc, myargs)
sys.exit()
My problem was that I send a string into the the test function. I
needed to convert that string into the appropriate object. globals()
provides a dictionary with string:object pairs in the global
namespace.

def test(myfunc, myargs):
""" execute a given function """
for key,value in globals().items():
if myfunc in key:
func = value
break
args = ""
for i in myargs:
args += i + ","
func(args[:-1]) ### removefromcue("myitem")

There's something very basic that I should know.

Apr 3 '07 #1
1 1257
On Mon, 02 Apr 2007 22:32:26 -0700, pelon wrote:
There must be a couple of lines that will replace the following:
Yes, because otherwise the terrorists will have won. *wink*
From the shell command line I wanted to send data to a specific
function inside my module and execute that function in order to test
it separately from the rest of the module.
For manual testing, why don't you do your testing from the interactive
Python shell?

e.g.

$ python
Python 2.3.4 (#1, Oct 11 2006, 06:18:43)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
import my_module
my_module.function('something') # test the function
Am I missing something?

Also, while your self-test code is very ingenious, perhaps you would be
better off using standard testing modules. Perhaps you should use the
doctest and/or unittest modules.

--
Steven D'Aprano

Apr 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Norbert Munkel | last post by:
Hi, If I try the new table functions get_dbm_cfg or get_db_cfg on a 8.2 (upgraded from 8.1.6) I always get the following Error: DB21034E The command was processed as an SQL statement because...
3
by: Kevin Burton | last post by:
I am trying to use managed C++ but I am getting the following link errors: Metadata file 'D:\Projects\Visa\AddressVerification\AddressVerificat...
14
by: Alan Silver | last post by:
Hello, I have spent ages trawling through Google, looking for information about global functions in ASP.NET and I'm still not clear about the best way to go about this (or not). I am writing...
2
by: David A. Osborn | last post by:
I'm writing a console program that takes input via the command line. Is there a way to pass these command line parameters while testing in Visual Studio? It's a real pain to keep creating the...
12
by: Bo Peng | last post by:
Dear list, Is there a better way than doing try: import aModule except: has_aModule = False else: has_aModule = True
15
by: AmmarN | last post by:
Hi all, I have a c++ programme that intakes a binary file and performs various operations on it. I am not gonna get in to the details of the operations, currently i specify the order in which the...
30
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just...
3
by: NaN | last post by:
I've been trying to use _kbhit() but it didn't do what I thought it would from books, "Detects whether a keypress is available for reading." Herbert Schildt says, "If the user has pressed a key,...
0
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.