Commit 4bdf2346 authored by Salko Jr, Robert's avatar Salko Jr, Robert
Browse files

Reformat test structure for PlotTools unit tests

Do not call using python explicitly because it may pick up the
wrong version.  Instead, set the command line arguments manually
and call the main procedure in the scripts.
parent 0987b71c
Loading
Loading
Loading
Loading
+83 −57
Original line number Diff line number Diff line
import os
from context import SubKit
from SubKit.process.PlotTools import *
import SubKit.process.PlotTools as PlotTools
import SubKit.process.plotPinRadialTemp as plotPinRadialTemp
import SubKit.process.plotPinDNBR as plotPinDNBR
import SubKit.process.plotChanVoid as plotChanVoid
import SubKit.process.plotChanQuality as plotChanQuality
import unittest
import subprocess
import sys
from mock import patch

myPath = os.path.abspath(os.path.dirname(__file__))

class test_PlotTools(unittest.TestCase):
   def setUp(me):
      me.obj = PlotTools(myPath+'/dummy.h5')
      me.obj = PlotTools.PlotTools(myPath+'/dummy.h5')

   def test_location(me):
      """ Ensures the location to plot is set correctly based on user input"""
@@ -55,64 +60,74 @@ class test_PlotTools(unittest.TestCase):
      # Just make sure the file gets generated for the correct location
      name = 'S1_P2_L5_pin_temp.png'
      if os.path.isfile(name): os.remove(name)
      subprocess.call('python ../../SubKit/process/plotPinRadialTemp.py --state=1 dummy.h5', shell=True)
      #me.obj.plotPinRadialTemp(state=1)
      args = ['dummy', '--state', '1', 'dummy.h5']
      with patch.object(sys, 'argv', args):
          plotPinRadialTemp.main()
          me.assertTrue(os.path.isfile(name))

      name = 'S2_P1_L5_pin_temp.png'
      if os.path.isfile(name): os.remove(name)
      subprocess.call('python ../../SubKit/process/plotPinRadialTemp.py --pin=1 dummy.h5', shell=True)
      #me.obj.plotPinRadialTemp(pin=1)
      args = ['dummy', '--pin', '1', 'dummy.h5']
      with patch.object(sys, 'argv', args):
          plotPinRadialTemp.main()
          me.assertTrue(os.path.isfile(name))

      name = 'S1_P1_L4_pin_temp.png'
      if os.path.isfile(name): os.remove(name)
      subprocess.call('python ../../SubKit/process/plotPinRadialTemp.py --state=1 --pin=1 dummy.h5', shell=True)
      #me.obj.plotPinRadialTemp(state=1, pin=1)
      args = ['dummy', '--state', '1', '--pin', '1', 'dummy.h5']
      with patch.object(sys, 'argv', args):
          plotPinRadialTemp.main()
          me.assertTrue(os.path.isfile(name))

      name = 'S1_P1_L1_pin_temp.png'
      if os.path.isfile(name): os.remove(name)
      subprocess.call('python ../../SubKit/process/plotPinRadialTemp.py --state=1 --pin=1 --level=1 dummy.h5', shell=True)
      #me.obj.plotPinRadialTemp(state=1, pin=1, level=0)
      args = ['dummy', '--state', '1', '--pin', '1', '--level', '1', 'dummy.h5']
      with patch.object(sys, 'argv', args):
          plotPinRadialTemp.main()
          me.assertTrue(os.path.isfile(name))

      name = 'customRadialTemp.png'
      if os.path.isfile(name): os.remove(name)
      subprocess.call('python ../../SubKit/process/plotPinRadialTemp.py --state=1 --pin=1 --level=0 --figname={:s} dummy.h5'.format(name), shell=True)
      #me.obj.plotPinRadialTemp(state=1, pin=1, level=0, figname=name)
      args = ['dummy', '--state', '1', '--pin', '1', '--level', '0', '--figname', name, 'dummy.h5']
      with patch.object(sys, 'argv', args):
          plotPinRadialTemp.main()
          me.assertTrue(os.path.isfile(name))

   def test_plotAxialDNBR(me):
       """ Test that axial DNBR plotter works"""
       name = 'S2_P2_T1_pin_dnbr.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotPinDNBR.py dummy.h5', shell=True)
       #me.obj.plotPinAxialDNBR()
       args = ['dummy', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotPinDNBR.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_P1_T2_pin_dnbr.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotPinDNBR.py --state=1 dummy.h5', shell=True)
       #me.obj.plotPinAxialDNBR(state=1)
       args = ['dummy', '--state', '1', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotPinDNBR.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_P1_T2_pin_dnbr.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotPinDNBR.py --state=1 --pin=1 dummy.h5', shell=True)
       #me.obj.plotPinAxialDNBR(state=1, pin=1)
       args = ['dummy', '--state', '1', '--pin', '1', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotPinDNBR.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_P2_T1_pin_dnbr.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotPinDNBR.py --state=1 --pin=2 --theta=1 dummy.h5', shell=True)
       #me.obj.plotPinAxialDNBR(state=1, pin=2, theta=0)
       args = ['dummy', '--state', '1', '--pin', '2', '--theta', '1', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotPinDNBR.main()
           me.assertTrue(os.path.isfile(name))

       name = 'customDNBR.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotPinDNBR.py --figname={:s} dummy.h5'.format(name), shell=True)
       #me.obj.plotPinAxialDNBR(figname=name)
       args = ['dummy', '--figname', name, 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotPinDNBR.main()
           me.assertTrue(os.path.isfile(name))

       with me.assertRaises(RuntimeError):
@@ -125,52 +140,63 @@ class test_PlotTools(unittest.TestCase):
   def test_plotChanVoid(me):
       name = 'S2_C1_chan_void_vap.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanVoid.py dummy.h5', shell=True)
       #me.obj.plotChAxialVoid()
       args = ['dummy', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanVoid.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_C1_chan_void_vap.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanVoid.py --state=1 dummy.h5', shell=True)
       #me.obj.plotChAxialVoid(state=1)
       args = ['dummy', '--state', '1', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanVoid.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_C2_chan_void_vap.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanVoid.py --state=1 --ch=2 dummy.h5', shell=True)
       #me.obj.plotChAxialVoid(state=1, ch=2)
       args = ['dummy', '--state', '1', '--ch', '2', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanVoid.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_C1_C2_chan_void_vap.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanVoid.py --state=1 --ch=1 --ch=2 dummy.h5', shell=True)
       #me.obj.plotChAxialVoid(state=1, ch=2)
       args = ['dummy', '--state', '1', '--ch', '1', '--ch', '2', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanVoid.main()
           me.assertTrue(os.path.isfile(name))

   def test_plotChanQuality(me):
       name = 'S2_C1_chan_equilibrium_quality.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanQuality.py dummy.h5', shell=True)
       #me.obj.plotChAxialVoid()
       args = ['dummy', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanQuality.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_C3_chan_equilibrium_quality.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanQuality.py --state=1 dummy.h5', shell=True)
       #me.obj.plotChAxialVoid(state=1)
       args = ['dummy', '--state', '1', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanQuality.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_C2_chan_equilibrium_quality.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanQuality.py --state=1 --ch=2 dummy.h5', shell=True)
       #me.obj.plotChAxialVoid(state=1, ch=2)
       args = ['dummy', '--state', '1', '--ch', '2', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanQuality.main()
           me.assertTrue(os.path.isfile(name))

       name = 'S1_C1_C2_chan_equilibrium_quality.png'
       if os.path.isfile(name): os.remove(name)
       subprocess.call('python ../../SubKit/process/plotChanQuality.py --state=1 --ch=1 --ch=2 dummy.h5', shell=True)
       #me.obj.plotChAxialVoid(state=1, ch=2)
       args = ['dummy', '--state', '1', '--ch', '1', '--ch', '2', 'dummy.h5']
       with patch.object(sys, 'argv', args):
           plotChanQuality.main()
           me.assertTrue(os.path.isfile(name))

if __name__=="__main__":

   myPath = os.path.abspath(os.path.dirname(__file__))

   unittest.main()