def test_keyword_replaced(self): thrift_contents = dedent(''' namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 from } ''') expected_replaced_contents = dedent(''' namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 from_ } ''') builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) m = mock_open(read_data=thrift_contents) with patch('__builtin__.open', m, create=True): builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) builder._modify_thrift('thrift_dummmy.thrift') expected_open_call_list = [call('thrift_dummmy.thrift'), call('thrift_dummmy.thrift', 'w')] m.call_args_list == expected_open_call_list mock_file_handle = m() mock_file_handle.write.assert_called_once_with(expected_replaced_contents)
def test_non_keyword_file(self): thrift_contents = dedent(''' namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 no_keyword 2: i16 from_ 3: i16 _fromdsd 4: i16 FROM 5: i16 fromsuffix } ''') builder = PythonThriftBuilder( target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) m = mock_open(read_data=thrift_contents) with patch('__builtin__.open', m, create=True): builder = PythonThriftBuilder( target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) builder._modify_thrift('thrift_dummmy.thrift') expected_open_call_list = [ call('thrift_dummmy.thrift'), call('thrift_dummmy.thrift', 'w') ] m.call_args_list == expected_open_call_list mock_file_handle = m() mock_file_handle.write.assert_called_once_with(thrift_contents)
def test_keyword_replaced(self): # These are ensure_binary because python's read() does not do decoding thrift_contents = dedent(''' # This file contains UTF-8: Anasûrimbor Kellhus namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 from } ''').encode('utf-8') expected_replaced_contents = ensure_binary(dedent(''' # This file contains UTF-8: Anasûrimbor Kellhus namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 from_ } ''').encode('utf-8')) builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) m = mock_open(read_data=thrift_contents) with patch('__builtin__.open', m, create=True): builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) builder._modify_thrift('thrift_dummmy.thrift') expected_open_call_list = [call('thrift_dummmy.thrift'), call('thrift_dummmy.thrift', 'w')] m.call_args_list == expected_open_call_list mock_file_handle = m() mock_file_handle.write.assert_called_once_with(expected_replaced_contents)
def prepare_task(self, config=None, args=None, targets=None, build_graph=None, build_file_parser=None, address_mapper=None, console_outstream=None, workspace=None): """Prepares a Task for execution. task_type: The class of the Task to create. config: An optional string representing the contents of a pants.ini config. args: optional list of command line flags, these should be prefixed with '--test-'. targets: optional list of Target objects passed on the command line. Returns a new Task ready to execute. """ task_type = self.task_type() assert issubclass( task_type, Task), 'task_type must be a Task subclass, got %s' % task_type config = create_config(config or '') workdir = os.path.join(config.getdefault('pants_workdir'), 'test', task_type.__name__) bootstrap_options = OptionsBootstrapper().get_bootstrap_options() options = Options(env={}, config=config, known_scopes=['', 'test'], args=args or []) # A lot of basic code uses these options, so always register them. register_bootstrap_options(options.register_global) # We need to wrap register_global (can't set .bootstrap attr on the bound instancemethod). def register_global_wrapper(*args, **kwargs): return options.register_global(*args, **kwargs) register_global_wrapper.bootstrap = bootstrap_options.for_global_scope( ) register_global_options(register_global_wrapper) task_type.options_scope = 'test' task_type.register_options_on_scope(options) run_tracker = create_run_tracker() context = Context(config, options, run_tracker, targets or [], build_graph=build_graph, build_file_parser=build_file_parser, address_mapper=address_mapper, console_outstream=console_outstream, workspace=workspace) return task_type(context, workdir)
def test_debug_config_default(self): config = create_config() self.assertEquals(5005, JvmDebugConfig.debug_port(config)) self.assertEquals([ '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005' ], JvmDebugConfig.debug_args(config))
def prepare_task(task_type, config=None, args=None, targets=None, **kwargs): """Prepares a Task for execution. task_type: The class of the Task to create. config: An optional string representing the contents of a pants.ini config. args: optional list of command line flags, these should be prefixed with '--test-'. targets: optional list of Target objects passed on the command line. **kwargs: Any additional args the Task subclass constructor takes beyond the required context. Returns a new Task ready to execute. """ assert issubclass(task_type, Task), 'task_type must be a Task subclass, got %s' % task_type config = create_config(config or '') parser = OptionParser() option_group = OptionGroup(parser, 'test') mkflag = Mkflag('test') task_type.setup_parser(option_group, args, mkflag) options, _ = parser.parse_args(args or []) run_tracker = create_run_tracker() context = Context(config, options, run_tracker, targets or []) return task_type(context, **kwargs)
def test_debug_config_override(self): config = create_config(dedent(""" [jvm] debug_port: 12345 debug_args: ['foo', 'bar', 'port=%(debug_port)s'] """)) self.assertEquals(12345, JvmDebugConfig.debug_port(config)) self.assertEquals(['foo', 'bar', 'port=12345'], JvmDebugConfig.debug_args(config))
def test_debug_config_override(self): config = create_config( dedent(""" [jvm] debug_port: 12345 debug_args: ['foo', 'bar', 'port=%(debug_port)s'] """)) self.assertEquals(12345, JvmDebugConfig.debug_port(config)) self.assertEquals(['foo', 'bar', 'port=12345'], JvmDebugConfig.debug_args(config))
def prepare_task(self, config=None, args=None, targets=None, build_graph=None, build_file_parser=None, address_mapper=None, console_outstream=None, workspace=None): """Prepares a Task for execution. task_type: The class of the Task to create. config: An optional string representing the contents of a pants.ini config. args: optional list of command line flags, these should be prefixed with '--test-'. targets: optional list of Target objects passed on the command line. Returns a new Task ready to execute. """ task_type = self.task_type() assert issubclass(task_type, Task), 'task_type must be a Task subclass, got %s' % task_type config = create_config(config or '') workdir = os.path.join(config.getdefault('pants_workdir'), 'test', task_type.__name__) bootstrap_options = OptionsBootstrapper().get_bootstrap_options() options = Options(env={}, config=config, known_scopes=['', 'test'], args=args or []) # A lot of basic code uses these options, so always register them. register_bootstrap_options(options.register_global) # We need to wrap register_global (can't set .bootstrap attr on the bound instancemethod). def register_global_wrapper(*args, **kwargs): return options.register_global(*args, **kwargs) register_global_wrapper.bootstrap = bootstrap_options.for_global_scope() register_global_options(register_global_wrapper) task_type.options_scope = 'test' task_type.register_options_on_scope(options) run_tracker = create_run_tracker() context = Context(config, options, run_tracker, targets or [], build_graph=build_graph, build_file_parser=build_file_parser, address_mapper=address_mapper, console_outstream=console_outstream, workspace=workspace) return task_type(context, workdir)
def prepare_task(self, config=None, args=None, targets=None, build_graph=None, build_file_parser=None, address_mapper=None, console_outstream=None, workspace=None): """Prepares a Task for execution. task_type: The class of the Task to create. config: An optional string representing the contents of a pants.ini config. args: optional list of command line flags, these should be prefixed with '--test-'. targets: optional list of Target objects passed on the command line. Returns a new Task ready to execute. """ task_type = self.task_type() assert issubclass(task_type, Task), 'task_type must be a Task subclass, got %s' % task_type config = create_config(config or '') workdir = os.path.join(config.getdefault('pants_workdir'), 'test', task_type.__name__) parser = OptionParser() option_group = OptionGroup(parser, 'test') mkflag = Mkflag('test') new_options = Options(env={}, config=config, known_scopes=['', 'test'], args=args or [], legacy_parser=parser) task_type.options_scope = 'test' task_type.register_options_on_scope(new_options) task_type.setup_parser(option_group, args, mkflag) old_options, _ = parser.parse_args(args or []) run_tracker = create_run_tracker() context = Context(config, old_options, new_options, run_tracker, targets or [], build_graph=build_graph, build_file_parser=build_file_parser, address_mapper=address_mapper, console_outstream=console_outstream, workspace=workspace) return task_type(context, workdir)
def test_keyword_replaced(self): # These are ensure_binary because python's read() does not do decoding thrift_contents = dedent(''' # This file contains UTF-8: Anasûrimbor Kellhus namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 from } ''').encode('utf-8') expected_replaced_contents = ensure_binary( dedent(''' # This file contains UTF-8: Anasûrimbor Kellhus namespace py gen.twitter.tweetypie.tweet struct UrlEntity { 1: i16 from_ } ''').encode('utf-8')) builder = PythonThriftBuilder( target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) m = mock_open(read_data=thrift_contents) with patch('__builtin__.open', m, create=True): builder = PythonThriftBuilder( target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) builder._modify_thrift('thrift_dummmy.thrift') expected_open_call_list = [ call('thrift_dummmy.thrift'), call('thrift_dummmy.thrift', 'w') ] m.call_args_list == expected_open_call_list mock_file_handle = m() mock_file_handle.write.assert_called_once_with( expected_replaced_contents)
def test_keyword_replacement(self): m = mock_open(read_data='') with patch('__builtin__.open', m, create=True): with patch('shutil.copyfile'): builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'), root_dir=self.build_root, config=create_config(sample_ini=sample_ini_test)) builder._modify_thrift = MagicMock() builder._run_thrift = MagicMock() builder.run_thrifts() builder._modify_thrift.assert_called_once_with(os.path.realpath('%s/thrift/py-thrift/%s' % (self.build_root, 'thrift/keyword.thrift')))
def setUp(self): super(IvyUtilsGenerateIvyTest, self).setUp() self.add_to_build_file('src/java/targets', dedent(''' jar_library( name='simple', jars=[ jar('org1', 'name1', 'rev1'), jar('org2', 'name2', 'rev2', force=True), ] ) ''')) self.simple = self.target('src/java/targets:simple') self.ivy_utils = IvyUtils(create_config(), self.create_options(), logging.Logger('test'))
def prepare_task(task_type, config=None, args=None, targets=None, build_graph=None, build_file_parser=None, address_mapper=None, console_outstream=None, workspace=None): """Prepares a Task for execution. task_type: The class of the Task to create. config: An optional string representing the contents of a pants.ini config. args: optional list of command line flags, these should be prefixed with '--test-'. targets: optional list of Target objects passed on the command line. Returns a new Task ready to execute. """ assert issubclass( task_type, Task), 'task_type must be a Task subclass, got %s' % task_type config = create_config(config or '') workdir = os.path.join(config.getdefault('pants_workdir'), 'test', task_type.__name__) parser = OptionParser() option_group = OptionGroup(parser, 'test') mkflag = Mkflag('test') task_type.setup_parser(option_group, args, mkflag) options, _ = parser.parse_args(args or []) run_tracker = create_run_tracker() context = Context(config, options, run_tracker, targets or [], build_graph=build_graph, build_file_parser=build_file_parser, address_mapper=address_mapper, console_outstream=console_outstream, workspace=workspace) return task_type(context, workdir)
def setUp(self): super(IvyUtilsGenerateIvyTest, self).setUp() self.add_to_build_file( 'src/java/targets', dedent(''' jar_library( name='simple', jars=[ jar('org1', 'name1', 'rev1'), jar('org2', 'name2', 'rev2', force=True), ] ) ''')) self.simple = self.target('src/java/targets:simple') self.ivy_utils = IvyUtils(create_config(), self.create_options(), logging.Logger('test'))
def setUp(self): super(IvyUtilsGenerateIvyTest, self).setUp() self.ivy_utils = IvyUtils(create_config(), self.create_options(), logging.Logger('test'))
def test_debug_config_default(self): config = create_config() self.assertEquals(5005, JvmDebugConfig.debug_port(config)) self.assertEquals(['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'], JvmDebugConfig.debug_args(config))
def create_defaults(ini=''): config = create_config(ini) return JavaThriftLibrary.Defaults(config)