コード例 #1
0
    def testStoryRunSucceeded(self):
        run = story_run.StoryRun(self.stories[0])
        self.assertTrue(run.ok)
        self.assertFalse(run.failed)
        self.assertFalse(run.skipped)

        run = story_run.StoryRun(self.stories[0])
        run.AddValue(scalar.ScalarValue(self.stories[0], 'a', 's', 1))
        self.assertTrue(run.ok)
        self.assertFalse(run.failed)
        self.assertFalse(run.skipped)
コード例 #2
0
    def testStoryRunSucceeded(self):
        run = story_run.StoryRun(self.story)
        self.assertTrue(run.ok)
        self.assertFalse(run.failed)
        self.assertFalse(run.skipped)
        self.assertEquals(run.failure_str, None)

        run = story_run.StoryRun(self.story)
        self.assertTrue(run.ok)
        self.assertFalse(run.failed)
        self.assertFalse(run.skipped)
        self.assertEquals(run.failure_str, None)
コード例 #3
0
    def testStoryRunFailed(self):
        run = story_run.StoryRun(self.stories[0])
        run.AddValue(failure.FailureValue.FromMessage(self.stories[0], 'test'))
        self.assertFalse(run.ok)
        self.assertTrue(run.failed)
        self.assertFalse(run.skipped)

        run = story_run.StoryRun(self.stories[0])
        run.AddValue(scalar.ScalarValue(self.stories[0], 'a', 's', 1))
        run.AddValue(failure.FailureValue.FromMessage(self.stories[0], 'test'))
        self.assertFalse(run.ok)
        self.assertTrue(run.failed)
        self.assertFalse(run.skipped)
コード例 #4
0
    def testStoryRunFailed(self):
        run = story_run.StoryRun(self.story)
        run.SetFailed('abc')
        self.assertFalse(run.ok)
        self.assertTrue(run.failed)
        self.assertFalse(run.skipped)
        self.assertEquals(run.failure_str, 'abc')

        run = story_run.StoryRun(self.story)
        run.SetFailed('something is wrong')
        self.assertFalse(run.ok)
        self.assertTrue(run.failed)
        self.assertFalse(run.skipped)
        self.assertEquals(run.failure_str, 'something is wrong')
コード例 #5
0
  def testStoryRunSucceeded(self):
    run = story_run.StoryRun(self.story)
    self.assertTrue(run.ok)
    self.assertFalse(run.failed)
    self.assertFalse(run.skipped)
    self.assertEquals(run.failure_str, None)

    run = story_run.StoryRun(self.story)
    run.AddValue(scalar.ScalarValue(
        self.story, 'a', 's', 1,
        improvement_direction=improvement_direction.UP))
    self.assertTrue(run.ok)
    self.assertFalse(run.failed)
    self.assertFalse(run.skipped)
    self.assertEquals(run.failure_str, None)
コード例 #6
0
 def WillRunPage(self, page, story_run_index=0):
   assert not self.finalized, 'Results are finalized, cannot run more stories.'
   assert not self._current_story_run, 'Did not call DidRunPage.'
   self._current_story_run = story_run.StoryRun(
       page, test_prefix=self.benchmark_name, index=story_run_index,
       intermediate_dir=self._intermediate_dir)
   self._progress_reporter.WillRunStory(self)
コード例 #7
0
 def WillRunPage(self, page, storyset_repeat_counter=0,
                 story_repeat_counter=0):
   assert not self._current_page_run, 'Did not call DidRunPage.'
   self._current_page_run = story_run.StoryRun(page)
   self._progress_reporter.WillRunPage(self)
   self.iteration_info.WillRunStory(
       page, storyset_repeat_counter, story_repeat_counter)
コード例 #8
0
    def CreateStoryRun(self, story, story_run_index=0):
        """A context manager to delimit the capture of results for a new story run.

    Args:
      story: The story to be run.
      story_run_index: An optional integer indicating the number of times this
        same story has been already run as part of the same benchmark run.
    """
        assert not self.finalized, 'Results are finalized, cannot run more stories.'
        assert not self._current_story_run, 'Already running a story'
        self._current_story_run = story_run.StoryRun(
            story,
            test_prefix=self.benchmark_name,
            index=story_run_index,
            intermediate_dir=self._intermediate_dir)
        artifact_logger.RegisterArtifactImplementation(self._current_story_run)
        try:
            with self.CreateArtifact(DIAGNOSTICS_NAME) as f:
                json.dump({'diagnostics': self._diagnostics}, f, indent=4)
            self._progress_reporter.WillRunStory(self._current_story_run)
            yield self._current_story_run
        finally:
            self._current_story_run.Finish()
            self._WriteJsonLine(self._current_story_run.AsDict())
            self._progress_reporter.DidRunStory(self._current_story_run)
            self._all_story_runs.append(self._current_story_run)
            self._current_story_run = None
