Esempio n. 1
0
    def setUp(self):
        super(TestBase, self).setUp()
        self._pathentry = PathEntry()

        self._filename = None
        if self.FILENAME is not None:
            self.set_source_file(self.FILENAME, self.SOURCE)
Esempio n. 2
0
class TestBase(VSCTest):

    FIXTURE = Fixture

    FILENAME = None
    SOURCE = ''

    def setUp(self):
        super(TestBase, self).setUp()
        self._pathentry = PathEntry()
        # Tests run a new thread in the same process and use that
        # thread as the main thread -- the current thread which is
        # managing the test should be invisible to the debugger.
        import threading
        threading.current_thread().is_pydev_daemon_thread = True

        self._filename = None
        if self.FILENAME is not None:
            self.set_source_file(self.FILENAME, self.SOURCE)

    def tearDown(self):
        super(TestBase, self).tearDown()
        self._pathentry.cleanup()

    @property
    def pathentry(self):
        return self._pathentry

    @property
    def workspace(self):
        try:
            return vars(self)['_workspace']
            #return self._workspace
        except KeyError:
            self._workspace = Workspace()
            self.addCleanup(self._workspace.cleanup)
            return self._workspace

    @property
    def filename(self):
        return None if self._filename is None else self._filePath

    def _new_fixture(self, new_daemon):
        self.assertIsNotNone(self._filename)
        return self.FIXTURE(self._filename, new_daemon)

    def set_source_file(self, filename, content=None):
        self.assertIsNone(self._fix)
        if content is not None:
            filename = self.pathentry.write(filename, content=content)
        self.pathentry.install()
        self._filePath = filename
        self._filename = 'file:' + filename

    def set_module(self, name, content=None):
        self.assertIsNone(self._fix)
        if content is not None:
            self.write_module(name, content)
        self.pathentry.install()
        self._filename = 'module:' + name
Esempio n. 3
0
 def pathentry(self):
     try:
         return self._pathentry
     except AttributeError:
         self._pathentry = PathEntry()
         self.addCleanup(self._pathentry.cleanup)
         self._pathentry.install()
         return self._pathentry
Esempio n. 4
0
class TestBase(VSCTest):

    FIXTURE = Fixture

    FILENAME = None
    SOURCE = ''

    def setUp(self):
        super(TestBase, self).setUp()
        self._pathentry = PathEntry()

        self._filename = None
        if self.FILENAME is not None:
            self.set_source_file(self.FILENAME, self.SOURCE)

    def tearDown(self):
        super(TestBase, self).tearDown()
        self._pathentry.cleanup()

    @property
    def pathentry(self):
        return self._pathentry

    @property
    def workspace(self):
        try:
            return vars(self)['_workspace']
            #return self._workspace
        except KeyError:
            self._workspace = Workspace()
            self.addCleanup(self._workspace.cleanup)
            return self._workspace

    @property
    def filename(self):
        return None if self._filename is None else self._filePath

    def _new_fixture(self, new_daemon):
        self.assertIsNotNone(self._filename)
        return self.FIXTURE(self._filename, new_daemon)

    def set_source_file(self, filename, content=None):
        self.assertIsNone(self._fix)
        if content is not None:
            filename = self.pathentry.write(filename, content=content)
        self.pathentry.install()
        self._filePath = filename
        self._filename = 'file:' + filename

    def set_module(self, name, content=None):
        self.assertIsNone(self._fix)
        if content is not None:
            self.write_module(name, content)
        self.pathentry.install()
        self._filename = 'module:' + name
Esempio n. 5
0
    def setUp(self):
        super(TestBase, self).setUp()
        self._pathentry = PathEntry()
        # Tests run a new thread in the same process and use that
        # thread as the main thread -- the current thread which is
        # managing the test should be invisible to the debugger.
        import threading
        threading.current_thread().is_pydev_daemon_thread = True

        self._filename = None
        if self.FILENAME is not None:
            self.set_source_file(self.FILENAME, self.SOURCE)
Esempio n. 6
0
class TestsBase(object):

    @property
    def workspace(self):
        try:
            return self._workspace
        except AttributeError:
            self._workspace = Workspace()
            self.addCleanup(self._workspace.cleanup)
            return self._workspace

    @property
    def pathentry(self):
        try:
            return self._pathentry
        except AttributeError:
            self._pathentry = PathEntry()
            self.addCleanup(self._pathentry.cleanup)
            self._pathentry.install()
            return self._pathentry

    def enable_verbose(self):
        DebugAdapter.VERBOSE = True

    def write_script(self, name, content):
        return self.workspace.write_python_script(name, content=content)

    def write_debugger_script(self, filename, port, run_as):
        cwd = os.getcwd()
        kwargs = {
            'filename': filename,
            'port_num': port,
            'debug_id': None,
            'debug_options': None,
            'run_as': run_as,
        }
        return self.write_script('debugger.py', """
            import sys
            sys.path.insert(0, {!r})
            from ptvsd.debugger import debug
            debug(
                {filename!r},
                {port_num!r},
                {debug_id!r},
                {debug_options!r},
                {run_as!r},
            )
            """.format(cwd, **kwargs))