Add TestsBase.pathentry.

This commit is contained in:
Eric Snow 2018-04-10 20:13:36 +00:00
parent ac7b58e6d8
commit f9666d5147

View file

@ -1,9 +1,8 @@
from textwrap import dedent
import unittest
from tests.helpers.editor import FakeEditor, get_locked_and_waiter
from tests.helpers.vsc import parse_message
from tests.helpers.workspace import PathEntry
from tests.helpers.workspace import Workspace, PathEntry
def lifecycle_handshake(session, command='launch', options=None):
@ -24,25 +23,26 @@ class TestsBase(object):
try:
return self._workspace
except AttributeError:
self._workspace = PathEntry()
self._workspace = Workspace()
self.addCleanup(self._workspace.cleanup)
self._workspace.install()
return self._workspace
def add_module(self, name, content):
return self.workspace.write_module(name, dedent(content))
def assert_received(self, received, expected):
received = [parse_message(msg) for msg in received]
expected = [parse_message(msg) for msg in expected]
self.assertEqual(received, expected)
@property
def pathentry(self):
try:
return self._pathentry
except AttributeError:
self._pathentry = PathEntry()
self.addCleanup(self._pathentry.cleanup)
self._pathentry.install()
return self._pathentry
class CLITests(TestsBase, unittest.TestCase):
def test_script_args(self):
lockfile, lockwait = self.workspace.lockfile('done.lock')
filename = self.add_module('spam', """
filename = self.pathentry.write_module('spam', """
import sys
print(sys.argv)
sys.stdout.flush()
@ -66,7 +66,7 @@ class CLITests(TestsBase, unittest.TestCase):
"[{!r}, '--eggs']\n".format(filename))
def test_run_to_completion(self):
filename = self.add_module('spam', """
filename = self.pathentry.write_module('spam', """
import sys
print('done')
sys.stdout.flush()
@ -84,7 +84,7 @@ class CLITests(TestsBase, unittest.TestCase):
self.assertEqual(rc, 0)
def test_failure(self):
filename = self.add_module('spam', """
filename = self.pathentry.write_module('spam', """
import sys
sys.exit(42)
""")
@ -101,6 +101,11 @@ class CLITests(TestsBase, unittest.TestCase):
class LifecycleTests(TestsBase, unittest.TestCase):
def assert_received(self, received, expected):
received = [parse_message(msg) for msg in received]
expected = [parse_message(msg) for msg in expected]
self.assertEqual(received, expected)
def test_pre_init(self):
lock, wait = get_locked_and_waiter()
@ -111,7 +116,7 @@ class LifecycleTests(TestsBase, unittest.TestCase):
return False
lock.release()
return True
filename = self.add_module('spam', '')
filename = self.pathentry.write_module('spam', '')
with FakeEditor() as editor:
adapter, session = editor.launch_script(
filename,