Skip to content

Commit

Permalink
Add testing routines for the duplicate option
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Smolenko committed Aug 22, 2022
1 parent 3cc571f commit fe7ae58
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tests/parameter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,115 @@ def test_etree_repr(self):
self.assertEqual(etree.tag, "parameterset")
self.assertEqual(len(etree.findall("parameter")), 2)

def test_concat_parameter(self):
"""Test concat_parameter"""
param1 = jube2.parameter.TemplateParameter(
name='param1',
value=['1','2','3'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')
param2 = jube2.parameter.TemplateParameter(
name='param1',
value=['4','5','6'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')
param3 = jube2.parameter.StaticParameter(
name='param1',
value='',
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')

paramset1 = jube2.parameter.Parameterset(name='paramset1',duplicate='concat')
paramset1.add_parameter(param1)
self.assertEqual(paramset1.concat_parameter(param2)._value,['1','2','3','4','5','6'])
self.assertEqual(paramset1.concat_parameter(param3)._value,['','1','2','3'])

def test_check_parameter_options(self):
"""Test check_parameter_options"""
param1 = jube2.parameter.TemplateParameter(
name='param1',
value=['1','2','3'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')
param2 = jube2.parameter.TemplateParameter(
name='param1',
value=['4','5','6'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')
param3 = jube2.parameter.TemplateParameter(
name='param1',
value=['7','8','9'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='replace')
paramset1 = jube2.parameter.Parameterset(name='paramset1',duplicate='concat')
paramset1.add_parameter(param1)
paramset1.check_parameter_options(param2)
with self.assertRaises(ValueError):
paramset1.check_parameter_options(param3)

def test_add_parameter(self):
"""Test add_parameter"""
param1 = jube2.parameter.TemplateParameter(
name='param1',
value=['1','2','3'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')
param2 = jube2.parameter.TemplateParameter(
name='param1',
value=['4','5','6'],
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='none')
param4 = jube2.parameter.StaticParameter(
name='param2',
value='',
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='replace')
param5 = jube2.parameter.StaticParameter(
name='param2',
value='1',
separator=',',
parameter_type='string',
parameter_mode='text',
duplicate='replace')

paramset1 = jube2.parameter.Parameterset(name='paramset1',duplicate='concat')
paramset1.add_parameter(param1)
self.assertEqual(paramset1._parameters[param1._name]._value,['1','2','3'])
paramset1.add_parameter(param2)
self.assertEqual(paramset1._parameters[param2._name]._value,['1','2','3','4','5','6'])

paramset2 = jube2.parameter.Parameterset(name='paramset2',duplicate='replace')
paramset2.add_parameter(param1)
paramset2.add_parameter(param2)
self.assertEqual(paramset2._parameters[param2._name]._value,['4','5','6'])

paramset3 = jube2.parameter.Parameterset(name='paramset3',duplicate='error')
paramset3.add_parameter(param1)
with self.assertRaises(Exception):
paramset3.add_parameter(param2)

paramset1.add_parameter(param4)
paramset1.add_parameter(param5)
self.assertEqual(paramset1._parameters[param4._name]._value,'1')


if __name__ == "__main__":
unittest.main()
12 changes: 12 additions & 0 deletions tests/util_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_convert_type(self):
self.assertEqual(jube2.util.util.convert_type("int","forty-two",stop=False),"forty-two")

def test_expand_dollar_count(self):
"""Test expand_dollar_count"""
test_text=[]
test_result_text=[]

Expand Down Expand Up @@ -73,6 +74,7 @@ def test_expand_dollar_count(self):
self.assertEqual(jube2.util.util.expand_dollar_count(text=test_text[i]),test_result_text[i])

def test_substitution(self):
"""Test substitution"""
test_substitution_dict={'test1':'test2','test3':'test4'}
test_text=[]
test_result_text=[]
Expand Down Expand Up @@ -107,5 +109,15 @@ def test_substitution(self):
for i in range(len(test_text)):
self.assertEqual(jube2.util.util.substitution(text=test_text[i], substitution_dict=test_substitution_dict),test_result_text[i])

def test_ensure_list(self):
"""Test ensure_list"""
self.assertEqual(jube2.util.util.ensure_list(42),[42])
self.assertEqual(type(jube2.util.util.ensure_list(42)),list)
self.assertEqual(jube2.util.util.ensure_list(""),[""])
self.assertEqual(type(jube2.util.util.ensure_list("")),list)
self.assertEqual(jube2.util.util.ensure_list(["",42,3.141]),["",42,3.141])
self.assertEqual(type(jube2.util.util.ensure_list(["",42,3.141])),list)


if __name__ == "__main__":
unittest.main()

0 comments on commit fe7ae58

Please sign in to comment.