def test_lint_test_files__errors(self):
        options = optparse.Values({
            'platform': 'test',
            'debug_rwt_logging': False
        })
        host = MockHost()

        # FIXME: incorrect complaints about spacing pylint: disable=C0322
        port = host.port_factory.get(options.platform, options=options)
        port.expectations_dict = lambda: {
            'foo': '-- syntax error1',
            'bar': '-- syntax error2'
        }

        host.port_factory.get = lambda platform, options=None: port
        host.port_factory.all_port_names = lambda platform=None: [port.name()]

        logging_stream = StringIO()

        res = lint_test_expectations.lint(host, options, logging_stream)

        self.assertEqual(res, -1)
        self.assertIn('Lint failed', logging_stream.getvalue())
        self.assertIn('foo:1', logging_stream.getvalue())
        self.assertIn('bar:1', logging_stream.getvalue())
    def test_success(self):
        orig_lint_fn = lint_test_expectations.lint

        # unused args pylint: disable=W0613
        def interrupting_lint(host, options, logging_stream):
            raise KeyboardInterrupt

        def successful_lint(host, options, logging_stream):
            return 0

        def exception_raising_lint(host, options, logging_stream):
            assert False

        stdout = StringIO()
        stderr = StringIO()
        try:
            lint_test_expectations.lint = interrupting_lint
            res = lint_test_expectations.main([], stdout, stderr)
            self.assertEqual(res,
                             lint_test_expectations.INTERRUPTED_EXIT_STATUS)

            lint_test_expectations.lint = successful_lint
            res = lint_test_expectations.main(['--platform', 'test'], stdout,
                                              stderr)
            self.assertEqual(res, 0)

            lint_test_expectations.lint = exception_raising_lint
            res = lint_test_expectations.main([], stdout, stderr)
            self.assertEqual(res,
                             lint_test_expectations.EXCEPTIONAL_EXIT_STATUS)
        finally:
            lint_test_expectations.lint = orig_lint_fn
示例#3
0
class _CaptureAndPassThroughStream(object):
    def __init__(self, stream):
        self._buffer = StringIO()
        self._stream = stream

    def write(self, msg):
        self._stream.write(msg)

        # Note that we don't want to capture any output generated by the debugger
        # because that could cause the results of capture_output() to be invalid.
        if not self._message_is_from_pdb():
            self._buffer.write(msg)

    def _message_is_from_pdb(self):
        # We will assume that if the pdb module is in the stack then the output
        # is being generated by the python debugger (or the user calling something
        # from inside the debugger).
        import inspect
        import pdb
        stack = inspect.stack()
        return any(frame[1] == pdb.__file__.replace('.pyc', '.py')
                   for frame in stack)

    def flush(self):
        self._stream.flush()

    def getvalue(self):
        return self._buffer.getvalue()
示例#4
0
    def test_simple_tee(self):
        file1, file2 = StringIO(), StringIO()
        tee = Tee(file1, file2)
        tee.write("foo bar\n")
        tee.write("baz\n")

        self.assertEqual(file1.getvalue(), "foo bar\nbaz\n")
        self.assertEqual(file2.getvalue(), file1.getvalue())
示例#5
0
 def _upload_attachment_to_server(self, attachment_id, attachment_metadata, attachment_data):
     upload_attachment_url = '{}/upload-attachment'.format(self._server_url())
     self._browser.open(upload_attachment_url)
     self._browser.select_form(name='upload_attachment')
     self._browser['attachment_id'] = unicode(attachment_id)
     self._browser.add_file(StringIO.StringIO(unicode(attachment_metadata)), 'application/json', 'attachment-{}-metadata.json'.format(attachment_id), 'attachment_metadata')
     if isinstance(attachment_data, unicode):
         attachment_data = attachment_data.encode('utf-8')
     self._browser.add_file(StringIO.StringIO(attachment_data), 'text/plain', 'attachment-{}.patch'.format(attachment_id), 'attachment_data')
     self._browser.submit()
示例#6
0
class SkipTest(unittest.TestCase):
    def setUp(self):
        self.logger = logging.getLogger(__name__)

        self.old_level = self.logger.level
        self.logger.setLevel(logging.INFO)

        self.old_propagate = self.logger.propagate
        self.logger.propagate = False

        self.log_stream = StringIO()
        self.handler = logging.StreamHandler(self.log_stream)
        self.logger.addHandler(self.handler)

        self.foo_was_called = False

    def tearDown(self):
        self.logger.removeHandler(self.handler)
        self.propagate = self.old_propagate
        self.logger.setLevel(self.old_level)

    def create_fixture_class(self):
        class TestSkipFixture(object):
            def __init__(self, callback):
                self.callback = callback

            def test_foo(self):
                self.callback()

        return TestSkipFixture

    def foo_callback(self):
        self.foo_was_called = True

    def test_skip_if_false(self):
        klass = skip_if(self.create_fixture_class(),
                        False,
                        'Should not see this message.',
                        logger=self.logger)
        klass(self.foo_callback).test_foo()
        self.assertEqual(self.log_stream.getvalue(), '')
        self.assertTrue(self.foo_was_called)

    def test_skip_if_true(self):
        klass = skip_if(self.create_fixture_class(),
                        True,
                        'Should see this message.',
                        logger=self.logger)
        klass(self.foo_callback).test_foo()
        self.assertEqual(
            self.log_stream.getvalue(),
            'Skipping webkitpy.test.skip_unittest.TestSkipFixture: Should see this message.\n'
        )
        self.assertFalse(self.foo_was_called)
示例#7
0
 def set_short_description_and_bug_url(self, short_description, bug_url):
     result = StringIO()
     with self._filesystem.open_text_file_for_reading(self.path) as file:
         short_description_placeholder = "Need a short description (OOPS!)."
         bug_url_placeholder = "Need the bug URL (OOPS!)."
         for line in file:
             stripped = line.strip()
             if stripped == short_description_placeholder:
                 line = self._changelog_indent + short_description + "\n"
             if stripped == bug_url_placeholder:
                 line = self._changelog_indent + bug_url + "\n"
             result.write(line)
     self._filesystem.write_text_file(self.path, result.getvalue())
    def test_lint_test_files(self):
        logging_stream = StringIO()
        options = optparse.Values({'platform': 'test-mac-leopard'})
        host = MockHost()

        # pylint appears to complain incorrectly about the method overrides pylint: disable=E0202,C0322
        # FIXME: incorrect complaints about spacing pylint: disable=C0322
        host.port_factory.all_port_names = lambda platform=None: [platform]

        res = lint_test_expectations.lint(host, options, logging_stream)

        self.assertEqual(res, 0)
        self.assertIn('Lint succeeded', logging_stream.getvalue())
示例#9
0
    def setUp(self):
        self.logger = logging.getLogger(__name__)

        self.old_level = self.logger.level
        self.logger.setLevel(logging.INFO)

        self.old_propagate = self.logger.propagate
        self.logger.propagate = False

        self.log_stream = StringIO()
        self.handler = logging.StreamHandler(self.log_stream)
        self.logger.addHandler(self.handler)

        self.foo_was_called = False
示例#10
0
 def delete_entries(self, num_entries):
     date_line_regexp = re.compile(ChangeLogEntry.date_line_regexp)
     rolled_over_regexp = re.compile(ChangeLogEntry.rolled_over_regexp)
     entries = 0
     result = StringIO()
     with self._filesystem.open_text_file_for_reading(self.path) as file:
         for line in file:
             if date_line_regexp.match(line):
                 entries += 1
             elif rolled_over_regexp.match(line):
                 entries = num_entries + 1
             if entries > num_entries:
                 result.write(line)
     self._filesystem.write_text_file(self.path, result.getvalue())
    def test_read_checksum(self):
        # Test a file with the comment.
        filehandle = StringIO(
            '''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x03 \x00\x00\x02X\x08\x02\x00\x00\x00\x15\x14\x15'\x00\x00\x00)tEXtchecksum\x003c4134fe2739880353f91c5b84cadbaaC\xb8?\xec\x00\x00\x16\xfeIDATx\x9c\xed\xdd[\x8cU\xe5\xc1\xff\xf15T\x18\x0ea,)\xa6\x80XZ<\x10\n\xd6H\xc4V\x88}\xb5\xa9\xd6r\xd5\x0bki0\xa6\xb5ih\xd2\xde\x98PHz\xd1\x02=\\q#\x01\x8b\xa5rJ\x8b\x88i\xacM\xc5h\x8cbMk(\x1ez@!\x0c\xd5\xd2\xc2\xb44\x1c\x848\x1dF(\xeb\x7f\xb1\xff\xd9\xef~g\xd6\xde3\xe0o\x10\xec\xe7sa6{\xd6z\xd6\xb3\xd7\xf3\xa8_7\xdbM[Y\x96\x05\x00\x009\xc3\xde\xeb\t\x00\x00\xbc\xdf\x08,\x00\x800\x81\x05\x00\x10&\xb0\x00\x00\xc2\x04\x16\x00@\x98\xc0\x02\x00\x08\x13X\x00\x00a\x02\x0b\x00 L
x01\x00\x84\t,\x00\x800\x81\x05\x00\x10\xd64\xb0\xda\x9a\xdb\xb6m\xdb\xb4i\xd3\xfa\x9fr\xf3\xcd7\x0f\xe5T\x07\xe5\xd4\xa9'''
        )
        checksum = read_checksum_from_png.read_checksum(filehandle)
        self.assertEqual('3c4134fe2739880353f91c5b84cadbaa', checksum)

        # Test a file without the comment.
        filehandle = StringIO(
            '''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x03 \x00\x00\x02X\x08\x02\x00\x00\x00\x15\x14\x15'\x00\x00\x16\xfeIDATx\x9c\xed\xdd[\x8cU\xe5\xc1\xff\xf15T\x18\x0ea,)\xa6\x80XZ<\x10\n\xd6H\xc4V\x88}\xb5\xa9\xd6r\xd5\x0bki0\xa6\xb5ih\xd2\xde\x98PHz\xd1\x02=\\q#\x01\x8b\xa5rJ\x8b\x88i\xacM\xc5h\x8cbMk(\x1ez@!\x0c\xd5\xd2\xc2\xb44\x1c\x848\x1dF(\xeb\x7f\xb1\xff\xd9\xef~g\xd6\xde3\xe0o\x10\xec\xe7sa6{\xd6z\xd6\xb3\xd7\xf3\xa8_7\xdbM[Y\x96\x05\x00\x009\xc3\xde\xeb\t\x00\x00\xbc\xdf\x08,\x00\x800\x81\x05\x00\x10&\xb0\x00\x00\xc2\x04\x16\x00@\x98\xc0\x02\x00\x08\x13X\x00\x00a\x02\x0b\x00 L
x01\x00\x84\t,\x00\x800\x81\x05\x00\x10\xd64\xb0\xda\x9a\xdb\xb6m\xdb\xb4i\xd3\xfa\x9fr\xf3\xcd7\x0f\xe5T\x07\xe5\xd4\xa9S\x8b\x17/\x1e?~\xfc\xf8\xf1\xe3\xef\xbf\xff\xfe\xf7z:M5\xbb\x87\x17\xcbUZ\x8f|V\xd7\xbd\x10\xb6\xcd{b\x88\xf6j\xb3\x9b?\x14\x9b\xa1>\xe6\xf9\xd9\xcf\x00\x17\x93'''
        )
        checksum = read_checksum_from_png.read_checksum(filehandle)
        self.assertIsNone(checksum)
示例#12
0
 def test_latest_entry_parse_single_entry(self):
     changelog_contents = u"%s\n%s" % (self._example_entry,
                                       self._rolled_over_footer)
     changelog_file = StringIO(changelog_contents)
     latest_entry = ChangeLog.parse_latest_entry_from_file(changelog_file)
     self.assertEqual(latest_entry.contents(), self._example_entry)
     self.assertEqual(latest_entry.author_name(), "Peter Kasting")
示例#13
0
 def test_filename_for_upload(self):
     bugzilla = Bugzilla()
     mock_file = Mock()
     mock_file.name = "foo"
     self.assertEqual(bugzilla._filename_for_upload(mock_file, 1234), 'foo')
     mock_timestamp = lambda: "now"
     filename = bugzilla._filename_for_upload(StringIO(), 1234, extension="patch", timestamp=mock_timestamp)
     self.assertEqual(filename, "bug-1234-now.patch")
示例#14
0
 def test_file_object_for_upload(self):
     bugzilla = Bugzilla()
     file_object = StringIO()
     unicode_tor = u"WebKit \u2661 Tor Arne Vestb\u00F8!"
     utf8_tor = unicode_tor.encode("utf-8")
     self.assertEqual(bugzilla._file_object_for_upload(file_object), file_object)
     self.assertEqual(bugzilla._file_object_for_upload(utf8_tor).read(), utf8_tor)
     self.assertEqual(bugzilla._file_object_for_upload(unicode_tor).read(), utf8_tor)
示例#15
0
    def create_bug(self,
                   bug_title,
                   bug_description,
                   component=None,
                   diff=None,
                   patch_description=None,
                   cc=None,
                   blocked=None,
                   assignee=None,
                   mark_for_review=False,
                   mark_for_commit_queue=False):
        self.authenticate()

        _log.info('Creating bug with title "%s"' % bug_title)
        self.open_url(config_urls.bug_server_url +
                      "enter_bug.cgi?product=WebKit")
        self.browser.select_form(name="Create")
        component_items = self.browser.find_control('component').items
        component_names = map(lambda item: item.name, component_items)
        if not component:
            component = "New Bugs"
        if component not in component_names:
            component = User.prompt_with_list("Please pick a component:",
                                              component_names)
        self.browser["component"] = [component]
        if cc:
            self.browser["cc"] = cc
        if blocked:
            self.browser["blocked"] = unicode(blocked)
        if not assignee:
            assignee = self.username
        if assignee and not self.browser.find_control("assigned_to").disabled:
            self.browser["assigned_to"] = assignee
        self.browser["short_desc"] = bug_title
        self.browser["comment"] = bug_description

        if diff:
            # _fill_attachment_form expects a file-like object
            # Patch files are already binary, so no encoding needed.
            assert (isinstance(diff, str))
            patch_file_object = StringIO(diff)
            commit_flag = CommitQueueFlag.mark_for_nothing
            if mark_for_commit_queue:
                commit_flag = CommitQueueFlag.mark_for_commit_queue

            self._fill_attachment_form(patch_description,
                                       patch_file_object,
                                       mark_for_review=mark_for_review,
                                       commit_flag=commit_flag,
                                       is_patch=True)

        response = self.browser.submit()

        bug_id = self._check_create_bug_response(response.read())
        _log.info("Bug %s created." % bug_id)
        _log.info("%sshow_bug.cgi?id=%s" %
                  (config_urls.bug_server_url, bug_id))
        return bug_id
示例#16
0
    def __init__(self, in1, in2):
        if isinstance(in1, str):
            waveFile1 = wave.open(StringIO(in1), 'r')
        else:
            waveFile1 = wave.open(BytesIO(in1), 'rb')
        if isinstance(in2, str):
            waveFile2 = wave.open(StringIO(in2), 'r')
        else:
            waveFile2 = wave.open(BytesIO(in2), 'rb')

        params1 = waveFile1.getparams()
        params2 = waveFile2.getparams()

        self._diff = ''

        self._filesAreIdentical = not sum(map(self._diffParam, params1, params2, self._paramNames))
        self._filesAreIdenticalWithinTolerance = self._filesAreIdentical

        if not self._filesAreIdentical:
            return

        # Metadata is identical, compare the content now.

        channelCount1 = waveFile1.getnchannels()
        frameCount1 = waveFile1.getnframes()
        sampleWidth1 = waveFile1.getsampwidth()
        channelCount2 = waveFile2.getnchannels()
        frameCount2 = waveFile2.getnframes()
        sampleWidth2 = waveFile2.getsampwidth()

        allData1 = self._readSamples(waveFile1, sampleWidth1, frameCount1 * channelCount1)
        allData2 = self._readSamples(waveFile2, sampleWidth2, frameCount2 * channelCount2)
        results = list(map(self._diffSample, allData1, allData2, range(max(frameCount1 * channelCount1, frameCount2 * channelCount2))))

        cumulativeSampleDiff = sum(results)
        differingSampleCount = len(list(filter(bool, results)))
        self._filesAreIdentical = not differingSampleCount
        self._filesAreIdenticalWithinTolerance = not len(list(filter(lambda x: x > self._tolerance, results)))

        if differingSampleCount:
            self._diff += '\n'
            self._diff += 'Total differing samples: %d\n' % differingSampleCount
            self._diff += 'Percentage of differing samples: %0.3f%%\n' % (100 * float(differingSampleCount) / max(frameCount1, frameCount2))
            self._diff += 'Cumulative sample difference: %d\n' % cumulativeSampleDiff
            self._diff += 'Average sample difference: %f\n' % (float(cumulativeSampleDiff) / differingSampleCount)
