<s> from toscaparser . common import exception <EOL> from toscaparser . elements . scalarunit import ScalarUnit_Frequency <EOL> from toscaparser . elements . scalarunit import ScalarUnit_Size <EOL> from toscaparser . elements . scalarunit import ScalarUnit_Time <EOL> from toscaparser . nodetemplate import NodeTemplate <EOL> from toscaparser . tests . base import TestCase <EOL> from toscaparser . utils . gettextutils import _ <EOL> from toscaparser . utils import yamlparser <EOL> class ScalarUnitPositiveTest ( TestCase ) : <EOL> scenarios = [ <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( tpl_snippet = '''<STR_LIT>''' , <EOL> property = '<STR_LIT>' , <EOL> expected = '<STR_LIT>' ) <EOL> ) , <EOL> ] <EOL> def test_scenario_scalar_unit_positive ( self ) : <EOL> tpl = self . tpl_snippet <EOL> nodetemplates = yamlparser . simple_parse ( tpl ) <EOL> nodetemplate = NodeTemplate ( '<STR_LIT>' , nodetemplates ) <EOL> props = nodetemplate . get_capability ( '<STR_LIT:host>' ) . get_properties ( ) <EOL> prop_name = self . property <EOL> if props and prop_name in props . keys ( ) : <EOL> prop = props [ prop_name ] <EOL> self . assertIsNone ( prop . validate ( ) ) <EOL> resolved = prop . value <EOL> self . assertEqual ( resolved , self . expected ) <EOL> class GetNumFromScalarUnitSizePositive ( TestCase ) : <EOL> scenarios = [ <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT:1000> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ] <EOL> def test_scenario_get_num_from_scalar_unit_size ( self ) : <EOL> resolved = ( ScalarUnit_Size ( self . InputMemSize ) . <EOL> get_num_from_scalar_unit ( self . UserInputUnit ) ) <EOL> self . assertEqual ( resolved , self . expected ) <EOL> class GetNumFromScalarUnitFrequencyPositive ( TestCase ) : <EOL> scenarios = [ <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ] <EOL> def test_scenario_get_num_from_scalar_unit_frequency ( self ) : <EOL> resolved = ( ScalarUnit_Frequency ( self . InputMemSize ) . <EOL> get_num_from_scalar_unit ( self . UserInputUnit ) ) <EOL> self . assertEqual ( resolved , self . expected ) <EOL> class GetNumFromScalarUnitTimePositive ( TestCase ) : <EOL> scenarios = [ <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT:s>' , <EOL> expected = <NUM_LIT:0.5> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT:s>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT:s>' , <EOL> expected = <NUM_LIT:30> ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> dict ( InputMemSize = '<STR_LIT>' , <EOL> UserInputUnit = '<STR_LIT:h>' , <EOL> expected = <NUM_LIT> ) <EOL> ) , <EOL> ] <EOL> def test_scenario_get_num_from_scalar_unit_time ( self ) : <EOL> resolved = ( ScalarUnit_Time ( self . InputMemSize ) . <EOL> get_num_from_scalar_unit ( self . UserInputUnit ) ) <EOL> self . assertEqual ( resolved , self . expected ) <EOL> class GetNumFromScalarUnitSizeNegative ( TestCase ) : <EOL> InputMemSize = '<STR_LIT>' <EOL> UserInputUnit = '<STR_LIT>' <EOL> def test_get_num_from_scalar_unit_size_negative ( self ) : <EOL> try : <EOL> ( ScalarUnit_Size ( self . InputMemSize ) . <EOL> get_num_from_scalar_unit ( self . UserInputUnit ) ) <EOL> except Exception as error : <EOL> self . assertTrue ( isinstance ( error , ValueError ) ) <EOL> self . assertEqual ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> error . __str__ ( ) ) <EOL> class GetNumFromScalarUnitFrequencyNegative ( TestCase ) : <EOL> InputFrequency = '<STR_LIT>' <EOL> UserInputUnit = '<STR_LIT>' <EOL> def test_get_num_from_scalar_unit_frequency_negative ( self ) : <EOL> try : <EOL> ( ScalarUnit_Frequency ( self . InputFrequency ) . <EOL> get_num_from_scalar_unit ( self . UserInputUnit ) ) <EOL> except Exception as error : <EOL> self . assertTrue ( isinstance ( error , ValueError ) ) <EOL> self . assertEqual ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> error . __str__ ( ) ) <EOL> class GetNumFromScalarUnitTimeNegative ( TestCase ) : <EOL> InputTime = '<STR_LIT>' <EOL> UserInputUnit = '<STR_LIT:D>' <EOL> def test_get_num_from_scalar_unit_frequency_negative ( self ) : <EOL> try : <EOL> ( ScalarUnit_Time ( self . InputTime ) . <EOL> get_num_from_scalar_unit ( self . UserInputUnit ) ) <EOL> except Exception as error : <EOL> self . assertTrue ( isinstance ( error , ValueError ) ) <EOL> self . assertEqual ( _ ( '<STR_LIT>' ) , <EOL> error . __str__ ( ) ) <EOL> class ScalarUnitNegativeTest ( TestCase ) : <EOL> custom_def_snippet = '''<STR_LIT>''' <EOL> custom_def = yamlparser . simple_parse ( custom_def_snippet ) <EOL> def test_invalid_scalar_unit ( self ) : <EOL> tpl_snippet = '''<STR_LIT>''' <EOL> nodetemplates = yamlparser . simple_parse ( tpl_snippet ) <EOL> nodetemplate = NodeTemplate ( '<STR_LIT>' , nodetemplates , self . custom_def ) <EOL> for p in nodetemplate . get_properties_objects ( ) : <EOL> self . assertRaises ( ValueError , p . validate ) <EOL> def test_constraint_for_scalar_unit ( self ) : <EOL> tpl_snippet = '''<STR_LIT>''' <EOL> nodetemplates = yamlparser . simple_parse ( tpl_snippet ) <EOL> nodetemplate = NodeTemplate ( '<STR_LIT>' , nodetemplates , self . custom_def ) <EOL> props = nodetemplate . get_properties ( ) <EOL> if '<STR_LIT>' in props . keys ( ) : <EOL> error = self . assertRaises ( exception . ValidationError , <EOL> props [ '<STR_LIT>' ] . validate ) <EOL> self . assertEqual ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , error . __str__ ( ) ) <EOL> if '<STR_LIT>' in props . keys ( ) : <EOL> error = self . assertRaises ( exception . ValidationError , <EOL> props [ '<STR_LIT>' ] . validate ) <EOL> self . assertEqual ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> error . __str__ ( ) ) <EOL> if '<STR_LIT>' in props . keys ( ) : <EOL> error = self . assertRaises ( exception . ValidationError , <EOL> props [ '<STR_LIT>' ] . validate ) <EOL> self . assertEqual ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> error . __str__ ( ) ) </s>
