def test_update_developer_names(self):
        with python_utils.open_file(
            update_changelog_and_credits.ABOUT_PAGE_CONSTANTS_FILEPATH, 'r'
        ) as f:
            about_page_lines = f.readlines()
            start_index = about_page_lines.index(
                update_changelog_and_credits.CREDITS_START_LINE) + 1
            end_index = about_page_lines[start_index:].index(
                update_changelog_and_credits.CREDITS_END_LINE) + 1
            existing_developer_names = about_page_lines[start_index:end_index]

        tmp_file = tempfile.NamedTemporaryFile()
        tmp_file.name = MOCK_ABOUT_PAGE_CONSTANTS_FILEPATH
        with python_utils.open_file(
            MOCK_ABOUT_PAGE_CONSTANTS_FILEPATH, 'w'
        ) as f:
            for line in about_page_lines:
                f.write(str(line))

        release_summary_lines = read_from_file(MOCK_RELEASE_SUMMARY_FILEPATH)
        new_developer_names = update_changelog_and_credits.get_new_contributors(
            release_summary_lines, return_only_names=True)

        expected_developer_names = existing_developer_names
        for name in new_developer_names:
            expected_developer_names.append('%s\'%s\',\n' % (
                update_changelog_and_credits.CREDITS_INDENT, name))
        expected_developer_names = sorted(
            list(set(expected_developer_names)), key=lambda s: s.lower())

        with self.swap(
            update_changelog_and_credits, 'ABOUT_PAGE_CONSTANTS_FILEPATH',
            MOCK_ABOUT_PAGE_CONSTANTS_FILEPATH):
            update_changelog_and_credits.update_developer_names(
                release_summary_lines)

        with python_utils.open_file(tmp_file.name, 'r') as f:
            about_page_lines = f.readlines()
            start_index = about_page_lines.index(
                update_changelog_and_credits.CREDITS_START_LINE) + 1
            end_index = about_page_lines[start_index:].index(
                update_changelog_and_credits.CREDITS_END_LINE) + 1
            actual_developer_names = about_page_lines[start_index:end_index]

            self.assertEqual(actual_developer_names, expected_developer_names)

        tmp_file.close()
        if os.path.isfile(MOCK_ABOUT_PAGE_CONSTANTS_FILEPATH):
            # Occasionally this temp file is not deleted.
            os.remove(MOCK_ABOUT_PAGE_CONSTANTS_FILEPATH)
 def test_update_developer_names(self):
     try:
         release_summary_lines = read_from_file(
             MOCK_RELEASE_SUMMARY_FILEPATH)
         about_page_filelines = read_from_file(MOCK_ABOUT_PAGE_FILEPATH)
         expected_filelines = read_from_file(
             MOCK_UPDATED_ABOUT_PAGE_FILEPATH)
         with self.swap(update_changelog_and_credits, 'ABOUT_PAGE_FILEPATH',
                        MOCK_ABOUT_PAGE_FILEPATH):
             update_changelog_and_credits.update_developer_names(
                 release_summary_lines)
         actual_filelines = read_from_file(MOCK_ABOUT_PAGE_FILEPATH)
         self.assertEqual(actual_filelines, expected_filelines)
     finally:
         write_to_file(MOCK_ABOUT_PAGE_FILEPATH, about_page_filelines)