示例#17
0
 def set_reviewer(self, reviewer):
     latest_entry = self.latest_entry()
     latest_entry_contents = latest_entry.contents()
     reviewer_text = latest_entry.reviewer()
     found_nobody = re.search("NOBODY\s*\(OOPS!\)", latest_entry_contents,
                              re.MULTILINE)
     found_reviewer_or_unreviewed = latest_entry.has_valid_reviewer()
     if not found_nobody and not found_reviewer_or_unreviewed and not reviewer_text:
         bug_url_number_of_items = len(
             re.findall(config_urls.bug_url_long, latest_entry_contents,
                        re.MULTILINE))
         bug_url_number_of_items += len(
             re.findall(config_urls.bug_url_short, latest_entry_contents,
                        re.MULTILINE))
         result = StringIO()
         with self._filesystem.open_text_file_for_reading(
                 self.path) as file:
             for line in file:
                 found_bug_url = re.search(config_urls.bug_url_long, line)
                 if not found_bug_url:
                     found_bug_url = re.search(config_urls.bug_url_short,
                                               line)
                 result.write(line)
                 if found_bug_url:
                     if bug_url_number_of_items == 1:
                         result.write("\n        Reviewed by %s.\n" %
                                      reviewer)
                     bug_url_number_of_items -= 1
         self._filesystem.write_text_file(self.path, result.getvalue())
     else:
         data = self._filesystem.read_text_file(self.path)
         newdata = data.replace("NOBODY (OOPS!)", reviewer)
         self._filesystem.write_text_file(self.path, newdata)
    def setUp(self):
        self.stream = StringIO()
        self.stream.isatty = lambda: self.isatty

        # configure a logger to test that log calls do normally get included.
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        self.logger.propagate = False

        # add a dummy time counter for a default behavior.
        self.times = list(range(10))

        self.meter = MeteredStream(self.stream,
                                   self.verbose,
                                   self.logger,
                                   self.time_fn,
                                   8675,
                                   print_timestamps=self.print_timestamps)
示例#19
0
 def _latest_entry_for_changelog_at_revision(self, changelog_path,
                                             revision):
     changelog_contents = self._scm.contents_at_revision(
         changelog_path, revision)
     # contents_at_revision returns a byte array (str()), but we know
     # that ChangeLog files are utf-8.  parse_latest_entry_from_file
     # expects a file-like object which vends unicode(), so we decode here.
     # Old revisions of Sources/WebKit/wx/ChangeLog have some invalid utf8 characters.
     changelog_file = StringIO(changelog_contents.decode("utf-8", "ignore"))
     return ChangeLog.parse_latest_entry_from_file(changelog_file)
示例#20
0
    def get_printer(self, args=None):
        args = args or []
        printing_options = printing.print_options()
        option_parser = optparse.OptionParser(option_list=printing_options)
        options, args = option_parser.parse_args(args)
        host = MockHost()
        self._port = host.port_factory.get('test', options)
        nproc = 2

        regular_output = StringIO()
        printer = printing.Printer(self._port, options, regular_output)
        return printer, regular_output
示例#21
0
 def strip_change_log(cls, diff):
     output = []
     skipping = False
     for line in StringIO(diff).readlines():
         indexline = re.match("^Index: ([^\\n]*/)?([^/\\n]*)$", line)
         if skipping and indexline:
             skipping = False
         if indexline and indexline.group(2) == "ChangeLog":
             skipping = True
         if not skipping:
             output.append(line)
     return "".join(output)
