<s> '''<STR_LIT>''' <EOL> import datetime <EOL> import os <EOL> import shutil <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> import unittest <EOL> import urllib <EOL> from cStringIO import StringIO <EOL> import dateutil . parser <EOL> from cellprofiler . modules . tests import example_images_directory , maybe_download_example_images <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> ARGLIST_START = [ sys . executable ] <EOL> else : <EOL> ARGLIST_START = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> @ unittest . skipIf ( sys . platform != '<STR_LIT:win32>' , "<STR_LIT>" ) <EOL> class TestCellProfiler ( unittest . TestCase ) : <EOL> def run_cellprofiler ( self , * args ) : <EOL> '''<STR_LIT>''' <EOL> if hasattr ( sys , "<STR_LIT>" ) : <EOL> args = [ sys . argv [ <NUM_LIT:0> ] ] + list ( args ) <EOL> return subprocess . check_output ( args ) <EOL> elif sys . platform == '<STR_LIT>' : <EOL> self . skipTest ( "<STR_LIT>" ) <EOL> else : <EOL> test_dir = os . path . dirname ( __file__ ) <EOL> cellprofiler_dir = os . path . dirname ( test_dir ) <EOL> root_dir = os . path . dirname ( cellprofiler_dir ) <EOL> cellprofiler_path = os . path . join ( root_dir , "<STR_LIT>" ) <EOL> self . assertTrue ( os . path . isfile ( cellprofiler_path ) ) <EOL> args = [ sys . executable , cellprofiler_path , <EOL> "<STR_LIT>" , "<STR_LIT>" ] + list ( args ) <EOL> return subprocess . check_output ( args , cwd = root_dir ) <EOL> def test_01_01_html ( self ) : <EOL> path = tempfile . mkdtemp ( ) <EOL> try : <EOL> self . run_cellprofiler ( "<STR_LIT>" , "<STR_LIT>" , path ) <EOL> filenames = os . listdir ( path ) <EOL> self . assertTrue ( "<STR_LIT>" in filenames ) <EOL> finally : <EOL> shutil . rmtree ( path ) <EOL> @ unittest . skipIf ( hasattr ( sys , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> def test_01_02_code_statistics ( self ) : <EOL> old_stdout = sys . stdout <EOL> fake_stdout = StringIO ( <EOL> self . run_cellprofiler ( "<STR_LIT>" ) ) <EOL> fake_stdout . seek ( <NUM_LIT:0> ) <EOL> found_module_stats = False <EOL> found_setting_stats = False <EOL> found_lines_of_code = False <EOL> for line in fake_stdout . readlines ( ) : <EOL> if line . startswith ( "<STR_LIT>" ) : <EOL> found_module_stats = True <EOL> elif line . startswith ( "<STR_LIT>" ) : <EOL> found_setting_stats = True <EOL> elif line . startswith ( "<STR_LIT>" ) : <EOL> found_lines_of_code = True <EOL> self . assertTrue ( found_module_stats ) <EOL> self . assertTrue ( found_setting_stats ) <EOL> self . assertTrue ( found_lines_of_code ) <EOL> def test_01_03_version ( self ) : <EOL> import cellprofiler . utilities . version as V <EOL> output = self . run_cellprofiler ( "<STR_LIT>" ) <EOL> version = dict ( [ tuple ( line . strip ( ) . split ( "<STR_LIT:U+0020>" ) ) <EOL> for line in output . split ( "<STR_LIT:\n>" ) <EOL> if "<STR_LIT:U+0020>" in line ] ) <EOL> self . assertEqual ( version [ "<STR_LIT>" ] , V . dotted_version ) <EOL> self . assertEqual ( version [ "<STR_LIT>" ] , V . git_hash ) <EOL> self . assertEqual ( int ( version [ "<STR_LIT>" ] [ : <NUM_LIT:8> ] ) , <EOL> int ( V . version_number / <NUM_LIT> ) ) <EOL> built = dateutil . parser . parse ( version [ "<STR_LIT>" ] ) <EOL> self . assertLessEqual ( built . date ( ) , datetime . date . today ( ) ) <EOL> def test_02_01_run_headless ( self ) : <EOL> output_directory = tempfile . mkdtemp ( ) <EOL> temp_directory = os . path . join ( output_directory , "<STR_LIT>" ) <EOL> os . mkdir ( temp_directory ) <EOL> try : <EOL> fly_pipe = "<STR_LIT>" <EOL> urllib . URLopener ( ) . open ( fly_pipe ) . close ( ) <EOL> measurements_file = os . path . join ( output_directory , "<STR_LIT>" ) <EOL> done_file = os . path . join ( output_directory , "<STR_LIT>" ) <EOL> self . run_cellprofiler ( "<STR_LIT:-c>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , output_directory , <EOL> "<STR_LIT>" , fly_pipe , <EOL> "<STR_LIT>" , done_file , <EOL> "<STR_LIT>" , temp_directory , <EOL> "<STR_LIT>" , "<STR_LIT:1>" , <EOL> "<STR_LIT>" , "<STR_LIT:1>" , <EOL> measurements_file ) <EOL> import cellprofiler . preferences as cpprefs <EOL> self . assertTrue ( os . path . exists ( measurements_file ) ) <EOL> self . assertTrue ( os . path . exists ( done_file ) ) <EOL> m2_file = os . path . join ( output_directory , "<STR_LIT>" ) <EOL> self . run_cellprofiler ( "<STR_LIT:-c>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , output_directory , <EOL> "<STR_LIT>" , "<STR_LIT:1>" , <EOL> "<STR_LIT>" , "<STR_LIT:1>" , <EOL> "<STR_LIT>" , measurements_file , <EOL> m2_file ) <EOL> self . assertTrue ( os . path . exists ( m2_file ) ) <EOL> except IOError , e : <EOL> if e . args [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> raise e <EOL> def bad_url ( e = e ) : <EOL> raise e <EOL> unittest . expectedFailure ( bad_url ) ( ) <EOL> finally : <EOL> shutil . rmtree ( output_directory ) </s>
