Doctests for the fix_texturepath spell
======================================

>>> import os
>>> from os.path import dirname
>>> dirpath = __file__
>>> for i in range(4): #recurse up to root repo dir
...     dirpath = dirname(dirpath)
>>> repo_root = dirpath
>>> script_dir = os.path.join(repo_root, "scripts", "nif")
>>> import sys
>>> script = os.path.join(script_dir, "niftoaster.py")
>>> sys.path.insert(-1, script_dir.replace("\\\\", "/"))
>>> nif_dir = "tests/spells/nif/files/"


NifToaster check
----------------

>>> import niftoaster
>>> sys.argv = ["niftoaster.py", "fix_clampmaterialalpha", "--dry-run", "--noninteractive", nif_dir + "test_fix_clampmaterialalpha.nif"]
>>> niftoaster.NifToaster().cli() # doctest: +ELLIPSIS +REPORT_NDIFF
pyffi.toaster:INFO:=== tests/spells/nif/files/test_fix_clampmaterialalpha.nif ===
pyffi.toaster:INFO:  --- fix_clampmaterialalpha ---
pyffi.toaster:INFO:    ~~~ NiNode [Scene Root] ~~~
pyffi.toaster:INFO:      ~~~ NiNode [Cone] ~~~
pyffi.toaster:INFO:        ~~~ NiTriShape [Tri Cone 0] ~~~
pyffi.toaster:INFO:          ~~~ NiMaterialProperty [Red] ~~~
pyffi.toaster:INFO:            clamping alpha value (1000.000000 -> 1.0)
pyffi.toaster:INFO:        ~~~ NiTriShape [Tri Cone 1] ~~~
pyffi.toaster:INFO:          ~~~ NiMaterialProperty [Green] ~~~
pyffi.toaster:INFO:            clamping alpha value (-1000.000000 -> 0.0)
pyffi.toaster:INFO:        ~~~ NiTriShape [Tri Cone 2] ~~~
pyffi.toaster:INFO:          ~~~ NiMaterialProperty [Blue] ~~~
pyffi.toaster:INFO:        ~~~ NiTriShape [Tri Cone 3] ~~~
pyffi.toaster:INFO:          ~~~ NiMaterialProperty [Yellow] ~~~
pyffi.toaster:INFO:  writing to temporary file
pyffi.toaster:INFO:Finished.

Explicit check
--------------

>>> from pyffi.formats.nif import NifFormat
>>> from pyffi.spells.nif import fix
>>> from pyffi.spells import Toaster
>>> data = NifFormat.Data()
>>> stream = open(nif_dir + "test_fix_clampmaterialalpha.nif", "rb")
>>> data.read(stream)
>>> # check that material alpha is out of range
>>> data.roots[0].children[0].children[0].properties[0].alpha > 1.01
True
>>> data.roots[0].children[0].children[1].properties[0].alpha < -0.01
True
>>> # run the spell that fixes this
>>> spell = fix.SpellClampMaterialAlpha(data=data)
>>> spell.recurse()
pyffi.toaster:INFO:--- fix_clampmaterialalpha ---
pyffi.toaster:INFO:  ~~~ NiNode [Scene Root] ~~~
pyffi.toaster:INFO:    ~~~ NiNode [Cone] ~~~
pyffi.toaster:INFO:      ~~~ NiTriShape [Tri Cone 0] ~~~
pyffi.toaster:INFO:        ~~~ NiMaterialProperty [Red] ~~~
pyffi.toaster:INFO:          clamping alpha value (1000.000000 -> 1.0)
pyffi.toaster:INFO:      ~~~ NiTriShape [Tri Cone 1] ~~~
pyffi.toaster:INFO:        ~~~ NiMaterialProperty [Green] ~~~
pyffi.toaster:INFO:          clamping alpha value (-1000.000000 -> 0.0)
pyffi.toaster:INFO:      ~~~ NiTriShape [Tri Cone 2] ~~~
pyffi.toaster:INFO:        ~~~ NiMaterialProperty [Blue] ~~~
pyffi.toaster:INFO:      ~~~ NiTriShape [Tri Cone 3] ~~~
pyffi.toaster:INFO:        ~~~ NiMaterialProperty [Yellow] ~~~
>>> # check that material alpha are no longer out of range
>>> "%.3f" % data.roots[0].children[0].children[0].properties[0].alpha
'1.000'
>>> "%.3f" % data.roots[0].children[0].children[1].properties[0].alpha
'0.000'