示例#22
0
    def test_no_tests_found(self):
        tester = Tester()
        errors = StringIO()

        # Here we need to remove any existing log handlers so that they
        # don't log the messages webkitpy.test while we're testing it.
        root_logger = logging.getLogger()
        root_handlers = root_logger.handlers
        root_logger.handlers = []

        tester.printer.stream = errors
        tester.finder.find_names = lambda args, run_all: []
        oc = OutputCapture()
        try:
            oc.capture_output()
            self.assertFalse(tester.run())
        finally:
            _, _, logs = oc.restore_output()
            root_logger.handlers = root_handlers

        self.assertIn('No tests to run', errors.getvalue())
        self.assertIn('No tests to run', logs)
    def test_all_configurations(self):
        host = MockHost()
        host.ports_parsed = []
        host.port_factory = FakeFactory(
            host,
            (FakePort(host, 'a', 'path-to-a'), FakePort(
                host, 'b', 'path-to-b'), FakePort(host, 'b-win', 'path-to-b')))

        logging_stream = StringIO()
        options = optparse.Values({'platform': None})
        res = lint_test_expectations.lint(host, options, logging_stream)
        self.assertEqual(res, 0)
        self.assertEqual(host.ports_parsed, ['a', 'b', 'b-win'])
示例#24
0
    def test_parse_log_entries_from_annotated_file(self):
        # Note that there are trailing spaces on some of the lines intentionally.
        changelog_file = StringIO(
            u"100000 [email protected] 2011-11-11  Csaba Osztrogon\u00e1c  <*****@*****.**>\n"
            u"100000 [email protected]\n"
            u"100000 [email protected]         100,000 !!!\n"
            u"100000 [email protected] \n"
            u"100000 [email protected]         Reviewed by Zoltan Herczeg.\n"
            u"100000 [email protected] \n"
            u"100000 [email protected]         * ChangeLog: Point out revision 100,000.\n"
            u"100000 [email protected] \n"
            u"93798 [email protected] 2011-08-25  Alexey Proskuryakov  <*****@*****.**>\n"
            u"93798 [email protected] \n"
            u"93798 [email protected]         Fix build when GCC 4.2 is not installed.\n"
            u"93798 [email protected] \n"
            u"93798 [email protected]         * gtest/xcode/Config/CompilerVersion.xcconfig: Copied from Source/WebCore/Configurations/CompilerVersion.xcconfig.\n"
            u"93798 [email protected]         * gtest/xcode/Config/General.xcconfig:\n"
            u"93798 [email protected]         Use the same compiler version as other projects do.\n"
            u"93798 [email protected]\n"
            u"99491 [email protected] 2011-11-03  Andreas Kling  <*****@*****.**>\n"
            u"99491 [email protected] \n"
            u"99190 [email protected]         Unreviewed build fix, sigh.\n"
            u"99190 [email protected] \n"
            u"99190 [email protected]         * css/CSSFontFaceRule.h:\n"
            u"99190 [email protected]         * css/CSSMutableStyleDeclaration.h:\n"
            u"99190 [email protected]\n"
            u"99190 [email protected] 2011-11-03  Andreas Kling  <*****@*****.**>\n"
            u"99190 [email protected] \n"
            u"99187 [email protected]         Unreviewed build fix, out-of-line StyleSheet::parentStyleSheet()\n"
            u"99187 [email protected]         again since there's a cycle in the includes between CSSRule/StyleSheet.\n"
            u"99187 [email protected] \n"
            u"99187 [email protected]         * css/StyleSheet.cpp:\n"
            u"99187 [email protected]         (WebCore::StyleSheet::parentStyleSheet):\n"
            u"99187 [email protected]         * css/StyleSheet.h:\n"
            u"99187 [email protected] \n")

        parsed_entries = list(
            ChangeLog.parse_entries_from_file(changelog_file))
        self.assertEqual(parsed_entries[0].revision(), 100000)
        self.assertEqual(parsed_entries[0].reviewer_text(), "Zoltan Herczeg")
        self.assertEqual(parsed_entries[0].author_name(),
                         u"Csaba Osztrogon\u00e1c")
        self.assertEqual(parsed_entries[0].author_email(), "*****@*****.**")
        self.assertEqual(parsed_entries[1].revision(), 93798)
        self.assertEqual(parsed_entries[1].author_name(),
                         "Alexey Proskuryakov")
        self.assertEqual(parsed_entries[2].revision(), 99190)
        self.assertEqual(parsed_entries[2].author_name(), "Andreas Kling")
        self.assertEqual(parsed_entries[3].revision(), 99187)
        self.assertEqual(parsed_entries[3].author_name(), "Andreas Kling")
 def test_logging_not_included(self):
     # This tests that if we don't hand a logger to the MeteredStream,
     # nothing is logged.
     logging_stream = StringIO()
     handler = logging.StreamHandler(logging_stream)
     root_logger = logging.getLogger()
     orig_level = root_logger.level
     root_logger.addHandler(handler)
     root_logger.setLevel(logging.DEBUG)
     try:
         self.meter = MeteredStream(self.stream,
                                    self.verbose,
                                    None,
                                    self.time_fn,
                                    8675,
                                    print_timestamps=self.print_timestamps)
         self.meter.write_throttled_update('foo')
         self.meter.write_update('bar')
         self.meter.write('baz')
         self.assertEqual(logging_stream.getvalue(), '')
     finally:
         root_logger.removeHandler(handler)
         root_logger.setLevel(orig_level)
