<s> '''<STR_LIT>''' <EOL> import base64 <EOL> import unittest <EOL> import zlib <EOL> from StringIO import StringIO <EOL> import numpy as np <EOL> from cellprofiler . preferences import set_headless <EOL> set_headless ( ) <EOL> import cellprofiler . workspace as cpw <EOL> import cellprofiler . pipeline as cpp <EOL> import cellprofiler . objects as cpo <EOL> import cellprofiler . cpimage as cpi <EOL> import cellprofiler . measurements as cpmeas <EOL> import cellprofiler . modules . editobjectsmanually as E <EOL> INPUT_OBJECTS_NAME = "<STR_LIT>" <EOL> OUTPUT_OBJECTS_NAME = "<STR_LIT>" <EOL> class TestEditObjectsManually ( unittest . TestCase ) : <EOL> def test_01_01_load_matlab ( self ) : <EOL> data = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( zlib . decompress ( base64 . b64decode ( data ) ) ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:3> ) <EOL> module = pipeline . modules ( ) [ - <NUM_LIT:1> ] <EOL> self . assertTrue ( isinstance ( module , E . EditObjectsManually ) ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . filtered_objects , "<STR_LIT>" ) <EOL> self . assertFalse ( module . wants_outlines ) <EOL> self . assertEqual ( module . renumber_choice , E . R_RENUMBER ) <EOL> def test_01_02_load_v1 ( self ) : <EOL> data = r"""<STR_LIT>""" <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( data ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:1> ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( module , E . EditObjectsManually ) ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . filtered_objects , "<STR_LIT>" ) <EOL> self . assertTrue ( module . wants_outlines ) <EOL> self . assertEqual ( module . outlines_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . renumber_choice , E . R_RENUMBER ) <EOL> self . assertFalse ( module . wants_image_display ) <EOL> def test_01_03_load_v2 ( self ) : <EOL> data = r"""<STR_LIT>""" <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( data ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:1> ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( module , E . EditObjectsManually ) ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . filtered_objects , "<STR_LIT>" ) <EOL> self . assertFalse ( module . wants_outlines ) <EOL> self . assertEqual ( module . renumber_choice , E . R_RETAIN ) <EOL> self . assertTrue ( module . wants_image_display ) <EOL> self . assertEqual ( module . image_name , "<STR_LIT>" ) <EOL> self . assertFalse ( module . allow_overlap ) <EOL> def test_01_04_load_v3 ( self ) : <EOL> data = r"""<STR_LIT>""" <EOL> pipeline = cpp . Pipeline ( ) <EOL> def callback ( caller , event ) : <EOL> self . assertFalse ( isinstance ( event , cpp . LoadExceptionEvent ) ) <EOL> pipeline . add_listener ( callback ) <EOL> pipeline . load ( StringIO ( data ) ) <EOL> self . assertEqual ( len ( pipeline . modules ( ) ) , <NUM_LIT:1> ) <EOL> module = pipeline . modules ( ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( module , E . EditObjectsManually ) ) <EOL> self . assertEqual ( module . object_name , "<STR_LIT>" ) <EOL> self . assertEqual ( module . filtered_objects , "<STR_LIT>" ) <EOL> self . assertFalse ( module . wants_outlines ) <EOL> self . assertEqual ( module . renumber_choice , E . R_RETAIN ) <EOL> self . assertTrue ( module . wants_image_display ) <EOL> self . assertEqual ( module . image_name , "<STR_LIT>" ) <EOL> self . assertTrue ( module . allow_overlap ) <EOL> def test_02_02_measurements ( self ) : <EOL> module = E . EditObjectsManually ( ) <EOL> module . object_name . value = INPUT_OBJECTS_NAME <EOL> module . filtered_objects . value = OUTPUT_OBJECTS_NAME <EOL> columns = module . get_measurement_columns ( None ) <EOL> expected_columns = [ <EOL> ( cpmeas . IMAGE , E . I . FF_COUNT % OUTPUT_OBJECTS_NAME , cpmeas . COLTYPE_INTEGER ) , <EOL> ( OUTPUT_OBJECTS_NAME , E . I . M_NUMBER_OBJECT_NUMBER , cpmeas . COLTYPE_INTEGER ) , <EOL> ( OUTPUT_OBJECTS_NAME , E . I . M_LOCATION_CENTER_X , cpmeas . COLTYPE_FLOAT ) , <EOL> ( OUTPUT_OBJECTS_NAME , E . I . M_LOCATION_CENTER_Y , cpmeas . COLTYPE_FLOAT ) , <EOL> ( OUTPUT_OBJECTS_NAME , E . I . FF_PARENT % INPUT_OBJECTS_NAME , cpmeas . COLTYPE_INTEGER ) , <EOL> ( INPUT_OBJECTS_NAME , E . I . FF_CHILDREN_COUNT % OUTPUT_OBJECTS_NAME , cpmeas . COLTYPE_INTEGER ) ] <EOL> for column in columns : <EOL> self . assertTrue ( any ( [ all ( [ column [ i ] == expected [ i ] for i in range ( <NUM_LIT:3> ) ] ) <EOL> for expected in expected_columns ] ) , <EOL> "<STR_LIT>" % column ) <EOL> self . assertEqual ( len ( [ '<STR_LIT:x>' for c in columns <EOL> if all ( [ column [ i ] == c [ i ] <EOL> for i in range ( <NUM_LIT:3> ) ] ) ] ) , <NUM_LIT:1> ) <EOL> for expected in expected_columns : <EOL> self . assertTrue ( any ( [ all ( [ column [ i ] == expected [ i ] for i in range ( <NUM_LIT:3> ) ] ) <EOL> for column in columns ] ) , <EOL> "<STR_LIT>" % expected ) <EOL> d = { cpmeas . IMAGE : { E . I . C_COUNT : [ OUTPUT_OBJECTS_NAME ] , <EOL> "<STR_LIT>" : [ ] } , <EOL> INPUT_OBJECTS_NAME : { E . I . C_CHILDREN : [ "<STR_LIT>" % OUTPUT_OBJECTS_NAME ] , <EOL> "<STR_LIT>" : [ ] } , <EOL> OUTPUT_OBJECTS_NAME : { <EOL> E . I . C_LOCATION : [ E . I . FTR_CENTER_X , E . I . FTR_CENTER_Y ] , <EOL> E . I . C_PARENT : [ INPUT_OBJECTS_NAME ] , <EOL> E . I . C_NUMBER : [ E . I . FTR_OBJECT_NUMBER ] , <EOL> "<STR_LIT>" : [ ] } , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> for object_name , category_d in d . iteritems ( ) : <EOL> categories = module . get_categories ( None , object_name ) <EOL> self . assertEqual ( len ( categories ) , len ( [ k for k in category_d . keys ( ) <EOL> if k != "<STR_LIT>" ] ) ) <EOL> for category in categories : <EOL> self . assertTrue ( category_d . has_key ( category ) ) <EOL> for category in category_d . keys ( ) : <EOL> if category != "<STR_LIT>" : <EOL> self . assertTrue ( category in categories ) <EOL> for category , expected_features in category_d . iteritems ( ) : <EOL> features = module . get_measurements ( None , object_name , <EOL> category ) <EOL> self . assertEqual ( len ( features ) , len ( expected_features ) ) <EOL> for feature in features : <EOL> self . assertTrue ( feature in expected_features , <EOL> "<STR_LIT>" % feature ) <EOL> for feature in expected_features : <EOL> self . assertTrue ( feature in features , <EOL> "<STR_LIT>" % feature ) </s>
