pyne/pyne — pull request #223 by kmanalo (2013-12-11 21:33:55+00:00)
Title: Surface Source 'Header' Reader supporting MCNP Versions=X/5/6

There are subtle changes to data lengths going from MCNP5 to MCNPX (e.g. change in byte length for loddat, change in data type) and MCNP6 adds in one extra binary Fortran read that did not exist before - how annoying!

Anyways, I wanted to throw in support for various changes to the formats as I work with the different version of MCNP quite frequently and desired to fix the header issue (mostly as members in our workgroup want to insert surface sources from other codes).

The main thrust is shown with pseudo-code below:

if MCNP5/X # not MCNP6
alter header storage against 5 or X
else
header storage with MCNP6

Adding 6 unit tests (really just 3 new tests but twice for each added files

mcnp5_surfsrc.w # moved from mcnp_surfsrc.w
mcnpx_surfsrc.w # new, adds 3 unit tests
mcnp6_surfsrc.w # new, adds 3 unit tests

The unit test that I alter are in `TestSurfSrc`

1. test_read_header_block
2. test_compare
3. test_put_header_block

One reason that `unittest.TestCase` was not subclassed was because I wanted to count each new write file as a separate test, under the old format, the number of tests was not increased. See link for reasoning:
http://stackoverflow.com/questions/6689537/nose-test-generators-inside-class
As for this specific `TestSurfSrc` class I call `nose.tools.assert_equal` where `self.assertEqual` was previously, and etc. for similar calls. I added tests specific to the new file changes. There may be better ways to hash out these unit tests but the generator usage seems to work well without adding too much overhead.

Running `nosetests --with-nicedots test_mcnp.py` (Note: to match output like below I changed a few lines in the handy plugin by kumar303/nose-nicedots, see https://github.com/kmanalo/nose-nicedots/, clone and install with `python setup.py install --user`)

**Before**:
```
test_mcnp.py:TestPtrac
....
test_mcnp.py:TestSurfSrc
......
test_mcnp.py:test_read_mcnp
.
SKIP: test_mcnp.py:test_wwinp_n

SKIP: test_mcnp.py:test_wwinp_p

SKIP: test_mcnp.py:test_wwinp_np

SKIP: test_mcnp.py:test_single_meshtally_meshtal

SKIP: test_mcnp.py:test_multiple_meshtally_meshtal

----------------------------------------------------------------------
Ran 16 tests in 0.042s

OK
```

**After** new additions:
```
test_mcnp.py:TestPtrac
....
test_mcnp.py:TestSurfSrc
............
test_mcnp.py:test_read_mcnp
.
SKIP: test_mcnp.py:test_wwinp_n

SKIP: test_mcnp.py:test_wwinp_p

SKIP: test_mcnp.py:test_wwinp_np

SKIP: test_mcnp.py:test_single_meshtally_meshtal

SKIP: test_mcnp.py:test_multiple_meshtally_meshtal

----------------------------------------------------------------------
Ran 22 tests in 0.058s

OK
```

I'm happy to work in improvements in cleaning up this code segment and minor stuff. Probably would be good to resolve PR for No PyTAPS fixes as I extend on that (interested to see how this all gets merged properly).
I appreciate the feedback.