コード例 #9
0
    def testAddMeasurements(self):
        with tempfile_ext.NamedTemporaryDirectory() as tempdir:
            run = story_run.StoryRun(self.story, intermediate_dir=tempdir)
            run.AddMeasurement('run_time', 'ms', [1, 2, 3])
            run.AddMeasurement('foo_bars',
                               'count',
                               4,
                               description='number of foo_bars found')
            run.Finish()

            artifact = run.GetArtifact(story_run.MEASUREMENTS_NAME)
            with open(artifact.local_path) as f:
                measurements = json.load(f)

            self.assertEqual(
                measurements, {
                    'measurements': [{
                        'name': 'run_time',
                        'unit': 'ms',
                        'samples': [1, 2, 3],
                    }, {
                        'name': 'foo_bars',
                        'unit': 'count',
                        'samples': [4],
                        'description': 'number of foo_bars found'
                    }]
                })
コード例 #10
0
  def testStoryRunFailed(self):
    run = story_run.StoryRun(self.story)
    run.SetFailed('abc')
    self.assertFalse(run.ok)
    self.assertTrue(run.failed)
    self.assertFalse(run.skipped)
    self.assertEquals(run.failure_str, 'abc')

    run = story_run.StoryRun(self.story)
    run.AddValue(scalar.ScalarValue(
        self.story, 'a', 's', 1,
        improvement_direction=improvement_direction.UP))
    run.SetFailed('something is wrong')
    self.assertFalse(run.ok)
    self.assertTrue(run.failed)
    self.assertFalse(run.skipped)
    self.assertEquals(run.failure_str, 'something is wrong')
コード例 #11
0
 def WillRunPage(self, page, story_run_index=0):
     assert not self._current_story_run, 'Did not call DidRunPage.'
     self._current_story_run = story_run.StoryRun(
         page,
         test_prefix=self.benchmark_name,
         index=story_run_index,
         output_dir=self._output_dir)
     self._progress_reporter.WillRunStory(self)
コード例 #12
0
    def testStoryRunSkipped(self):
        run = story_run.StoryRun(self.story)
        run.SetFailed('oops')
        run.Skip('test', is_expected=True)
        self.assertFalse(run.ok)
        self.assertFalse(run.failed)
        self.assertTrue(run.skipped)
        self.assertTrue(run.is_expected)
        self.assertEquals(run.failure_str, 'oops')

        run = story_run.StoryRun(self.story)
        run.Skip('test', is_expected=False)
        self.assertFalse(run.ok)
        self.assertFalse(run.failed)
        self.assertTrue(run.skipped)
        self.assertFalse(run.is_expected)
        self.assertEquals(run.failure_str, None)
コード例 #13
0
    def testStoryRunFailed(self):
        run = story_run.StoryRun(self.stories[0])
        run.SetFailed()
        self.assertFalse(run.ok)
        self.assertTrue(run.failed)
        self.assertFalse(run.skipped)

        run = story_run.StoryRun(self.stories[0])
        run.AddValue(
            scalar.ScalarValue(self.stories[0],
                               'a',
                               's',
                               1,
                               improvement_direction=improvement_direction.UP))
        run.SetFailed()
        self.assertFalse(run.ok)
        self.assertTrue(run.failed)
        self.assertFalse(run.skipped)
コード例 #14
0
    def testCreateArtifact(self):
        with tempfile_ext.NamedTemporaryDirectory() as tempdir:
            run = story_run.StoryRun(self.story, tempdir)
            with run.CreateArtifact('logs') as log_file:
                log_file.write('hi\n')

            filename = run.GetArtifact('logs').local_path
            with open(filename) as f:
                self.assertEqual(f.read(), 'hi\n')
コード例 #15
0
 def WillRunPage(self, page, story_run_index=0):
   assert not self.finalized, 'Results are finalized, cannot run more stories.'
   assert not self._current_story_run, 'Did not call DidRunPage.'
   self._current_story_run = story_run.StoryRun(
       page, test_prefix=self.benchmark_name, index=story_run_index,
       intermediate_dir=self._intermediate_dir)
   with self.CreateArtifact(DIAGNOSTICS_NAME) as f:
     json.dump({'diagnostics': self._diagnostics}, f, indent=4)
   self._progress_reporter.WillRunStory(self)
コード例 #16
0
    def testCreateArtifact(self):
        with tempfile_ext.NamedTemporaryDirectory() as tempdir:
            run = story_run.StoryRun(self.story, intermediate_dir=tempdir)
            with run.CreateArtifact('logs.txt') as log_file:
                log_file.write('hi\n')

            artifact = run.GetArtifact('logs.txt')
            with open(artifact.local_path) as f:
                self.assertEqual(f.read(), 'hi\n')
            self.assertEqual(artifact.content_type, 'text/plain')
コード例 #17
0
    def testStoryRunSkipped(self):
        run = story_run.StoryRun(self.stories[0])
        run.AddValue(failure.FailureValue.FromMessage(self.stories[0], 'test'))
        run.AddValue(skip.SkipValue(self.stories[0], 'test'))
        self.assertFalse(run.ok)
        self.assertFalse(run.failed)
        self.assertTrue(run.skipped)

        run = story_run.StoryRun(self.stories[0])
        run.AddValue(
            scalar.ScalarValue(self.stories[0],
                               'a',
                               's',
                               1,
                               improvement_direction=improvement_direction.UP))
        run.AddValue(skip.SkipValue(self.stories[0], 'test'))
        self.assertFalse(run.ok)
        self.assertFalse(run.failed)
        self.assertTrue(run.skipped)
コード例 #18
0
    def testCreateArtifact(self):
        with tempfile_ext.NamedTemporaryDirectory(
                prefix='artifact_tests') as tempdir:
            run = story_run.StoryRun(self.story, tempdir)
            with run.CreateArtifact('logs', '', '') as log_file:
                filename = log_file.name
                log_file.write('hi\n')

            with open(filename) as f:
                self.assertEqual(f.read(), 'hi\n')
コード例 #19
0
  def testStoryRunSkipped(self):
    run = story_run.StoryRun(self.story)
    run.SetFailed('oops')
    run.Skip('test', is_expected=True)
    self.assertFalse(run.ok)
    self.assertFalse(run.failed)
    self.assertTrue(run.skipped)
    self.assertTrue(run.is_expected)
    self.assertEquals(run.failure_str, 'oops')

    run = story_run.StoryRun(self.story)
    run.AddValue(scalar.ScalarValue(
        self.story, 'a', 's', 1,
        improvement_direction=improvement_direction.UP))
    run.Skip('test', is_expected=False)
    self.assertFalse(run.ok)
    self.assertFalse(run.failed)
    self.assertTrue(run.skipped)
    self.assertFalse(run.is_expected)
    self.assertEquals(run.failure_str, None)
コード例 #20
0
    def testAddArtifactBasic(self, make_patch, move_patch):
        run = story_run.StoryRun(self.story, _abs_join('foo'))

        run.AddArtifact('artifact_name',
                        _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'),
        })
コード例 #21
0
 def testAsDict(self, time_module):
     time_module.time.side_effect = [1234567890.987, 1234567900.987]
     with tempfile_ext.NamedTemporaryDirectory() as tempdir:
         run = story_run.StoryRun(
             story=TestStory(name='http://example.com'),
             test_prefix='benchmark',
             intermediate_dir=tempdir)
         with run.CreateArtifact('logs.txt') as log_file:
             log_file.write('hello\n')
         run.SetTbmMetrics(['metric1', 'metric2'])
         run.Finish()
         entry = run.AsDict()
         self.assertEqual(
             entry, {
                 'testResult': {
                     'testPath':
                     'benchmark/http%3A%2F%2Fexample.com',
                     'status':
                     'PASS',
                     'isExpected':
                     True,
                     'startTime':
                     '2009-02-13T23:31:30.987000Z',
                     'runDuration':
                     '10.00s',
                     'artifacts': {
                         'logs.txt': {
                             'filePath': mock.ANY,
                             'contentType': 'text/plain'
                         }
                     },
                     'tags': [
                         {
                             'key': 'tbmv2',
                             'value': 'metric1'
                         },
                         {
                             'key': 'tbmv2',
                             'value': 'metric2'
                         },
                     ],
                 }
             })
         # Log file is in the {intermediate_dir}/ directory, and file name
         # extension is preserved.
         logs_file = entry['testResult']['artifacts']['logs.txt'][
             'filePath']
         intermediate_dir = os.path.join(tempdir, '')
         self.assertTrue(logs_file.startswith(intermediate_dir))
         self.assertTrue(logs_file.endswith('.txt'))
