Example #1
0
 def _StopProfiling(self, results):
     if self.browser:
         profiler_files = self.browser.profiling_controller.Stop()
         for f in profiler_files:
             if os.path.isfile(f):
                 results.AddProfilingFile(self._current_page,
                                          file_handle.FromFilePath(f))
Example #2
0
    def testCreatingFileHandle(self):
        fh1 = file_handle.FromTempFile(self.temp_file_txt)
        self.assertEquals(fh1.extension, '.txt')

        fh2 = file_handle.FromFilePath(self.abs_path_html)
        self.assertEquals(fh2.extension, '.html')
        self.assertNotEquals(fh1.id, fh2.id)
Example #3
0
 def _GetTempFileHandle(self, trace_data):
     tf = tempfile.NamedTemporaryFile(delete=False, suffix='.html')
     tf.close()
     title = ''
     if self.page:
         title = self.page.name
     trace_data.Serialize(tf.name, trace_title=title)
     return file_handle.FromFilePath(tf.name)
Example #4
0
 def Serialize(self, dir_path):
     if self._temp_file is None:
         raise ValueError('Tried to serialize nonexistent trace.')
     file_name = str(self._temp_file.id) + self._temp_file.extension
     file_path = os.path.abspath(os.path.join(dir_path, file_name))
     shutil.copy(self._temp_file.GetAbsPath(), file_path)
     self._serialized_file_handle = file_handle.FromFilePath(file_path)
     return self._serialized_file_handle
Example #5
0
 def Serialize(self):
   if self._temp_file is None:
     raise ValueError('Tried to serialize nonexistent trace.')
   if self._file_path is None:
     raise ValueError('Serialize requires file_path.')
   shutil.copy(self._temp_file.GetAbsPath(), self._file_path)
   self._serialized_file_handle = file_handle.FromFilePath(self._file_path)
   return self._serialized_file_handle
Example #6
0
    def testAddArtifactFileHandle(self, make_patch, move_patch):
        run = story_run.StoryRun(self.story, _abs_join('foo'))

        run.AddArtifact(
            'artifact_name',
            file_handle.FromFilePath(
                _abs_join('', 'foo', 'artifacts', 'bar.log')))
        move_patch.assert_not_called()
        make_patch.assert_called_with(_abs_join('foo', 'artifacts'))

        self.assertEqual(run._artifacts, {
            'artifact_name': os.path.join('artifacts', 'bar.log'),
        })
  def testAddFileHandle(self, make_patch, move_patch):
    ar = artifact_results.ArtifactResults(_abs_join('foo'))

    ar.AddArtifact('test', 'artifact_name', file_handle.FromFilePath(
        _abs_join('', 'foo', 'artifacts', 'bar.log')))
    move_patch.assert_not_called()
    make_patch.assert_called_with(_abs_join('foo', 'artifacts'))

    self.assertEqual({k: dict(v) for k, v in ar._test_artifacts.items()}, {
        'test': {
            'artifact_name': ['artifacts/bar.log'],
        }
    })
Example #8
0
 def Serialize(self, dir_path):
     if self._temp_file is None:
         raise ValueError('Tried to serialize nonexistent trace.')
     if self.page:
         file_name = self.page.file_safe_name
     else:
         file_name = ''
     file_name += str(self._temp_file.id)
     file_name += datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
     file_name += self._temp_file.extension
     file_path = os.path.abspath(os.path.join(dir_path, file_name))
     shutil.copy(self._temp_file.GetAbsPath(), file_path)
     self._serialized_file_handle = file_handle.FromFilePath(file_path)
     return self._serialized_file_handle