def testShouldDisableComplex(self):
        """Ensure that browser-dependent ShouldDisable overrides are respected."""
        expected_printed_stream = (
            # Expected output for 'TestBrowser':
            'Available benchmarks for TestBrowser are:\n'
            '  FooBenchmark      Benchmark Foo for testing.\n'
            '\n'
            'Disabled benchmarks for TestBrowser are (force run with -d):\n'
            '  BarBenchmarkkkkk  Benchmark Bar for testing long description line.\n'
            'Pass --browser to list benchmarks for another browser.\n\n'
            # Expected output for 'MockBrowser':
            'Available benchmarks for MockBrowser are:\n'
            '  BarBenchmarkkkkk  Benchmark Bar for testing long description line.\n'
            '  FooBenchmark      Benchmark Foo for testing.\n'
            'Pass --browser to list benchmarks for another browser.\n\n')

        @classmethod
        def FakeShouldDisable(cls, possible_browser):
            return cls is BenchmarkBar and not 'Mock' in possible_browser.browser_type

        BenchmarkFoo.ShouldDisable = FakeShouldDisable
        BenchmarkBar.ShouldDisable = FakeShouldDisable
        benchmark_runner.PrintBenchmarkList([BenchmarkFoo, BenchmarkBar],
                                            self._mock_possible_browser,
                                            self._stream)
        self._mock_possible_browser.browser_type = 'MockBrowser'
        benchmark_runner.PrintBenchmarkList([BenchmarkFoo, BenchmarkBar],
                                            self._mock_possible_browser,
                                            self._stream)
        self.assertEquals(expected_printed_stream, self._stream.output_data)
Esempio n. 2
0
  def testPrintBenchmarkListWithOneDisabledBenchmark(self):
    expected_printed_stream = (
        'Available benchmarks for TestBrowser are:\n'
        '  BenchmarkFoo Benchmark foo for testing.\n'
        '\n'
        'Disabled benchmarks for TestBrowser are (force run with -d):\n'
        '  BenchmarkBar Benchmark bar for testing.\n'
        'Pass --browser to list benchmarks for another browser.\n\n')

    expectations_file_contents = (
        '# tags: All\n'
        'crbug.com/123 [ All ] BenchmarkBar/* [ Skip ]\n'
    )

    expectations_file = tempfile.NamedTemporaryFile(bufsize=0, delete=False)
    try:
      expectations_file.write(expectations_file_contents)
      expectations_file.close()
      benchmark_runner.PrintBenchmarkList([BenchmarkFoo, BenchmarkBar],
                                          self._mock_possible_browser,
                                          expectations_file.name,
                                          self._stream)

      self.assertEquals(expected_printed_stream, self._stream.getvalue())

    finally:
      os.remove(expectations_file.name)
    def testPrintBenchmarkListInJSON(self):
        expected_printed_stream = json.dumps(
            [{
                'name': BenchmarkFoo.Name(),
                'description': BenchmarkFoo.Description(),
                'enabled': True
            }, {
                'name': BenchmarkBar.Name(),
                'description': BenchmarkBar.Description(),
                'enabled': False
            }],
            indent=4,
            sort_keys=True,
            separators=(',', ': '))

        expectations_file_contents = (
            '# tags: All\n'
            'crbug.com/123 [ All ] BenchmarkBar/* [ Skip ]\n')

        expectations_file = tempfile.NamedTemporaryFile(bufsize=0,
                                                        delete=False)
        try:
            expectations_file.write(expectations_file_contents)
            expectations_file.close()
            benchmark_runner.PrintBenchmarkList([BenchmarkFoo, BenchmarkBar],
                                                self._mock_possible_browser,
                                                expectations_file.name,
                                                self._stream,
                                                as_json=True)

            self.assertEquals(expected_printed_stream, self._stream.getvalue())

        finally:
            os.remove(expectations_file.name)
Esempio n. 4
0
 def testPrintBenchmarkListWithNoDisabledBenchmark(self):
   expected_printed_stream = (
       'Available benchmarks for TestBrowser are:\n'
       '  BenchmarkBar Benchmark bar for testing.\n'
       '  BenchmarkFoo Benchmark foo for testing.\n'
       'Pass --browser to list benchmarks for another browser.\n\n')
   benchmark_runner.PrintBenchmarkList([BenchmarkBar, BenchmarkFoo],
                                       self._mock_possible_browser, None,
                                       self._stream)
   self.assertEquals(expected_printed_stream, self._stream.getvalue())
Esempio n. 5
0
 def testPrintBenchmarkListWithNoDisabledBenchmark(self):
     expected_printed_stream = (
         'Available benchmarks for TestBrowser are:\n'
         '  EnabledBench  Enabled benchmark for testing.\n'
         '  EnabledBench  Enabled benchmark for testing.\n'
         'Pass --browser to list benchmarks for another browser.\n\n')
     benchmark_runner.PrintBenchmarkList(
         [BenchmarkEnabled, BenchmarkEnabled], self._mock_possible_browser,
         None, self._stream)
     self.assertEquals(expected_printed_stream, self._stream.output_data)
Esempio n. 6
0
 def testPrintBenchmarkListWithNoDisabledBenchmark(self):
   expected_printed_stream = (
       'Available benchmarks for TestBrowser are:\n'
       '  BarBenchmarkkkkk  Benchmark Bar for testing long description line.\n'
       '  FooBenchmark      Benchmark Foo for testing.\n'
       'Pass --browser to list benchmarks for another browser.\n\n')
   with mock.patch('telemetry.benchmark_runner.decorators') as mock_module:
     mock_module.IsEnabled.return_value = (True, None)
     benchmark_runner.PrintBenchmarkList(
       [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream)
     self.assertEquals(expected_printed_stream, self._stream.output_data)
Esempio n. 7
0
 def testShouldDisable(self):
   """Ensure that overridden ShouldDisable class methods are respected."""
   expected_printed_stream = (
       'Available benchmarks for TestBrowser are:\n'
       '  BarBenchmarkkkkk  Benchmark Bar for testing long description line.\n'
       '\n'
       'Disabled benchmarks for TestBrowser are (force run with -d):\n'
       '  FooBenchmark      Benchmark Foo for testing.\n'
       'Pass --browser to list benchmarks for another browser.\n\n')
   @classmethod
   def FakeShouldDisable(cls, possible_browser):
     del possible_browser  # unused
     return cls is BenchmarkFoo
   BenchmarkFoo.ShouldDisable = FakeShouldDisable
   BenchmarkBar.ShouldDisable = FakeShouldDisable
   benchmark_runner.PrintBenchmarkList(
     [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream)
   self.assertEquals(expected_printed_stream, self._stream.output_data)
Esempio n. 8
0
 def testPrintBenchmarkListWithOneDisabledBenchmark(self):
   expected_printed_stream = (
       'Available benchmarks for TestBrowser are:\n'
       '  FooBenchmark      Benchmark Foo for testing.\n'
       '\n'
       'Disabled benchmarks for TestBrowser are (force run with -d):\n'
       '  BarBenchmarkkkkk  Benchmark Bar for testing long description line.\n'
       'Pass --browser to list benchmarks for another browser.\n\n')
   with mock.patch('telemetry.benchmark_runner.decorators') as mock_module:
     def FakeIsEnabled(benchmark_class, _):
       if benchmark_class is BenchmarkFoo:
         return True, None
       else:
         return False, 'Only supported BenchmarkFoo'
     mock_module.IsEnabled = FakeIsEnabled
     benchmark_runner.PrintBenchmarkList(
       [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream)
     self.assertEquals(expected_printed_stream, self._stream.output_data)