コード例 #22
0
 def testAddMeasurementValidation(self):
     run = story_run.StoryRun(self.story)
     with self.assertRaises(TypeError):
         run.AddMeasurement(name=None, unit='ms', samples=[1, 2, 3])
     with self.assertRaises(TypeError):
         run.AddMeasurement(name='run_time', unit=7, samples=[1, 2, 3])
     with self.assertRaises(TypeError):
         run.AddMeasurement(name='run_time',
                            unit='ms',
                            samples=[1, None, 3])
     with self.assertRaises(TypeError):
         run.AddMeasurement(name='run_time',
                            unit='ms',
                            samples=[1, 2, 3],
                            description=['not', 'a', 'string'])
コード例 #23
0
    def testIterArtifacts(self):
        with tempfile_ext.NamedTemporaryDirectory() as tempdir:
            run = story_run.StoryRun(self.story, tempdir)

            with run.CreateArtifact('log/log1'):
                pass
            with run.CreateArtifact('trace/trace1'):
                pass
            with run.CreateArtifact('trace/trace2'):
                pass

            all_artifacts = list(run.IterArtifacts())
            self.assertEqual(3, len(all_artifacts))

            logs = list(run.IterArtifacts('log'))
            self.assertEqual(1, len(logs))

            traces = list(run.IterArtifacts('trace'))
            self.assertEqual(2, len(traces))
コード例 #24
0
 def testAsDict(self, time_module):
     time_module.time.side_effect = [1234567890.987, 1234567900.987]
     run = story_run.StoryRun(self.story)
     run.AddValue(
         scalar.ScalarValue(self.story,
                            'a',
                            's',
                            1,
                            improvement_direction=improvement_direction.UP))
     run.Finish()
     self.assertEquals(
         run.AsDict(), {
             'testRun': {
                 'testName': 'foo',
                 'status': 'PASS',
                 'startTime': '2009-02-13T23:31:30.987000Z',
                 'endTime': '2009-02-13T23:31:40.987000Z'
             }
         })
コード例 #25
0
 def testAsDict(self, time_module):
   time_module.time.side_effect = [1234567890.987,
                                   1234567900.987]
   run = story_run.StoryRun(
       story=TestStory(name='http://example.com'), test_prefix='benchmark')
   run.AddValue(scalar.ScalarValue(
       self.story, 'a', 's', 1,
       improvement_direction=improvement_direction.UP))
   run.Finish()
   self.assertEquals(
       run.AsDict(),
       {
           'testResult': {
               'testPath': 'benchmark/http%3A%2F%2Fexample.com',
               'status': 'PASS',
               'isExpected': True,
               'startTime': '2009-02-13T23:31:30.987000Z',
               'runDuration': '10.00s'
           }
       }
   )
コード例 #26
0
  def testIterArtifacts(self):
    with tempfile_ext.NamedTemporaryDirectory() as tempdir:
      run = story_run.StoryRun(self.story, output_dir=tempdir)

      with run.CreateArtifact('log/log1.foo'):
        pass
      with run.CreateArtifact('trace/trace1.json'):
        pass
      with run.CreateArtifact('trace/trace2.json'):
        pass

      all_artifacts = list(run.IterArtifacts())
      self.assertEqual(3, len(all_artifacts))

      logs = list(run.IterArtifacts('log'))
      self.assertEqual(1, len(logs))
      # Falls back to 'application/octet-stream' due to unknown extension.
      self.assertEqual('application/octet-stream', logs[0].content_type)

      traces = list(run.IterArtifacts('trace'))
      self.assertEqual(2, len(traces))
      self.assertTrue(all(t.content_type == 'application/json' for t in traces))
コード例 #27
0
 def WillRunPage(self, page):
     assert not self._current_page_run, 'Did not call DidRunPage.'
     self._current_page_run = story_run.StoryRun(page)
     self._progress_reporter.WillRunPage(self)
コード例 #28
0
 def testAddMeasurementTwiceRaises(self):
     run = story_run.StoryRun(self.story)
     run.AddMeasurement('foo_bars', 'ms', [1])
     with self.assertRaises(AssertionError):
         run.AddMeasurement('foo_bars', 'ms', [2])
コード例 #29
0
 def testAddMeasurementRaisesAfterFinish(self):
     run = story_run.StoryRun(self.story)
     run.AddMeasurement('run_time', 'ms', [1, 2, 3])
     run.Finish()
     with self.assertRaises(AssertionError):
         run.AddMeasurement('foo_bars', 'count', 4)
コード例 #30
0
 def WillRunPage(self, page, storyset_repeat_counter=0):
     assert not self._current_page_run, 'Did not call DidRunPage.'
     self._current_page_run = story_run.StoryRun(page, self._output_dir)
     self._progress_reporter.WillRunPage(self)
     self.telemetry_info.WillRunStory(page, storyset_repeat_counter)