Skip to content
Snippets Groups Projects
test_shear_file.py 2.28 KiB
Newer Older
mads's avatar
mads committed
'''
Created on 05/11/2015

@author: MMPE
'''
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from io import open
from future import standard_library
standard_library.install_aliases()
mads's avatar
mads committed
import unittest
from wetb.hawc2 import shear_file
mads's avatar
mads committed
import numpy as np
import os
import shutil
mads's avatar
mads committed
testfilepath = 'test_files/'
mads's avatar
mads committed
class TestShearFile(unittest.TestCase):
mads's avatar
mads committed


    def test_shearfile(self):
mads's avatar
mads committed
        f = testfilepath + "tmp_shearfile1.dat"
        shear_file.save(f, [-55, 55], [30, 100, 160] , u=np.array([[0.7, 1, 1.3], [0.7, 1, 1.3]]).T)
mads's avatar
mads committed
        with open(f) as fid:
            self.assertEqual(fid.read(),
""" # autogenerated shear file
  2 3
 # shear v component
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
 # shear u component
  0.7000000000 0.7000000000
  1.0000000000 1.0000000000
  1.3000000000 1.3000000000
 # shear w component
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
 # y coordinates
  -55.0000000000
  55.0000000000
 # z coordinates
  30.0000000000
  100.0000000000
  160.0000000000
""")
        os.remove(f)


    def test_shearfile2(self):
mads's avatar
mads committed
        f = testfilepath + "tmp_shearfile2.dat"
        shear_file.save(f, [-55, 55], [30, 100, 160] , u=np.array([0.7, 1, 1.3]).T)
        with open(f) as fid:
            self.assertEqual(fid.read(),
""" # autogenerated shear file
  2 3
 # shear v component
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
 # shear u component
  0.7000000000 0.7000000000
  1.0000000000 1.0000000000
  1.3000000000 1.3000000000
 # shear w component
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
  0.0000000000 0.0000000000
 # y coordinates
  -55.0000000000
  55.0000000000
 # z coordinates
  30.0000000000
  100.0000000000
  160.0000000000
""")
        os.remove(f)

    def test_shear_makedirs(self):
        f = testfilepath + "shear/tmp_shearfile2.dat"
        shear_file.save(f, [-55, 55], [30, 100, 160] , u=np.array([0.7, 1, 1.3]).T)
        shutil.rmtree(testfilepath + "shear")

mads's avatar
mads committed
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_shearfile']
    unittest.main()