Commit d6dc2118 authored by erodrigu's avatar erodrigu
Browse files

Split test.py into multiple test files

parent 62a1199e
import unittest
class TestFinder(unittest.TestCase):
def test_find_function_type_from_header_1(self):
import AutoRPE.UtilsRPE.Finder as Finder
header = 'RECURSIVE FUNCTION nodal_factort( kformula ) RESULT( zf )'
var_declaration = ['INTEGER, INTENT(in) :: kformula', 'type(rpe_var) :: zf', 'type(rpe_var) '
' :: zs',
'type(rpe_var) :: zf1', 'type(rpe_var) :: zf2', 'CHARACTER(LEN=3) '
' :: clformula']
ret_type, ret_val = Finder.find_function_type_from_header(header, var_declaration)
expected_retval = [None, 'zf']
self.assertEqual([ret_type, ret_val], expected_retval)
def test_find_function_type_from_header_2(self):
import AutoRPE.UtilsRPE.Finder as Finder
header = ' type(rpe_var) function bdy_segs_surf(phu, phv)'
var_declaration = ['type(rpe_var), DIMENSION(jpi,jpj), INTENT(in) :: phu',
'type(rpe_var), DIMENSION(jpi,jpj), INTENT(in) :: phv', 'INTEGER :: igrd',
'INTEGER :: ib_bdy', 'INTEGER :: ib', 'INTEGER , POINTER :: nbi',
'INTEGER , POINTER :: nbj', 'type(rpe_var), POINTER :: zflagu',
'type(rpe_var), POINTER :: zflagv']
ret_type, ret_val = Finder.find_function_type_from_header(header, var_declaration)
expected_retval = ['rpe_var', 'bdy_segs_surf']
self.assertEqual([ret_type, ret_val], expected_retval)
def test_find_function_type_from_header_3(self):
import AutoRPE.UtilsRPE.Finder as Finder
header = ' function dia_ptr_alloc()'
var_declaration = ['INTEGER :: dia_ptr_alloc', 'INTEGER, DIMENSION(3) :: ierr']
ret_type, ret_val = Finder.find_function_type_from_header(header, var_declaration)
expected_retval = [None, 'dia_ptr_alloc']
self.assertEqual([ret_type, ret_val], expected_retval)
if __name__ == '__main__':
unittest.main()
import unittest
import AutoRPE.UtilsRPE.Getter as Getter
class TestGetter(unittest.TestCase):
def test_type_of_real_cast_with_double_specification(self):
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),dp)'
self.assertEqual(Getter.get_type_of_real_cast(string), 'double')
def test_type_of_real_cast_with_single_specification(self):
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),sp)'
self.assertEqual(Getter.get_type_of_real_cast(string), 'single')
def test_type_of_real_cast_no_specification(self):
from AutoRPE.UtilsRPE.VariablePrecision import wp
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1))'
self.assertEqual(Getter.get_type_of_real_cast(string), wp)
def test_dimension_of_contents_1(self):
import AutoRPE.UtilsRPE.Getter as Getter
self.assertEqual(Getter.get_dimension_of_contents("1.0"), 0)
def test_dimension_of_contents_2(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = "real( ( ( z3d(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )"
dimension = Getter.get_dimension_of_contents(string)
self.assertEqual(dimension, 3)
def test_dimension_of_contents_3(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = "e1e2t(:,:) * zfwf(:,:)"
dimension = Getter.get_dimension_of_contents(string)
self.assertEqual(dimension, 2)
def test_dimension_of_contents(self):
import AutoRPE.UtilsRPE.Getter as Getter
cases = [
('SUM( a_i(:,:,:)%val - a_i_b(:,:,:)%val, dim=3 )', 2),
('SQRT( ( zs1(:,:)%val - zs2(:,:)%val )**2 + 4*zs12(:,:)%val**2 ) * zmsk00(:,:)', 2)
]
for case, answer in cases:
self.assertEqual(Getter.get_dimension_of_contents(case), answer)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
import unittest
class TestInserter(unittest.TestCase):
def test_replace_variable_exact_match(self):
import AutoRPE.UtilsRPE.Inserter as Inserter
# This is the line of code from NEMO
fun_in = "znam = 'sye'//'_l'//zchar1 ; z3d(:,:,:) = sye (:,:,jk,:) ; CALL iom_rstput( iter, nitrst, numriw, znam , z3d )"
# This is the argument that we want to replace and its replacement
piece_to_replace = "z3d"
replacement = "REAL(z3d, dp)"
# This is what the function actually gives
fun_out = Inserter.replace_variable_exact_match(piece_to_replace, replacement, fun_in)
# This is what it should give
solution = "znam = 'sye'//'_l'//zchar1 ; z3d(:,:,:) = sye (:,:,jk,:) ; CALL iom_rstput( iter, nitrst, numriw, znam , REAL(z3d, dp) )"
self.assertEqual(fun_out, solution)
def test_replace_variable_exact_match_2(self):
import AutoRPE.UtilsRPE.Inserter as Inserter
# This is the line of code from NEMO
fun_in = "CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice )"
# This is the argument that we want to replace and its replacement
piece_to_replace = "sxice"
replacement = "REAL(sxice, dp)"
# This is what the function actually gives
fun_out = Inserter.replace_variable_exact_match(piece_to_replace, replacement, fun_in)
# This is what it should give
solution = "CALL iom_rstput( iter, nitrst, numriw, 'sxice' , REAL(sxice, dp) )"
self.assertEqual(fun_out, solution)
if __name__ == '__main__':
unittest.main()
import unittest
class TestNatureDeterminer(unittest.TestCase):
def test_has_operations(self):
import AutoRPE.UtilsRPE.NatureDeterminer as NatureDeterminer
string = 'SUM( a_i(:,:,:)%val - a_i_b(:,:,:)%val, dim=3 ) * r1_Dt_ice'
self.assertTrue(NatureDeterminer.has_operations(string))
def test_has_operations_2(self):
import AutoRPE.UtilsRPE.NatureDeterminer as NatureDeterminer
# Some cases that appear in NEMO
cases = [
'kndims=indims',
'lduld=lluld',
'kfillmode=jpfillnothing',
'lsend=llsend2',
'ktype = jp_i4',
'pfillval=1.0_wp',
]
for case in cases:
self.assertFalse(NatureDeterminer.has_operations(case))
if __name__ == '__main__':
unittest.main()
import unittest
class TestRegexPattern(unittest.TestCase):
def test_regex_hardcoded_array_1(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = ' (/ llnon, llson, llean, llwen /)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string)
def test_regex_hardcoded_array_2(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = ' (/ (zshift + REAL(ji,wp), ji = 1, jpi_crs*jpj_crs) /)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string)
def test_regex_hardcoded_array_3(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = '(/sd(ju)%ln_tint/)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string)
def test_regex_hardcoded_array_4(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = '(/ sdjf%cltype == \'monthly\' .OR. idy == 0 /)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string.strip())
def test_regex_hardcoded_array_4(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'RESHAPE( (/pfield1d%val/), (/1,1,SIZE(pfield1d%val)/) )'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match, None)
def test_regex_array_in_write_statement(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = '(iall_rank(idum) ,all_etime(idum),all_ctime(idum),zall_ratio(idum),idum=1, jpnij)'
array_match = re.search(RegexPattern.array_in_write_statement, string)
self.assertEqual(array_match.group(), string)
def test_regex_real_with_precision_declaration_1(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'real(wp) :: costheta'
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string, flags=re.I)
self.assertEqual(match.group(), 'real(wp) ::')
def test_regex_real_with_precision_declaration_2(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'real(wp), pointer, dimension(:,:,:,:,:), intent(inout) :: real_vec_obj'
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string, flags=re.I)
self.assertEqual(match.group(), 'real(wp), pointer, dimension(:,:,:,:,:), intent(inout) ::')
def test_regex_real_with_precision_declaration_3(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'REAL(wp) FUNCTION bdy_segs_surf(phu, phv)'
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string,flags=re.I)
self.assertEqual(match.group(), 'REAL(wp) FUNCTION')
def test_regex_real_with_precision_declaration_4(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'REAL(KIND=wp) FUNCTION fspott( pft, pfs, pfp )'
match = ""
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string, flags=re.I)
self.assertEqual(match.group(), 'REAL(KIND=wp) FUNCTION')
def test_regex_real_with_precision_declaration_5(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'type(treal_at_qn3d) :: nodval(3)'
match = ""
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.general_real_declaration, string, flags=re.I)
self.assertEqual(match, "")
if __name__ == '__main__':
unittest.main()
import unittest
import AutoRPE.UtilsRPE.Splitter as Splitter
class TestSplitter(unittest.TestCase):
def test_separate_line_container_and_arguments_1(self):
string = 'write(numicb,*) \'bergstep \',nktberg,\' send ns: \', ibergs_to_send_n, ibergs_to_send_s'
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
actual_arguments = ["'bergstep '", 'nktberg', "' send ns: '", ' ibergs_to_send_n', ' ibergs_to_send_s']
actual_line_container = 'write(numicb,*) ###TOREPLACE###'
self.assertTrue(line_container == actual_line_container and actual_arguments == arguments)
def test_separate_line_container_and_arguments_2(self):
string = "WRITE(cl_asmbkg, FMT='(A,\".nc\")' ) TRIM( c_asmbkg )"
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
actual_arguments = ['TRIM( c_asmbkg )']
actual_line_container = 'WRITE(cl_asmbkg, FMT=\'(A,".nc")\' ) ###TOREPLACE###'
self.assertTrue(line_container == actual_line_container and actual_arguments == arguments)
def test_separate_line_container_and_arguments_3(self):
string = "IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)') ' =======>> 1/2 time step before the start of the run DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, ' nsec_day:', nsec_day, ' nsec_monday:', nsec_monday, ' nsec_month:', nsec_month , ' nsec_year:' , nsec_year"
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_separate_line_container_and_arguments_4(self):
string = 'IF( lwriter ) WRITE(numtime,*) \' ===> W A R N I N G: \''
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_separate_line_container_and_arguments_4(self):
string = 'IF (ln_grid_search_lookup)WRITE(numout,*) \' Grid search lookup file header cn_gridsearchfile = \', cn_gridsearchfile'
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
if __name__ == '__main__':
unittest.main()
import unittest import unittest
import AutoRPE.UtilsRPE.Error as Error
class TestFunctionMethods(unittest.TestCase):
def test_type_of_real_cast_with_double_specification(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),dp)'
self.assertEqual(Getter.get_type_of_real_cast(string), 'double')
def test_type_of_real_cast_with_single_specification(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),sp)'
self.assertEqual(Getter.get_type_of_real_cast(string), 'single')
def test_type_of_real_cast_no_specification(self):
import AutoRPE.UtilsRPE.Getter as Getter
from AutoRPE.UtilsRPE.VariablePrecision import wp
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1))'
self.assertEqual(Getter.get_type_of_real_cast(string), wp)
def test_separate_line_container_and_arguments_1(self):
import AutoRPE.UtilsRPE.Splitter as Splitter
string = 'write(numicb,*) \'bergstep \',nktberg,\' send ns: \', ibergs_to_send_n, ibergs_to_send_s'
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
actual_arguments = ["'bergstep '", 'nktberg', "' send ns: '", ' ibergs_to_send_n', ' ibergs_to_send_s']
actual_line_container = 'write(numicb,*) ###TOREPLACE###'
self.assertTrue(line_container == actual_line_container and actual_arguments == arguments)
def test_separate_line_container_and_arguments_2(self):
import AutoRPE.UtilsRPE.Splitter as Splitter
string = "WRITE(cl_asmbkg, FMT='(A,\".nc\")' ) TRIM( c_asmbkg )"
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
actual_arguments = ['TRIM( c_asmbkg )']
actual_line_container = 'WRITE(cl_asmbkg, FMT=\'(A,".nc")\' ) ###TOREPLACE###'
self.assertTrue(line_container == actual_line_container and actual_arguments == arguments)
def test_separate_line_container_and_arguments_3(self):
import AutoRPE.UtilsRPE.Splitter as Splitter
string = "IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)') ' =======>> 1/2 time step before the start of the run DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, ' nsec_day:', nsec_day, ' nsec_monday:', nsec_monday, ' nsec_month:', nsec_month , ' nsec_year:' , nsec_year"
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_separate_line_container_and_arguments_4(self):
import AutoRPE.UtilsRPE.Splitter as Splitter
string = 'IF( lwriter ) WRITE(numtime,*) \' ===> W A R N I N G: \''
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_separate_line_container_and_arguments_4(self):
import AutoRPE.UtilsRPE.Splitter as Splitter
string = 'IF (ln_grid_search_lookup)WRITE(numout,*) \' Grid search lookup file header cn_gridsearchfile = \', cn_gridsearchfile'
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_dimension_of_contents_1(self):
import AutoRPE.UtilsRPE.Getter as Getter
self.assertEqual(Getter.get_dimension_of_contents("1.0"), 0)
def test_dimension_of_contents_2(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = "real( ( ( z3d(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )"
dimension = Getter.get_dimension_of_contents(string)
self.assertEqual(dimension, 3)
def test_dimension_of_contents_3(self):
import AutoRPE.UtilsRPE.Getter as Getter
string = "e1e2t(:,:) * zfwf(:,:)"
dimension = Getter.get_dimension_of_contents(string)
self.assertEqual(dimension, 2)
def test_add_val(self):
# Need to be sure that same strings are not replaced twice
pass
def test_has_operations(self):
import AutoRPE.UtilsRPE.NatureDeterminer as NatureDeterminer
string = 'SUM( a_i(:,:,:)%val - a_i_b(:,:,:)%val, dim=3 ) * r1_Dt_ice'
self.assertTrue(NatureDeterminer.has_operations(string))
def test_has_operations_2(self):
import AutoRPE.UtilsRPE.NatureDeterminer as NatureDeterminer
# Some cases that appear in NEMO
cases = [
'kndims=indims',
'lduld=lluld',
'kfillmode=jpfillnothing',
'lsend=llsend2',
'ktype = jp_i4',
'pfillval=1.0_wp',
]
for case in cases:
self.assertFalse(NatureDeterminer.has_operations(case))
def test_dimension_of_contents(self):
import AutoRPE.UtilsRPE.Getter as Getter
cases = [
('SUM( a_i(:,:,:)%val - a_i_b(:,:,:)%val, dim=3 )', 2),
('SQRT( ( zs1(:,:)%val - zs2(:,:)%val )**2 + 4*zs12(:,:)%val**2 ) * zmsk00(:,:)', 2)
]
for case, answer in cases:
self.assertEqual(Getter.get_dimension_of_contents(case), answer)
def test_replace_variable_exact_match(self):
import AutoRPE.UtilsRPE.Inserter as Inserter
# This is the line of code from NEMO
fun_in = "znam = 'sye'//'_l'//zchar1 ; z3d(:,:,:) = sye (:,:,jk,:) ; CALL iom_rstput( iter, nitrst, numriw, znam , z3d )"
# This is the argument that we want to replace and its replacement
piece_to_replace = "z3d"
replacement = "REAL(z3d, dp)"
# This is what the function actually gives
fun_out = Inserter.replace_variable_exact_match(piece_to_replace, replacement, fun_in)
# This is what it should give
solution = "znam = 'sye'//'_l'//zchar1 ; z3d(:,:,:) = sye (:,:,jk,:) ; CALL iom_rstput( iter, nitrst, numriw, znam , REAL(z3d, dp) )"
self.assertEqual(fun_out, solution)
def test_replace_variable_exact_match_2(self):
import AutoRPE.UtilsRPE.Inserter as Inserter
# This is the line of code from NEMO
fun_in = "CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice )"
# This is the argument that we want to replace and its replacement
piece_to_replace = "sxice"
replacement = "REAL(sxice, dp)"
# This is what the function actually gives
fun_out = Inserter.replace_variable_exact_match(piece_to_replace, replacement, fun_in)
# This is what it should give
solution = "CALL iom_rstput( iter, nitrst, numriw, 'sxice' , REAL(sxice, dp) )"
self.assertEqual(fun_out, solution)
def test_find_function_type_from_header_1(self):
import AutoRPE.UtilsRPE.Finder as Finder
header = 'RECURSIVE FUNCTION nodal_factort( kformula ) RESULT( zf )'
var_declaration = ['INTEGER, INTENT(in) :: kformula', 'type(rpe_var) :: zf', 'type(rpe_var) '
' :: zs',
'type(rpe_var) :: zf1', 'type(rpe_var) :: zf2', 'CHARACTER(LEN=3) '
' :: clformula']
ret_type, ret_val = Finder.find_function_type_from_header(header, var_declaration)
expected_retval = [None, 'zf']
self.assertEqual([ret_type, ret_val], expected_retval)
def test_find_function_type_from_header_2(self):
import AutoRPE.UtilsRPE.Finder as Finder
header = ' type(rpe_var) function bdy_segs_surf(phu, phv)'
var_declaration = ['type(rpe_var), DIMENSION(jpi,jpj), INTENT(in) :: phu', 'type(rpe_var), DIMENSION(jpi,jpj), INTENT(in) :: phv', 'INTEGER :: igrd', 'INTEGER :: ib_bdy', 'INTEGER :: ib', 'INTEGER , POINTER :: nbi', 'INTEGER , POINTER :: nbj', 'type(rpe_var), POINTER :: zflagu', 'type(rpe_var), POINTER :: zflagv']
ret_type, ret_val = Finder.find_function_type_from_header(header, var_declaration)
expected_retval = ['rpe_var', 'bdy_segs_surf']
self.assertEqual([ret_type, ret_val], expected_retval)
def test_find_function_type_from_header_3(self):
import AutoRPE.UtilsRPE.Finder as Finder
header = ' function dia_ptr_alloc()'
var_declaration = ['INTEGER :: dia_ptr_alloc', 'INTEGER, DIMENSION(3) :: ierr']
ret_type, ret_val = Finder.find_function_type_from_header(header, var_declaration)
expected_retval = [None, 'dia_ptr_alloc']
self.assertEqual([ret_type, ret_val], expected_retval)
def test_regex_hardcoded_array_1(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = ' (/ llnon, llson, llean, llwen /)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string)
def test_regex_hardcoded_array_2(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = ' (/ (zshift + REAL(ji,wp), ji = 1, jpi_crs*jpj_crs) /)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string)
def test_regex_hardcoded_array_3(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = '(/sd(ju)%ln_tint/)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string)
def test_regex_hardcoded_array_4(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = '(/ sdjf%cltype == \'monthly\' .OR. idy == 0 /)'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match.group(), string.strip())
def test_regex_hardcoded_array_4(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'RESHAPE( (/pfield1d%val/), (/1,1,SIZE(pfield1d%val)/) )'
array_match = re.search(RegexPattern.hardcoded_array, string)
self.assertEqual(array_match, None)
def test_regex_array_in_write_statement(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = '(iall_rank(idum) ,all_etime(idum),all_ctime(idum),zall_ratio(idum),idum=1, jpnij)'
array_match = re.search(RegexPattern.array_in_write_statement, string)
self.assertEqual(array_match.group(), string)
def test_regex_real_with_precision_declaration_1(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'real(wp) :: costheta'
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string, flags=re.I)
self.assertEqual(match.group(), 'real(wp) ::')
def test_regex_real_with_precision_declaration_2(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'real(wp), pointer, dimension(:,:,:,:,:), intent(inout) :: real_vec_obj'
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string, flags=re.I)
self.assertEqual(match.group(), 'real(wp), pointer, dimension(:,:,:,:,:), intent(inout) ::')
def test_regex_real_with_precision_declaration_3(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'REAL(wp) FUNCTION bdy_segs_surf(phu, phv)'
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string,flags=re.I)
self.assertEqual(match.group(), 'REAL(wp) FUNCTION')
def test_regex_real_with_precision_declaration_4(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'REAL(KIND=wp) FUNCTION fspott( pft, pfs, pfp )'
match = ""
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.real_with_precision_declaration, string, flags=re.I)
self.assertEqual(match.group(), 'REAL(KIND=wp) FUNCTION')
def test_regex_real_with_precision_declaration_5(self):
import AutoRPE.UtilsRPE.RegexPattern as RegexPattern
import re
string = 'type(treal_at_qn3d) :: nodval(3)'
match = ""
if re.search(RegexPattern.general_real_declaration, string, flags=re.I):
match = re.search(RegexPattern.general_real_declaration, string, flags=re.I)
self.assertEqual(match, "")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() loader = unittest.TestLoader()
tests = loader.discover(start_dir='.', pattern="Test*.py")
testRunner = unittest.runner.TextTestRunner()
testRunner.run(tests)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment