当前位置: 首页>>代码示例>>Python>>正文


Python tests.reverse函数代码示例

本文整理汇总了Python中mysite.missions.base.tests.reverse函数的典型用法代码示例。如果您正苦于以下问题:Python reverse函数的具体用法?Python reverse怎么用?Python reverse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了reverse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_do_mission_correctly_with_old_filenames

    def test_do_mission_correctly_with_old_filenames(self):
        orig_response = self.client.get(
            reverse(views.diffrecursive_get_original_tarball))
        tfile = tarfile.open(
            fileobj=StringIO(orig_response.content), mode='r:gz')
        diff = StringIO()
        for fileinfo in tfile:
            if not fileinfo.isfile():
                continue

            # calcualate the old name
            transformed_name = view_helpers.DiffRecursiveMission.name_new2old(
                fileinfo.name)

            oldlines = tfile.extractfile(fileinfo).readlines()
            newlines = []
            for line in oldlines:
                for old, new in view_helpers.DiffRecursiveMission.SUBSTITUTIONS:
                    line = line.replace(old, new)
                newlines.append(line)

            diff.writelines(difflib.unified_diff(oldlines, newlines,
                                                 'orig-' + transformed_name,
                                                 transformed_name))

        diff.seek(0)
        diff.name = 'foo.patch'
        submit_response = self.client.post(
            reverse(views.diffrecursive_submit), {'diff': diff})
        self.assert_(submit_response.context['diffrecursive_success'])

        paulproteus = Person.objects.get(user__username='paulproteus')
        self.assertEqual(len(StepCompletion.objects.filter(
            step__name='diffpatch_diffrecursive', person=paulproteus)), 1)
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:34,代码来源:tests.py

示例2: test_do_mission_incorrectly_revdiff

    def test_do_mission_incorrectly_revdiff(self):
        orig_response = self.client.get(
            reverse(views.diffrecursive_get_original_tarball))
        tfile = tarfile.open(
            fileobj=StringIO(orig_response.content), mode='r:gz')
        diff = StringIO()
        for fileinfo in tfile:
            if not fileinfo.isfile():
                continue
            oldlines = tfile.extractfile(fileinfo).readlines()
            newlines = []
            for line in oldlines:
                for old, new in view_helpers.DiffRecursiveMission.SUBSTITUTIONS:
                    line = line.replace(old, new)
                newlines.append(line)

            # We're very similar to test_do_mission-correctly, but here we
            # switch newlines and oldlines, to create a reverse patch
            diff.writelines(
                difflib.unified_diff(newlines, oldlines, 'orig-' + fileinfo.name, fileinfo.name))
        diff.seek(0)
        diff.name = 'foo.patch'

        # Submit, and see if we get the same error message we expect.
        error = self.client.post(
            reverse(views.diffrecursive_submit), {'diff': diff})
        self.assert_(
            'You submitted a patch that would revert the correct changes back to the originals.  You may have mixed the parameters for diff, or performed a reverse patch.' in utf8(error))
        paulproteus = Person.objects.get(user__username='paulproteus')
        self.assertEqual(len(StepCompletion.objects.filter(
            step__name='diffpatch_diffrecursive', person=paulproteus)), 0)
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:31,代码来源:tests.py

示例3: test_do_mission_correctly

    def test_do_mission_correctly(self):
        oldfile = tempfile.NamedTemporaryFile(delete=False)
        file_to_patch = oldfile.name

        try:
            orig_response = self.client.get(
                reverse(views.patchsingle_get_original_file))
            oldfile.write(orig_response.content)
            oldfile.close()

            patch_response = self.client.get(
                reverse(views.patchsingle_get_patch))
            patch_process = subprocess.Popen(
                ['patch', file_to_patch], stdin=subprocess.PIPE)
            patch_process.communicate(patch_response.content)
            self.assertEqual(patch_process.returncode, 0)

            submit_response = self.client.post(
                reverse(views.patchsingle_submit), {'patched_file': open(file_to_patch)})
            self.assert_(submit_response.context['patchsingle_success'])

            paulproteus = Person.objects.get(user__username='paulproteus')
            self.assertEqual(len(StepCompletion.objects.filter(
                step__name='diffpatch_patchsingle', person=paulproteus)), 1)

        finally:
            os.unlink(file_to_patch)
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:27,代码来源:tests.py

示例4: test_downloads_of_needed_files

 def test_downloads_of_needed_files(self):
     orig_response = self.client.get(
         reverse(views.patchsingle_get_original_file))
     self.assert_(orig_response['Content-Disposition']
                  .startswith('attachment'))
     patch_response = self.client.get(reverse(views.patchsingle_get_patch))
     self.assert_(patch_response['Content-Disposition']
                  .startswith('attachment'))
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:8,代码来源:tests.py

示例5: test_do_mission_correctly

    def test_do_mission_correctly(self):
        orig_response = self.client.get(reverse(views.diffsingle_get_original_file))
        orig_lines = StringIO(orig_response.content).readlines()
        result_lines = open(view_helpers.DiffSingleFileMission.NEW_FILE).readlines()

        diff = "".join(difflib.unified_diff(orig_lines, result_lines))

        submit_response = self.client.post(reverse(views.diffsingle_submit), {"diff": diff})
        self.assert_(submit_response.context["diffsingle_success"])

        paulproteus = Person.objects.get(user__username="paulproteus")
        self.assertEqual(len(StepCompletion.objects.filter(step__name="diffpatch_diffsingle", person=paulproteus)), 1)
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:12,代码来源:tests.py

示例6: _calculate_correct_recursive_diff

    def _calculate_correct_recursive_diff(self, dos_line_endings=False):
        orig_response = self.client.get(
            reverse(views.diffrecursive_get_original_tarball))
        tfile = tarfile.open(
            fileobj=StringIO(orig_response.content), mode='r:gz')
        diff = StringIO()
        for fileinfo in tfile:
            if not fileinfo.isfile():
                continue
            oldlines = tfile.extractfile(fileinfo).readlines()
            newlines = []
            for line in oldlines:
                for old, new in view_helpers.DiffRecursiveMission.SUBSTITUTIONS:
                    line = line.replace(old, new)
                newlines.append(line)
            lines_for_output = list(
                difflib.unified_diff(oldlines, newlines, 'orig-' + fileinfo.name, fileinfo.name))
            bytes_for_output = ''.join(lines_for_output)
            if dos_line_endings:
                bytes_for_output = bytes_for_output.replace('\n', '\r\n')
            diff.write(bytes_for_output)

        diff.seek(0)
        diff.name = 'foo.patch'
        return diff
开发者ID:JoseDiaz27,项目名称:oh-mainline,代码行数:25,代码来源:tests.py

示例7: test_do_mission_correctly

    def test_do_mission_correctly(self):
        correct_diff = self._calculate_correct_recursive_diff()
        submit_response = self.client.post(reverse(views.diffrecursive_submit), {'diff': correct_diff})
        self.assert_(submit_response.context['diffrecursive_success'])

        paulproteus = Person.objects.get(user__username='paulproteus')
        self.assertEqual(len(StepCompletion.objects.filter(step__name='diffpatch_diffrecursive', person=paulproteus)), 1)
开发者ID:catrope,项目名称:oh-mainline,代码行数:7,代码来源:tests.py

示例8: test_do_mission_incorrectly

    def test_do_mission_incorrectly(self):
        patched_file = StringIO("Some arbitrary contents so the file is incorrect.")
        patched_file.name = "foo.c"
        submit_response = self.client.post(reverse(views.patchsingle_submit), {"patched_file": patched_file})
        self.assertFalse(submit_response.context["patchsingle_success"])

        paulproteus = Person.objects.get(user__username="paulproteus")
        self.assertEqual(len(StepCompletion.objects.filter(step__name="diffpatch_patchsingle", person=paulproteus)), 0)
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:8,代码来源:tests.py

示例9: test_do_mission_incorrectly_BOM

    def test_do_mission_incorrectly_BOM(self):
        diff = StringIO('--- a/foo.txt\n+++ b/foo.txt\[email protected]@ -0,0 +0,1 @@\n+\xef\xbb\xbfHello World\n')
        diff.name = 'foo.patch'
        submit_response = self.client.post(reverse(views.diffrecursive_submit), {'diff': diff})
        self.assertFalse(submit_response.context['diffrecursive_success'])

        paulproteus = Person.objects.get(user__username='paulproteus')
        self.assertEqual(len(StepCompletion.objects.filter(step__name='diffpatch_diffrecursive', person=paulproteus)), 0)
开发者ID:catrope,项目名称:oh-mainline,代码行数:8,代码来源:tests.py

