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')))
Example #3
0
 def _dump_thrift_library(self, library):
   builder = PythonThriftBuilder(library, self.root)
   print '  Generating %s...' % library
   egg_file = builder.build_egg()
   if egg_file:
     egg_file = os.path.relpath(egg_file, self.root)
     for pkg in builder.packages():
       print '    found namespace: %s' % pkg
     # make a random string to disambiguate possibly similarly-named eggs?
     randstr = ''.join(map(chr, random.sample(range(ord('a'), ord('z')), 8))) + '_'
     print '    copying...',
     self.chroot.copy(egg_file, os.path.join('.deps', randstr + os.path.basename(egg_file)), 'resources')
     print 'done.'
   else:
     print '   Failed!'
     raise PythonChroot.BuildFailureException(
       "Failed to build %s!" % library)
Example #4
0
 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)
Example #5
0
    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')))
Example #6
0
 def _dump_thrift_library(self, library):
     self._dump_built_library(library,
                              PythonThriftBuilder(library, self._root))
Example #7
0
 def _dump_thrift_library(self, library):
     print '  Generating %s...' % library
     self._dump_built_library(PythonThriftBuilder(library, self.root))