<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from textwrap import dedent <EOL> from pants . backend . codegen . targets . java_ragel_library import JavaRagelLibrary <EOL> from pants . backend . codegen . tasks . ragel_gen import RagelGen , calculate_genfile <EOL> from pants . util . contextutil import temporary_file <EOL> from pants . util . dirutil import safe_mkdtemp <EOL> from pants_test . tasks . task_test_base import TaskTestBase <EOL> ragel_file_contents = dedent ( """<STR_LIT>""" ) <EOL> class RagelGenTest ( TaskTestBase ) : <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return RagelGen <EOL> def test_ragel_gen ( self ) : <EOL> self . create_file ( relpath = '<STR_LIT>' , contents = ragel_file_contents ) <EOL> target = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JavaRagelLibrary , <EOL> sources = [ '<STR_LIT>' ] ) <EOL> task = self . create_task ( self . context ( target_roots = [ target ] ) ) <EOL> target_workdir = safe_mkdtemp ( dir = self . test_workdir ) <EOL> task . execute_codegen ( target , target_workdir ) <EOL> generated_files = [ ] <EOL> for root , _ , files in os . walk ( target_workdir ) : <EOL> generated_files . extend ( os . path . relpath ( os . path . join ( root , f ) , target_workdir ) for f in files ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , generated_files ) <EOL> def test_smoke ( self ) : <EOL> with temporary_file ( ) as fp : <EOL> fp . write ( ragel_file_contents ) <EOL> fp . flush ( ) <EOL> self . assertEquals ( calculate_genfile ( fp . name ) , '<STR_LIT>' ) </s>