示例10: test_do_mission_incorrectly

    def test_do_mission_incorrectly(self):
        answers = {}
        for key, value in controllers.PatchRecursiveMission.ANSWERS.iteritems():
            answers[key] = value + 1
        response = self.client.post(reverse(views.patchrecursive_submit), answers)
        self.assertFalse(response.context['patchrecursive_success'])

        paulproteus = Person.objects.get(user__username='paulproteus')
        self.assertEqual(len(StepCompletion.objects.filter(step__name='diffpatch_patchrecursive', person=paulproteus)), 0)
开发者ID:catrope,项目名称:oh-mainline,代码行数:9,代码来源:tests.py

示例11: test_do_mission_backwards_diff

    def test_do_mission_backwards_diff(self):
        """
        Submitting a backwards diff generates a special failure message.
        """
        submit_response = self.client.post(reverse(views.diffsingle_submit), {"diff": self.make_swapped_patch()})
        self.assert_("order of files passed to diff was flipped" in submit_response.content)
        self.assertFalse(submit_response.context["diffsingle_success"])

        paulproteus = Person.objects.get(user__username="paulproteus")
        self.assertEqual(len(StepCompletion.objects.filter(step__name="diffpatch_diffsingle", person=paulproteus)), 0)
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:10,代码来源:tests.py

示例12: test_do_mission_incorrectly

    def test_do_mission_incorrectly(self):
        """
        Submitting a generically incorrect diff generates a generic failure message.
        """
        submit_response = self.client.post(reverse(views.diffsingle_submit), {"diff": self.make_wrong_dest_patch()})
        self.assert_("does not have the correct contents" in submit_response.content)
        self.assertFalse(submit_response.context["diffsingle_success"])

        paulproteus = Person.objects.get(user__username="paulproteus")
        self.assertEqual(len(StepCompletion.objects.filter(step__name="diffpatch_diffsingle", person=paulproteus)), 0)
开发者ID:pselle,项目名称:oh-mainline,代码行数:10,代码来源:tests.py

示例13: test_do_mission_correctly_with_dos_line_endings

    def test_do_mission_correctly_with_dos_line_endings(self):
        correct_diff = self._calculate_correct_recursive_diff(dos_line_endings=True)
        self.assertTrue("\r\n" in correct_diff.getvalue())
        submit_response = self.client.post(reverse(views.diffrecursive_submit), {"diff": correct_diff})
        self.assert_(submit_response.context["diffrecursive_success"])

        paulproteus = Person.objects.get(user__username="paulproteus")
        self.assertEqual(
            len(StepCompletion.objects.filter(step__name="diffpatch_diffrecursive", person=paulproteus)), 1
        )
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:10,代码来源:tests.py

示例14: test_do_mission_incorrectly_with_leading_dot_slash

    def test_do_mission_incorrectly_with_leading_dot_slash(self):
        file_path = get_mission_test_data_path('diffpatch')
        for i in range(1,4):
            filename = os.path.join(file_path, "leading_dot_slash_diff_" + str(i) + ".txt")
            with open(filename) as f:
                leading_dot_slash_diff = f.read()
            submit_response = self.client.post(reverse(views.diffrecursive_submit), {'diff': leading_dot_slash_diff})
            self.assertFalse(submit_response.context['diffrecursive_success'])

            paulproteus = Person.objects.get(user__username='paulproteus')
            self.assertEqual(len(StepCompletion.objects.filter(step__name='diffpatch_diffrecursive', person=paulproteus)), 0)
开发者ID:CourtneyThurston,项目名称:oh-mainline,代码行数:11,代码来源:tests.py

示例15: _calculate_correct_recursive_diff

    def _calculate_correct_recursive_diff(self):
        orig_response = self.client.get(reverse(views.diffrecursive_get_original_tarball))
        tfile = tarfile.open(fileobj=StringIO(orig_response.content), mode='r:gz')
        diff = StringIO()
        for fileinfo in tfile:
            if not fileinfo.isfile():
                continue
            oldlines = tfile.extractfile(fileinfo).readlines()
            newlines = []
            for line in oldlines:
                for old, new in controllers.DiffRecursiveMission.SUBSTITUTIONS:
                    line = line.replace(old, new)
                newlines.append(line)
            diff.writelines(difflib.unified_diff(oldlines, newlines, 'orig-'+fileinfo.name, fileinfo.name))

        diff.seek(0)
        diff.name = 'foo.patch'
        return diff
开发者ID:berryp,项目名称:oh-mainline,代码行数:18,代码来源:tests.py


注:本文中的mysite.missions.base.tests.reverse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。