示例#26
0
 def test_run(self,
              verbose=0,
              timing=False,
              child_processes=1,
              quiet=False):
     options = MockOptions(verbose=verbose,
                           timing=timing,
                           child_processes=child_processes,
                           quiet=quiet,
                           pass_through=False)
     stream = StringIO()
     loader = FakeLoader(('test1 (Foo)', '.', ''),
                         ('test2 (Foo)', 'F', 'test2\nfailed'),
                         ('test3 (Foo)', 'E', 'test3\nerred'))
     runner = Runner(Printer(stream, options), loader)
     runner.run(['Foo.test1', 'Foo.test2', 'Foo.test3'], 1)
     self.assertEqual(len(runner.tests_run), 3)
     self.assertEqual(len(runner.failures), 1)
     self.assertEqual(len(runner.errors), 1)
示例#27
0
    def test_git_diff_to_svn_diff(self):
        output = """\
Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py
===================================================================
--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py
+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py
@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
 A
 B
 C
+D
 E
 F
"""

        inputfmt = StringIO("""\
diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
index 2ed552c4555db72df16b212547f2c125ae301a04..72870482000c0dba64ce4300ed782c03ee79b74f 100644
--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
 A
 B
 C
+D
 E
 F
""")
        shortfmt = StringIO("""\
diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
index b48b162..f300960 100644
--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
 A
 B
 C
+D
 E
 F
""")

        self.assertMultiLineEqual(
            output, ''.join(
                diff_parser.git_diff_to_svn_diff(x)
                for x in shortfmt.readlines()))
        self.assertMultiLineEqual(
            output, ''.join(
                diff_parser.git_diff_to_svn_diff(x)
                for x in inputfmt.readlines()))
示例#28
0
    def test_latest_entry_parse(self):
        changelog_contents = u"%s\n%s" % (self._example_entry,
                                          self._example_changelog)
        changelog_file = StringIO(changelog_contents)
        latest_entry = ChangeLog.parse_latest_entry_from_file(changelog_file)
        self.assertEqual(latest_entry.contents(), self._example_entry)
        self.assertEqual(latest_entry.author_name(), "Peter Kasting")
        self.assertEqual(latest_entry.author_email(), "*****@*****.**")
        self.assertEqual(latest_entry.reviewer_text(),
                         u"Fr\u00e9d\u00e9ric Wang")
        touched_files = [
            "DumpRenderTree/win/DumpRenderTree.vcproj",
            "DumpRenderTree/win/ImageDiff.vcproj",
            "DumpRenderTree/win/TestNetscapePlugin/TestNetscapePlugin.vcproj"
        ]
        self.assertEqual(latest_entry.touched_files(), touched_files)
        self.assertEqual(latest_entry.touched_functions(),
                         dict((f, []) for f in touched_files))

        self.assertTrue(latest_entry.reviewer()
                        )  # Make sure that our UTF8-based lookup of Tor works.
示例#29
0
    def update_with_unreviewed_message(self, message):
        first_boilerplate_line_regexp = re.compile(
            "%sNeed a short description \(OOPS!\)\." % self._changelog_indent)
        removing_boilerplate = False
        result = StringIO()
        with self._filesystem.open_text_file_for_reading(self.path) as file:
            for line in file:
                if first_boilerplate_line_regexp.search(line):
                    message_lines = self._wrap_lines(message)
                    result.write(
                        first_boilerplate_line_regexp.sub(message_lines, line))
                    # Remove all the ChangeLog boilerplate, except the first line (date, name, e-mail).
                    removing_boilerplate = True
                elif removing_boilerplate:
                    if re.search(
                            "^[1-9]", line
                    ):  # each changelog entry is preceded by a date
                        removing_boilerplate = False

                if not removing_boilerplate:
                    result.write(line)
        self._filesystem.write_text_file(self.path, result.getvalue())
