<s> """<STR_LIT>""" <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> import os <EOL> import h5py <EOL> import tempfile <EOL> import unittest <EOL> import cellprofiler . measurements as cpmeas <EOL> import cellprofiler . pipeline as cpp <EOL> import cellprofiler . workspace as cpw <EOL> from cellprofiler . utilities . hdf5_dict import FILE_LIST_GROUP , TOP_LEVEL_GROUP_NAME <EOL> class TestWorkspace ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . workspace_files = [ ] <EOL> def tearDown ( self ) : <EOL> for path in self . workspace_files : <EOL> try : <EOL> os . remove ( path ) <EOL> except : <EOL> logger . warn ( "<STR_LIT>" % path , <EOL> exc_info = <NUM_LIT:1> ) <EOL> def make_workspace_file ( self ) : <EOL> '''<STR_LIT>''' <EOL> pipeline = cpp . Pipeline ( ) <EOL> pipeline . init_modules ( ) <EOL> m = cpmeas . Measurements ( ) <EOL> workspace = cpw . Workspace ( pipeline , None , m , None , m , None ) <EOL> fd , path = tempfile . mkstemp ( "<STR_LIT>" ) <EOL> file_list = workspace . get_file_list ( ) <EOL> file_list . add_files_to_filelist ( <EOL> [ "<STR_LIT>" ] ) <EOL> workspace . save ( path ) <EOL> self . workspace_files . append ( path ) <EOL> os . close ( fd ) <EOL> return path <EOL> def test_01_01_is_workspace_file ( self ) : <EOL> path = self . make_workspace_file ( ) <EOL> self . assertTrue ( cpw . is_workspace_file ( path ) ) <EOL> def test_01_02_is_not_workspace_file ( self ) : <EOL> self . assertFalse ( cpw . is_workspace_file ( __file__ ) ) <EOL> for group in TOP_LEVEL_GROUP_NAME , FILE_LIST_GROUP : <EOL> path = self . make_workspace_file ( ) <EOL> h5file = h5py . File ( path ) <EOL> del h5file [ group ] <EOL> h5file . close ( ) <EOL> self . assertFalse ( cpw . is_workspace_file ( path ) ) <EOL> def test_01_03_file_handle_closed ( self ) : <EOL> path = self . make_workspace_file ( ) <EOL> self . assertTrue ( cpw . is_workspace_file ( path ) ) <EOL> os . remove ( path ) <EOL> self . workspace_files . remove ( path ) <EOL> self . assertFalse ( os . path . isfile ( path ) ) </s>
