<s> from unittest import TestCase <EOL> import os <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> from kingpin . zk_update_monitor import zk_util <EOL> from kingpin . zk_update_monitor . zk_update_monitor import transform_command_with_value <EOL> LARGE_SERVERSET_EXAMPLE_FILE_PATH = '<STR_LIT>' <EOL> SMALL_SERVERSET_EXAMPLE = '<STR_LIT>' <EOL> class ZKUpdateMonitorTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_transform_command_for_large_serverset ( self ) : <EOL> try : <EOL> command = '<STR_LIT>' <EOL> notification_timestamp = <NUM_LIT> <EOL> with open ( LARGE_SERVERSET_EXAMPLE_FILE_PATH ) as f : <EOL> large_serverset_value = f . readline ( ) <EOL> ( transformed_command , tmp_filepath ) = transform_command_with_value ( <EOL> command , large_serverset_value , notification_timestamp ) <EOL> santinized_value = large_serverset_value . strip ( '<STR_LIT:\n>' ) . strip ( '<STR_LIT:\r>' ) <EOL> expected_tmp_filepath = '<STR_LIT>' + zk_util . get_md5_digest ( <EOL> santinized_value ) + '<STR_LIT:_>' + str ( notification_timestamp ) <EOL> expected_transformed_command = '<STR_LIT>' + expected_tmp_filepath + '<STR_LIT>' <EOL> self . assertEqual ( expected_transformed_command , transformed_command ) <EOL> self . assertEqual ( expected_tmp_filepath , tmp_filepath ) <EOL> tmpfile = open ( expected_tmp_filepath ) <EOL> tmpfile_value = tmpfile . readline ( ) . rstrip ( '<STR_LIT:\n>' ) <EOL> tmpfile_md5 = tmpfile . readline ( ) <EOL> expected_tmpfile_value = santinized_value <EOL> expected_tmpfile_md5 = zk_util . get_md5_digest ( expected_tmpfile_value ) <EOL> self . assertEqual ( expected_tmpfile_value , tmpfile_value ) <EOL> self . assertEqual ( expected_tmpfile_md5 , tmpfile_md5 ) <EOL> finally : <EOL> if os . path . isfile ( tmp_filepath ) : <EOL> os . remove ( tmp_filepath ) <EOL> def test_transform_command_for_small_serverset ( self ) : <EOL> command = '<STR_LIT>' <EOL> notification_timestamp = <NUM_LIT> <EOL> small_serverset_value = SMALL_SERVERSET_EXAMPLE <EOL> ( transformed_command , tmp_filepath ) = transform_command_with_value ( <EOL> command , small_serverset_value , notification_timestamp ) <EOL> expected_tmp_filepath = None <EOL> expected_transformed_command = '<STR_LIT>' + "<STR_LIT:'>" + small_serverset_value + "<STR_LIT:'>" + '<STR_LIT>' <EOL> self . assertEqual ( expected_transformed_command , transformed_command ) <EOL> self . assertEqual ( expected_tmp_filepath , tmp_filepath ) <EOL> class SplitProblematicEndpointsLineTestCase ( TestCase ) : <EOL> def assert_splitted_parts_equal ( self , desired_list , actual_list ) : <EOL> desired_list . sort ( ) <EOL> actual_list . sort ( ) <EOL> self . assertEqual ( desired_list , actual_list ) <EOL> def test_split_problematic_endpoints_line ( self ) : <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> self . assert_splitted_parts_equal ( [ "<STR_LIT>" ] , splitted_parts ) <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> desired_answer = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assert_splitted_parts_equal ( desired_answer , splitted_parts ) <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> desired_answer = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assert_splitted_parts_equal ( desired_answer , splitted_parts ) <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> desired_answer = [ ] <EOL> self . assert_splitted_parts_equal ( desired_answer , splitted_parts ) <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> desired_answer = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assert_splitted_parts_equal ( desired_answer , splitted_parts ) <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> desired_answer = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assert_splitted_parts_equal ( desired_answer , splitted_parts ) <EOL> line = "<STR_LIT>" <EOL> splitted_parts = zk_util . split_problematic_endpoints_line ( line ) <EOL> desired_answer = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assert_splitted_parts_equal ( desired_answer , splitted_parts ) </s>
