JeanSebTr/node-python — pull request #10 by mateodelnorte (2014-08-11 16:30:26+00:00)
Title: Improved error handling, fixed array->list translation, added mocha tests

***
Note: There's an outstanding issue that needs to be solved before this is merged, located at https://github.com/JeanSebTr/node-python/issues/9.
***

I've improved error handling to provide traceback errors for errors occurred during python runtime. They look like:

```
1) bondmath BondCalculator calc w/ getHedgeRatio calculates the correct hedge ratio for a bond and its benchmark:
TypeError: Python Error: TypeError: unsupported operand type(s) for +: 'float' and 'Decimal'

Traceback (most recent call last):
File "/Users/matt/development/electronifie/scratch/bondmath/bondpy/code/tests/helper.py", line 75, in calc
bond_rslts['hedgeRatio'] = getHedgeRatio(trade_date, corp, treasury, config)
File "/Users/matt/development/electronifie/scratch/bondmath/bondpy/code/tests/helper.py", line 88, in getHedgeRatio
corp_dv01 = corp.calc(trade_date, config['bond'], calcs=['dv01'])['dv01']
File "/Users/matt/development/electronifie/scratch/bondmath/bondpy/code/bondmodels/bond.py", line 79, in calc
pv_df_1 = calc_setup(self.cashflows, rslts['yield'] + Decimal('0.0001'), settle_dt)
TypeError: unsupported operand type(s) for +: 'float' and 'Decimal'

at Object.getHedgeRatio (/Users/matt/development/electronifie/scratch/bondmath/index.js:27:33)
at Context. (/Users/matt/development/electronifie/scratch/bondmath/test/index.js:31:41)
at callFn (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runnable.js:247:21)
at Test.Runnable.run (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runnable.js:240:7)
at Runner.runTest (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:373:10)
at /Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:451:12
at next (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:298:14)
at /Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:308:7
at next (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:246:23)
at Object._onImmediate (/Users/matt/development/electronifie/scratch/bondmath/node_modules/mocha/lib/runner.js:275:5)
at processImmediate [as _immediateCallback] (timers.js:336:15)
```

In V8, an Array is an Object. As a result, there was an ordering problem in the logic for checking to see if a variable is an object and then checking if it was an array. This was causing all arrays to convert to python dictionaries. It's now converting to lists correctly.

I added mocha tests to start adding some stability to the lib. They look like:

```
node-python
eval
✓ should return resulting value from python statement executed
✓ should return resulting value from python statement executed, converting to string with complex types
import
✓ should return object representing module imported, containing functions from imported module
✓ should throw a PythonError when importing a module that does not exist
✓ should throw an Error when importing a module that includes bad syntax

5 passing (28ms)
```