示例#1
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'
            '# results: [ Skip ]\n'
            'crbug.com/123 [ All ] BenchmarkBar* [ Skip ]\n')

        expectations_file = tempfile.NamedTemporaryFile(bufsize=0,
                                                        delete=False)
        with mock.patch.object(self._mock_possible_browser,
                               'GetTypExpectationsTags',
                               return_value=['All']):
            try:
                expectations_file.write(expectations_file_contents)
                expectations_file.close()
                commands.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)
示例#2
0
 def testPrintBenchmarkListWithNoDisabledBenchmark(self):
     expected_printed_stream = (
         'Available benchmarks for TestBrowser are:\n'
         '  BenchmarkFoo Benchmark foo for testing.\n'
         'Pass --browser to list benchmarks for another browser.\n\n')
     commands.PrintBenchmarkList([BenchmarkFoo],
                                 self._mock_possible_browser, self._stream)
     self.assertEquals(expected_printed_stream, self._stream.getvalue())
示例#3
0
    def testPrintBenchmarkListWithOneDisabledBenchmark(self):
        expected_printed_stream = (
            'Available benchmarks for TestBrowser are:\n'
            '  BenchmarkFoo      Benchmark foo for testing.\n'
            '\n'
            'Not supported benchmarks for TestBrowser are (force run with -d):\n'
            '  BenchmarkDisabled Benchmark disabled for testing.\n'
            'Pass --browser to list benchmarks for another browser.\n\n')

        with mock.patch.object(self._mock_possible_browser,
                               'GetTypExpectationsTags',
                               return_value=['All']):
            commands.PrintBenchmarkList([BenchmarkFoo, BenchmarkDisabled],
                                        self._mock_possible_browser,
                                        self._stream)
            self.assertEquals(expected_printed_stream, self._stream.getvalue())
示例#4
0
    def testPrintBenchmarkListInJSON(self):
        expected_json_stream = json.dumps(
            [{
                'name': BenchmarkFoo.Name(),
                'description': BenchmarkFoo.Description(),
                'enabled': True,
                'supported': True,
                'stories': [{
                    'name': 'dummy_page',
                    'tags': ['foo', 'bar']
                }]
            }],
            indent=4,
            sort_keys=True,
            separators=(',', ': '))

        commands.PrintBenchmarkList([BenchmarkFoo],
                                    self._mock_possible_browser,
                                    json_pipe=self._json_stream)
        self.assertEquals(expected_json_stream, self._json_stream.getvalue())
    def testPrintBenchmarkListInJSON(self):
        expected_json_stream = json.dumps(sorted(
            [{
                'name': BenchmarkFoo.Name(),
                'description': BenchmarkFoo.Description(),
                'enabled': True,
                'stories': [{
                    'name': 'dummy_page',
                    'tags': ['foo', 'bar']
                }]
            }, {
                'name': BenchmarkBar.Name(),
                'description': BenchmarkBar.Description(),
                'enabled': False,
                'stories': []
            }],
            key=lambda b: b['name']),
                                          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()
            commands.PrintBenchmarkList([BenchmarkFoo, BenchmarkBar],
                                        self._mock_possible_browser,
                                        expectations_file.name, self._stream,
                                        self._json_stream)

            self.assertEquals(expected_json_stream,
                              self._json_stream.getvalue())

        finally:
            os.remove(expectations_file.name)