Support #600

python vs c++ tests

Added by Rogers, Chris over 12 years ago. Updated over 12 years ago.

Target version:
Start date:
26 July 2011
Due date:
% Done:


Estimated time:


Email exchange


Dear Chris,

First, I had some Python unit testing question. As I told you last week, I
am writing the unit tests for Digitization and Space points (in Python
as you suggested). I am trying to write a test function in the python file
for a function in Digitization (C++) that takes in 2 arguments that are
Json::Value (like Json objects). So when I am creating test Json objects
the python file and try to 'test' them (i.e. call the function in
Digitization), python complains (says something like Error Type, second
argument of Json Value). Here are the 3 lines of code I am talking about:

testJson1 = '{"channel_id":[{"tracker_number":0,
"channel_number": 0}]}'
testJson2 = '{"channel_id":[{"tracker_number":0,
"channel_number": 0}]}'
test1 = json.loads(testJson1)
test2 = json.loads(testJson2)
self.assertTrue(self.mapper.Check_param(test1, test2))

I was just wondering whether you think there might be a problem with
a Json object created in python to a function in C++...


Can you attach:

The map code
The test code
Full copy of the output

How are you finding the process of testing C++ code in python? Is it

Attached is the all the code and the output of the test (the error I
get). Once again, thanks a lot for the help!

I wouldn't say that testing C++ code in python is too painful.. One of
my biggest problems is that I am a lot less familiar with python than
with C++. Also, I feel like there are certain things that C++ uses
that Python doesn't really have.. For example, the other day I was
trying to find a way to pass a pointer in a Python function, and I
couldn't really find a way to do that either..

Best regards,

Files (11.6 KB) Rogers, Chris, 26 July 2011 08:14
MapCppTrackerDigitization.hh (4.01 KB) MapCppTrackerDigitization.hh Rogers, Chris, 26 July 2011 08:14 (2.67 KB) Rogers, Chris, 26 July 2011 08:14
Test_output (791 Bytes) Test_output Rogers, Chris, 26 July 2011 08:14

Updated by Rogers, Chris over 12 years ago

Yeah, I don't think SWIG is clever enough to convert from python dict to json::Value. I think the only way is to make a small wrapper function that takes a std::string and converts to Json::Value to do the test. A bit of a pain...


Updated by Rogers, Chris over 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF