#NEWLINE# def _generate_testworthy_splits( self ) : #NEWLINE# #INDENT# 'Take some non-canonical analysis files and generate test data from them.\n\n    The resulting files will be "canonical". That is, merging and re-splitting them will yield\n    the same files. Therefore the resulting files can be used as test data (after eyeballing them\n    to ensure no pathologies).\n\n    An easy way to generate input for this function is to run a scala compile on some targets using\n    --strategy=isolated. Then .pants.d/compile/jvm/scala/isolated-analysis/ will contain a bunch\n    of per-target analysis files.\n\n    Those files can be anonymized (see anonymize_analysis.py), ideally with some non-ASCII words\n    thrown in (as explained there), and then you can point this function to those anonymized\n    files by setting ZINC_ANALYSIS_TEST_DATA_SOURCE=<dir> in the environment and running this test.\n\n    Note: Yes, it\'s slightly problematic that we\'re using the very code we\'re testing to generate\n    the test inputs. Hence the need to spot-check for obvious pathologies.\n    ' #NEWLINE# original_splits_dir = os . environ . get ( _TEST_DATA_SOURCE_ENV_VAR ) #NEWLINE# canonical_dir = os . path . join ( original_splits_dir , 'canonical' ) #NEWLINE# if os . path . exists ( canonical_dir ) : #NEWLINE# #INDENT# shutil . rmtree ( canonical_dir , True ) #NEWLINE# #UNINDENT# os . mkdir ( canonical_dir ) #NEWLINE# original_split_filenames = [ f . decode ( 'utf-8' ) for f in os . listdir ( original_splits_dir ) ] #NEWLINE# original_splits_files = [ os . path . join ( original_splits_dir , f ) for f in original_split_filenames if f . endswith ( '.analysis' ) ] #NEWLINE# parser = ZincAnalysisParser ( ) #NEWLINE# original_split_analyses = [ parser . parse_from_path ( f ) for f in original_splits_files ] #NEWLINE# merged_analysis = ZincAnalysis . merge ( original_split_analyses ) #NEWLINE# merged_analysis . write_to_path ( os . path . join ( canonical_dir , 'all.merged.analysis' ) ) #NEWLINE# sources_per_analysis = [ a . stamps . sources . keys ( ) for a in original_split_analyses ] #NEWLINE# split_analyses = merged_analysis . split ( sources_per_analysis , os . path . dirname ( __file__ ) ) #NEWLINE# for ( original_split_file , split_analysis ) in zip ( original_splits_files , split_analyses ) : #NEWLINE# #INDENT# outpath = os . path . join ( canonical_dir , os . path . basename ( original_split_file ) ) #NEWLINE# split_analysis . write_to_path ( outpath ) #NEWLINE# #UNINDENT# print ( 'Wrote canonical analysis data to {}' . format ( original_split_filenames ) )