<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> import time <EOL> from pants . backend . jvm . tasks . jvm_compile . zinc . zinc_compile import ZincCompile <EOL> from pants . util . contextutil import temporary_dir <EOL> from pants . util . dirutil import safe_mkdir , touch <EOL> from pants_test . pants_run_integration_test import PantsRunIntegrationTest <EOL> class CacheCleanupIntegrationTest ( PantsRunIntegrationTest ) : <EOL> def create_platform_args ( self , version ) : <EOL> return [ ( """<STR_LIT>""" <EOL> . format ( version = version ) ) , <EOL> '<STR_LIT>' ] <EOL> def test_buildcache_leave_one ( self ) : <EOL> """<STR_LIT>""" <EOL> with temporary_dir ( ) as cache_dir : <EOL> artifact_dir = os . path . join ( cache_dir , ZincCompile . stable_name ( ) , <EOL> '<STR_LIT>' ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> config = { '<STR_LIT>' : { '<STR_LIT>' : [ cache_dir ] } } <EOL> pants_run = self . run_pants ( self . create_platform_args ( <NUM_LIT:6> ) + <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> config = config ) <EOL> self . assert_success ( pants_run ) <EOL> self . assertEqual ( len ( os . listdir ( artifact_dir ) ) , <NUM_LIT:1> ) <EOL> pants_run = self . run_pants ( self . create_platform_args ( <NUM_LIT:7> ) + <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> config ) <EOL> self . assert_success ( pants_run ) <EOL> self . assertEqual ( len ( os . listdir ( artifact_dir ) ) , <NUM_LIT:1> ) <EOL> def test_buildcache_leave_none ( self ) : <EOL> """<STR_LIT>""" <EOL> with temporary_dir ( ) as cache_dir : <EOL> artifact_dir = os . path . join ( cache_dir , ZincCompile . stable_name ( ) , <EOL> '<STR_LIT>' ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> touch ( os . path . join ( artifact_dir , '<STR_LIT>' ) ) <EOL> config = { '<STR_LIT>' : { '<STR_LIT>' : [ cache_dir ] } } <EOL> pants_run = self . run_pants ( self . create_platform_args ( <NUM_LIT:6> ) + <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> config = config ) <EOL> self . assert_success ( pants_run ) <EOL> self . assertEqual ( len ( os . listdir ( artifact_dir ) ) , <NUM_LIT:6> ) <EOL> pants_run = self . run_pants ( self . create_platform_args ( <NUM_LIT:7> ) + <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> config ) <EOL> self . assert_success ( pants_run ) <EOL> self . assertEqual ( len ( os . listdir ( artifact_dir ) ) , <NUM_LIT:7> ) <EOL> def test_workdir_stale_builds_cleanup ( self ) : <EOL> """<STR_LIT>""" <EOL> with temporary_dir ( ) as tmp_dir : <EOL> workdir = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> pants_run = self . run_pants_with_workdir ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , workdir ) <EOL> self . assert_success ( pants_run ) <EOL> classpath = '<STR_LIT>' <EOL> jar_path_in_pantsd = os . path . realpath ( classpath ) <EOL> target_dir_in_pantsd = os . path . dirname ( os . path . dirname ( jar_path_in_pantsd ) ) <EOL> safe_mkdir ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) <EOL> safe_mkdir ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) <EOL> safe_mkdir ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> safe_mkdir ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) <EOL> safe_mkdir ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) <EOL> self . assertTrue ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( len ( os . listdir ( target_dir_in_pantsd ) ) , <NUM_LIT:7> ) <EOL> max_entries_per_target = <NUM_LIT:2> <EOL> pants_run_2 = self . run_pants_with_workdir ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( max_entries_per_target ) <EOL> ] , workdir ) <EOL> self . assert_success ( pants_run_2 ) <EOL> self . assertEqual ( len ( os . listdir ( target_dir_in_pantsd ) ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( os . path . exists ( os . path . join ( target_dir_in_pantsd , '<STR_LIT>' ) ) ) </s>
