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_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 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)