示例#30
0
 def test_parse_log_entries_from_changelog(self):
     changelog_file = StringIO(self._example_changelog)
     parsed_entries = list(
         ChangeLog.parse_entries_from_file(changelog_file))
     self.assertEqual(len(parsed_entries), 9)
     self.assertEqual(
         parsed_entries[0].date_line(),
         u"2009-08-17  Fr\u00e9d\u00e9ric Wang  <*****@*****.**>")
     self.assertEqual(parsed_entries[0].date(), "2009-08-17")
     self.assertEqual(parsed_entries[0].reviewer_text(), "David Levin")
     self.assertEqual(parsed_entries[0].is_touched_files_text_clean(),
                      False)
     self.assertIsNone(parsed_entries[0].bug_description())
     self.assertEqual(parsed_entries[1].date_line(),
                      "2009-08-16  David Kilzer  <*****@*****.**>")
     self.assertEqual(parsed_entries[1].date(), "2009-08-16")
     self.assertEqual(parsed_entries[1].author_email(),
                      "*****@*****.**")
     self.assertEqual(parsed_entries[1].bug_description(),
                      "Backed out r47343 which was mistakenly committed")
     self.assertEqual(
         parsed_entries[1].touched_files_text(),
         "        * Scripts/bugzilla-tool:\n        * Scripts/modules/scm.py:\n"
     )
     self.assertEqual(parsed_entries[1].is_touched_files_text_clean(), True)
     self.assertEqual(parsed_entries[2].reviewer_text(), "Mark Rowe")
     self.assertEqual(parsed_entries[2].touched_files(),
                      ["DumpRenderTree/mac/DumpRenderTreeWindow.mm"])
     self.assertEqual(
         parsed_entries[2].touched_functions(), {
             "DumpRenderTree/mac/DumpRenderTreeWindow.mm":
             ["-[DumpRenderTreeWindow close]"]
         })
     self.assertEqual(parsed_entries[2].is_touched_files_text_clean(),
                      False)
     self.assertIsNone(parsed_entries[2].bug_description())
     self.assertEqual(parsed_entries[3].author_name(), "Benjamin Poulain")
     self.assertEqual(parsed_entries[3].touched_files(), [
         "platform/cf/KURLCFNet.cpp", "platform/mac/KURLMac.mm",
         "WebCoreSupport/ChromeClientEfl.cpp", "ewk/ewk_private.h",
         "ewk/ewk_view.cpp"
     ])
     self.assertEqual(
         parsed_entries[3].touched_functions(), {
             "platform/cf/KURLCFNet.cpp": [
                 "WebCore::createCFURLFromBuffer",
                 "WebCore::KURL::createCFURL"
             ],
             "platform/mac/KURLMac.mm": [
                 "WebCore::KURL::operator NSURL *",
                 "WebCore::KURL::createCFURL"
             ],
             "WebCoreSupport/ChromeClientEfl.cpp":
             ["WebCore::ChromeClientEfl::closeWindowSoon"],
             "ewk/ewk_private.h": [],
             "ewk/ewk_view.cpp": []
         })
     self.assertEqual(
         parsed_entries[3].bug_description(),
         "[Mac] ResourceRequest's nsURLRequest() does not differentiate null and empty URLs with CFNetwork"
     )
     self.assertEqual(parsed_entries[4].reviewer_text(), "David Hyatt")
     self.assertIsNone(parsed_entries[4].bug_description())
     self.assertEqual(parsed_entries[5].reviewer_text(), "Adam Roben")
     self.assertIsNone(parsed_entries[5].bug_description())
     self.assertEqual(parsed_entries[6].reviewer_text(), "Tony Chang")
     self.assertIsNone(parsed_entries[6].bug_description())
     self.assertIsNone(parsed_entries[7].reviewer_text())
     self.assertEqual(parsed_entries[7].bug_description(),
                      "Unreviewed warning fix.")
     self.assertEqual(parsed_entries[8].reviewer_text(), 'Darin Adler')
     self.assertEqual(
         parsed_entries[8].bug_description(),
         'Resolve regular and visited link style in a single pass')