473,320 Members | 1,845 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,320 software developers and data experts.

testing C code with python

Hi,

A simple question - Is it common/good practice to test C code using
Python? For example one could wrap individual C functions, and test
each of them using python, maybe not for low-level things but at least
for algorithmic correctness. Anyone effectively doing this as common
practice?

Thanks,
Bahadir

Nov 10 '05 #1
4 4104
Bi*************@gmail.com wrote:
A simple question - Is it common/good practice to test C code using
Python? For example one could wrap individual C functions, and test
each of them using python, maybe not for low-level things but at least
for algorithmic correctness. Anyone effectively doing this as common
practice?


I doubt this is common practice (in general), but at a previous company
we developed a tool that let us write tests in Python, which would then
call into C code which was executing in the form of object code (in an
S19 file) running inside a simulated microcontroller CPU (68HC12) which
was itself implemented in Python.

I realize that doesn't help you, but I just thought I'd mention it,
because it was a heck of a lot of fun writing it. :-)

-Peter
Nov 11 '05 #2
On 11/10/05, Peter Hansen <pe***@engcorp.com> wrote:
Bi*************@gmail.com wrote:
A simple question - Is it common/good practice to test C code using
Python? For example one could wrap individual C functions, and test
each of them using python, maybe not for low-level things but at least
for algorithmic correctness. Anyone effectively doing this as common
practice?


Take a look at swig.org

There are some examples for testing C code y python and/or extend
python with C functions.
Nov 11 '05 #3
>Bi*************@gmail.com wrote:
A simple question - Is it common/good practice to test C code using
Python?


I certainly do such testing (hand-wrapped, because it doesn't
seem to cost too much time to do so. Usually I develop in Python
and accumulate my tests there, then write the C equivalent, and
move the tests to the C code. I've done this for programs that
were always to have become C programs as well as for those things
I intend to wrap as Python modules.

--
-Scott David Daniels
sc***********@acm.org
Nov 11 '05 #4
I have recently started using tcl to do this with C++ code and will
soon be switching to doing it with python.

I think it is a fantastic way to arrange to test C++ and C code.
Python makes an excellent test-harness, and writing interfaces for
complex units of C++ code to enable them to be tested from Python is an
valuable exercise in itself. It forces you to make your code
inspectable and brings up all sorts of important design issues that
otherwise would never occur to you.

It was a lot of work to get started with this but once you put in the
initial effort, it gets eaiser to maintiain. And the payoff is that it
lets you write regression tests easily so that would be too hard to do
otherwise.

Nov 11 '05 #5

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

Similar topics

11
by: rhat | last post by:
Hi Everyone, I've recently been reading some articles about unit-testing in Python , but I am a bit confused: where do I go to get started with this? I tried googling for "unittest" but all I've...
38
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the...
27
by: brad | last post by:
Does anyone else feel that unittesting is too much work? Not in general, just the official unittest module for small to medium sized projects? It seems easier to write some quick methods that are...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
4
by: David | last post by:
Hi list. Do test-driven development or behaviour-driven development advocate how to do higher-level testing than unit testing? types of testing: unit integration system
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
by: Alexnb | last post by:
Timothy Grant wrote: well I can tel you it didn't work for me. In fact I didn't see the code you posted on there, I ended up figuring it out on my own with a little help from the missing manual...
2
by: Edwin.Madari | last post by:
use re module import re template = '^My name is alex' astring = 'My name is alex, and I like pie' if re.match(template, astring): print 'Found it' else: print '%s does not begin with %s' %...
3
by: David Moss | last post by:
Hopefully a service like this already exists and I just haven't found it yet. If not it could be an idea for some kind soul(s) to pick up and run with ;-) As someone who writes and releases...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.