コード例 #1
0
ファイル: test_evaluate.py プロジェクト: pharazone/ptvsd
 def code_to_debug():
     from dbgimporter import import_and_enable_debugger
     import_and_enable_debugger()
     a = 1
     b = {"one": 1, "two": 2}
     c = 3
     print([a, b, c])
コード例 #2
0
ファイル: test_run.py プロジェクト: HarryWeppner/ptvsd
    def code_to_debug():
        import os
        import sys
        import backchannel

        print('begin')
        assert backchannel.read_json() == 'continue'
        backchannel.write_json(os.path.abspath(sys.modules['ptvsd'].__file__))
        print('end')
コード例 #3
0
ファイル: timeline.py プロジェクト: agrimarcal/ptvsd
 def wait_for_next(self,
                   expectation,
                   freeze=True,
                   explain=True,
                   observe=True):
     if explain:
         print(colors.LIGHT_MAGENTA + 'Waiting for next ' + colors.RESET +
               colors.color_repr(expectation))
     return self._wait_until_realized(expectation, False, freeze, explain,
                                      observe)
コード例 #4
0
ファイル: timeline.py プロジェクト: redreamality/ptvsd
 def wait_for(self, expectation, freeze=None, explain=True):
     assert expectation.has_lower_bound, (
         'Expectation must have a lower time bound to be used with wait_for()! '
         'Use >> to sequence an expectation against an occurrence to establish a lower bound, '
         'or wait_for_next() to wait for the next expectation since the timeline was last '
         'frozen, or wait_until_realized() when a lower bound is really not necessary.'
     )
     if explain:
         print(colors.LIGHT_MAGENTA + 'Waiting for ' + colors.RESET + colors.color_repr(expectation))
     return self._wait_until_realized(expectation, freeze, explain=explain)
コード例 #5
0
ファイル: timeline.py プロジェクト: pharazone/ptvsd
    def wait_until_realized(self,
                            expectation,
                            freeze=None,
                            explain=True,
                            observe=True):
        if explain:
            print(colors.LIGHT_MAGENTA + 'Waiting for ' + colors.RESET +
                  colors.color_repr(expectation))

        reasons = {}
        check_past = [True]

        def has_been_realized(occ):
            # First time wait_until() calls us, we have to check the whole timeline.
            # On subsequent calls, we only need to check the newly added occurrence.
            if check_past:
                # if explain:
                #     print(
                #         colors.LIGHT_MAGENTA + 'Testing ' + colors.RESET +
                #         colors.color_repr(expectation) +
                #         colors.LIGHT_MAGENTA + ' against timeline up to and including ' + colors.RESET +
                #         colors.color_repr(occ)
                #     )
                reasons.update(expectation.test_at_or_before(occ) or {})
                del check_past[:]
            else:
                # if explain:
                #     print(
                #         colors.LIGHT_MAGENTA + 'Testing ' + colors.RESET +
                #         colors.color_repr(expectation) +
                #         colors.LIGHT_MAGENTA + ' against ' + colors.RESET +
                #         colors.color_repr(occ)
                #     )
                reasons.update(expectation.test_at(occ) or {})

            if reasons:
                if observe:
                    self.expect_realized(expectation,
                                         explain=explain,
                                         observe=observe)
                return True
            # else:
            #     if explain:
            #         print(
            #             colors.color_repr(occ) +
            #             colors.LIGHT_MAGENTA + ' did not realize ' + colors.RESET +
            #             colors.color_repr(expectation)
            #         )

        self.wait_until(has_been_realized, freeze)

        realized_at = reasons[expectation]
        return realized_at
コード例 #6
0
 def code_to_debug():
     b_test = {"spam": "A", "eggs": "B", "abcd": "C"}  # noqa
     _b_test = 12  # noqa
     __b_test = 13  # noqa
     __b_test__ = 14  # noqa
     a_test = 1  # noqa
     _a_test = 2  # noqa
     __a_test = 3  # noqa
     __a_test__ = 4  # noqa
     c_test = {1: "one", 2: "two", 10: "ten"}  # noqa
     _c_test = 22  # noqa
     __c_test = 23  # noqa
     __c_test__ = 24  # noqa
     d = 3  # noqa
     print('done')
コード例 #7
0
ファイル: timeline.py プロジェクト: scorphus/ptvsd
    def finalize(self):
        if self.is_final:
            return

        print(colors.LIGHT_MAGENTA + 'Finalizing' + colors.RESET)
        with self.unfrozen():
            self.mark('finalized')

        with self.unfrozen():
            self._finalized.set()
            # Drain the record queue.
            self._record_queue.join()
            # Tell the recorder to shut itself down.
            self._record_queue.put(None)
            self._recorder_thread.join()

        assert self._record_queue.empty(), 'Finalized timeline had pending records'
コード例 #8
0
ファイル: timeline.py プロジェクト: agrimarcal/ptvsd
    def expect_no_unobserved(self):
        if not self:
            return

        # print('Checking for unobserved since %s' % colors.color_repr(self[0]))
        unobserved = [
            occ for occ in self if not occ.observed and all(
                exp != occ for exp in self.timeline.ignore_unobserved)
        ]
        if not unobserved:
            return

        print(colors.LIGHT_RED + 'Unobserved occurrences detected:' +
              colors.RESET)
        for occ in unobserved:
            print('   ' + colors.color_repr(occ))
        raise Exception('Unobserved occurrences detected')
コード例 #9
0
ファイル: test_evaluate.py プロジェクト: pharazone/ptvsd
 def code_to_debug():
     from dbgimporter import import_and_enable_debugger
     import_and_enable_debugger()
     b_test = {"spam": "A", "eggs": "B", "abcd": "C"}  # noqa
     _b_test = 12  # noqa
     __b_test = 13  # noqa
     __b_test__ = 14  # noqa
     a_test = 1  # noqa
     _a_test = 2  # noqa
     __a_test = 3  # noqa
     __a_test__ = 4  # noqa
     c_test = {1: "one", 2: "two", 10: "ten"}  # noqa
     _c_test = 22  # noqa
     __c_test = 23  # noqa
     __c_test__ = 24  # noqa
     d = 3  # noqa
     print('done')
コード例 #10
0
ファイル: timeline.py プロジェクト: redreamality/ptvsd
    def _expect_realized(self, expectation, first, explain=True, observe=True):
        self.expect_frozen()

        try:
            reasons = next(expectation.test(first, self.last))
        except StopIteration:
            print(colors.LIGHT_RED + 'No matching ' + colors.RESET + colors.color_repr(expectation))
            # The weird always-false assert is to make pytest print occurrences nicely.
            occurrences = list(first.and_following())
            assert occurrences is ('not matching expectation', expectation)

        occs = tuple(reasons.values())
        assert occs
        if observe:
            self.observe(*occs)
        if explain:
            self._explain_how_realized(expectation, reasons)
        return occs if len(occs) > 1 else occs[0]
コード例 #11
0
ファイル: timeline.py プロジェクト: scorphus/ptvsd
    def _expect_realized(self, expectation, occurrences, explain=True, observe=True):
        self.expect_frozen()

        occurrences = list(occurrences)
        reasons = expectation.test_until_realized(occurrences)
        if reasons is None:
            print(colors.LIGHT_RED + 'No matching ' + colors.RESET + colors.color_repr(expectation))

            # The weird always-false assert is to make pytest print occurrences nicely.
            occurrences = list(occurrences)
            assert occurrences is ('not matching expectation', expectation)

        if observe:
            self.observe(*reasons.values())

        realized_at = reasons[expectation]
        if explain:
            self._explain_how_realized(realized_at, expectation, reasons)
        return realized_at
コード例 #12
0
ファイル: timeline.py プロジェクト: agrimarcal/ptvsd
    def _explain_how_realized(self, occurrence, expectation, reasons):
        message = (colors.LIGHT_MAGENTA + 'Realized ' + colors.RESET +
                   colors.color_repr(expectation) + colors.LIGHT_MAGENTA +
                   ' via ' + colors.RESET + colors.color_repr(occurrence))

        # For the breakdown, we want to skip the top-level expectation (since we already
        # printed that above), and also any expectations that were exact occurrences,
        # since there's no point explaining that occurrence was realized by itself.
        skip = [expectation] + [
            exp for exp in reasons.keys() if isinstance(exp, Occurrence)
        ]
        for exp in skip:
            reasons.pop(exp, None)

        if reasons:
            message += colors.LIGHT_MAGENTA + '; breakdown:' + colors.RESET
            for exp, reason in reasons.items():
                message += ('\n    ' + colors.color_repr(exp) +
                            colors.LIGHT_MAGENTA + ' by ' + colors.RESET +
                            colors.color_repr(reason))
        print(message)
コード例 #13
0
ファイル: timeline.py プロジェクト: scorphus/ptvsd
        def has_been_realized(occ):
            # First time wait_until() calls us, we have to check the whole timeline.
            # On subsequent calls, we only need to check the newly added occurrence.
            if check_past:
                if explain:
                    print(
                        colors.LIGHT_MAGENTA + 'Testing ' + colors.RESET +
                        colors.color_repr(expectation) +
                        colors.LIGHT_MAGENTA + ' against timeline up to and including ' + colors.RESET +
                        colors.color_repr(occ)
                    )
                reasons.update(expectation.test_at_or_before(occ) or {})
                del check_past[:]
            else:
                if explain:
                    print(
                        colors.LIGHT_MAGENTA + 'Testing ' + colors.RESET +
                        colors.color_repr(expectation) +
                        colors.LIGHT_MAGENTA + ' against ' + colors.RESET +
                        colors.color_repr(occ)
                    )
                reasons.update(expectation.test_at(occ) or {})

            if reasons:
                if observe:
                    self.expect_realized(expectation, explain=explain, observe=observe)
                return True
            else:
                if explain:
                    print(
                        colors.color_repr(occ) +
                        colors.LIGHT_MAGENTA + ' did not realize ' + colors.RESET +
                        colors.color_repr(expectation)
                    )
コード例 #14
0
 def code_to_debug():
     import sys
     from dbgimporter import import_and_enable_debugger
     import_and_enable_debugger()
     print('one')
     print('two')
     print('three')
     sys.exit(12345)
コード例 #15
0
ファイル: timeline.py プロジェクト: scorphus/ptvsd
    def __init__(self, *expectations):
        self.expectations = expectations
        assert len(expectations) > 0
        assert all(isinstance(exp, Expectation) for exp in expectations)

        timelines = {id(exp.timeline): exp.timeline for exp in expectations}
        timelines.pop(id(None), None)
        if len(timelines) > 1:
            print(colors.RED + 'Cannot mix expectations from multiple timelines:' + colors.RESET)
            for tl_id, tl in timelines.items():
                print('\n    %d: %r' % (tl_id, tl))
            print()
            raise ValueError('Cannot mix expectations from multiple timelines')
        for tl in timelines.values():
            self.timeline = tl
コード例 #16
0
 def code_to_debug():
     a = 1
     print(a)
コード例 #17
0
ファイル: test_evaluate.py プロジェクト: danishprakash/ptvsd
 def code_to_debug():
     a = 1
     b = {"one": 1, "two": 2}
     c = 3
     print([a, b, c])
コード例 #18
0
ファイル: test_evaluate.py プロジェクト: pharazone/ptvsd
 def code_to_debug():
     from dbgimporter import import_and_enable_debugger
     import_and_enable_debugger()
     a = 1
     print(a)
コード例 #19
0
 def code_to_debug():
     from dbgimporter import import_and_enable_debugger
     import_and_enable_debugger()
     print('one')
     print('two')
     print('three')
コード例 #20
0
 def code_to_debug():
     import sys
     print('one')
     print('two')
     print('three')
     sys.exit(12345)
コード例 #21
0
 def code_to_debug():
     print('one')
     print('two')
     print('three')