def setUp(self): self.rmi_launcher = ApplicationLauncher(application) self.rmi_launcher._get_output_files = lambda: ('out', 'err') self.rmi_launcher.db_path = '/tempfile' self.rmi_launcher.application_started = self._fake_application_started self.os_library = _FakeOperatingSystemLibrary() self.rmi_launcher.operating_system = self.os_library
class TestApplicationLauncherImportingLibrary(unittest.TestCase): def setUp(self): class _FakeNamespace: _testlibs = {} NAMESPACES.current = _FakeNamespace() self.rmi_launcher = ApplicationLauncher(application) self.builtin_library = _FakeBuiltInLibrary() self.rmi_launcher.builtin = self.builtin_library self.rmi_launcher._run_remote_import = self._fake_remote_import self.rmi_launcher._prepare_for_reimport_if_necessary = lambda x,*args: None self.library = None def test_imports(self): self.rmi_launcher.import_remote_library('SomeLibrary', 'WITH NAME', 'someLib') assert_equals('SomeLibrary', self.library_name) assert_equals('ApplicationLauncher.RemoteLibrary', self.builtin_library.library) expected_args = ('rmi://someservice', 'WITH NAME', 'someLib') assert_equals(expected_args, self.builtin_library.arguments) def test_adds_name_when_with_name_is_not_used(self): self.rmi_launcher.import_remote_library('SomeLibrary') assert_equals('SomeLibrary', self.library_name) assert_equals('ApplicationLauncher.RemoteLibrary', self.builtin_library.library) expected_args = ('rmi://someservice', 'WITH NAME', 'SomeLibrary') assert_equals(expected_args, self.builtin_library.arguments) def test_parses_timestring(self): rmi_launcher = ApplicationLauncher(application, '1 second') assert_equals(1, rmi_launcher.timeout) def _fake_remote_import(self, library_name): self.library_name = library_name return 'rmi://someservice'
class TestApplicationLauncherStartingApplication(unittest.TestCase): def setUp(self): self.rmi_launcher = ApplicationLauncher(application) self.rmi_launcher.db_path = '/tempfile' self.os_library = _FakeOperatingSystemLibrary() self.rmi_launcher.operating_system = self.os_library def test_starts_application(self): self.rmi_launcher.start_application() assert_equals(self._get_expected_command(), self.os_library.command) def tests_passes_arguments(self): self.rmi_launcher.start_application('-Done=two -Dthree=four', 'one two three') expected_command = self._get_expected_command('-Done=two -Dthree=four', 'one two three') assert_equals(expected_command, self.os_library.command) def _get_expected_command(self, jvm_args='', args=''): current_pythonpath = self._get_current_pythonpath() script_path = self._get_path_to_script() template = 'jython -Dpython.path=%s %s %s /tempfile %s %s' return template % (current_pythonpath, jvm_args, script_path, application, args) def _get_current_pythonpath(self): return os.pathsep.join(sys.path) def _get_path_to_script(self): base = os.path.abspath(os.path.normpath(os.path.split(sys.argv[0])[0])) return '%s/src/main/python/ApplicationLauncher.py' % base
def setUp(self): class _FakeNamespace: _testlibs = {} NAMESPACES.current = _FakeNamespace() self.rmi_launcher = ApplicationLauncher(application) self.builtin_library = _FakeBuiltInLibrary() self.rmi_launcher.builtin = self.builtin_library self.rmi_launcher._run_remote_import = self._fake_remote_import self.rmi_launcher._prepare_for_reimport_if_necessary = lambda x,*args: None self.library = None
class TestApplicationLauncherStartingApplication(unittest.TestCase): def setUp(self): self.rmi_launcher = ApplicationLauncher(application) self.rmi_launcher._get_output_files = lambda: ('out', 'err') self.rmi_launcher.db_path = '/tempfile' self.rmi_launcher.application_started = self._fake_application_started self.os_library = _FakeOperatingSystemLibrary() self.rmi_launcher.operating_system = self.os_library def test_starts_application(self): self.rmi_launcher.start_application() assert_equals(self._get_expected_command(), self.os_library.command) assert_true(self.application_started) def tests_passes_arguments(self): self.rmi_launcher.start_application('one two three', '-Done=two -Dthree=four') expected_command = self._get_expected_command( 'one two three', '-Done=two -Dthree=four') assert_equals(expected_command, self.os_library.command) def _get_expected_command(self, args='', jvm_args=''): current_pythonpath = self._get_current_pythonpath() script_path = self._get_path_to_script() template = 'jython -Dpython.path="%s" %s "%s" %s %s 1>out 2>err' return template % (current_pythonpath, jvm_args, script_path, application, args) def _get_current_pythonpath(self): for path_entry in sys.path: if os.path.exists(os.path.join(path_entry, 'robot')): return path_entry def _get_path_to_script(self): base = os.path.abspath(os.path.normpath(os.path.split(sys.argv[0])[0])) return '%s/src/main/python/ApplicationLauncher.py' % base def _fake_application_started(self): self.application_started = True
class TestApplicationLauncherStartingApplication(unittest.TestCase): def setUp(self): self.rmi_launcher = ApplicationLauncher(application) self.rmi_launcher._get_output_files = lambda: ('out', 'err') self.rmi_launcher.db_path = '/tempfile' self.rmi_launcher.application_started = self._fake_application_started self.os_library = _FakeOperatingSystemLibrary() self.rmi_launcher.operating_system = self.os_library def test_starts_application(self): self.rmi_launcher.start_application() assert_equals(self._get_expected_command(), self.os_library.command) assert_true(self.application_started) def tests_passes_arguments(self): self.rmi_launcher.start_application('one two three', '-Done=two -Dthree=four') expected_command = self._get_expected_command('one two three', '-Done=two -Dthree=four') assert_equals(expected_command, self.os_library.command) def _get_expected_command(self, args='', jvm_args=''): current_pythonpath = self._get_current_pythonpath() script_path = self._get_path_to_script() template = 'jython -Dpython.path="%s" %s "%s" %s %s 1>out 2>err' return template % (current_pythonpath, jvm_args, script_path, application, args) def _get_current_pythonpath(self): for path_entry in sys.path: if os.path.exists(os.path.join(path_entry, 'robot')): return path_entry def _get_path_to_script(self): base = os.path.abspath(os.path.normpath(os.path.split(sys.argv[0])[0])) return '%s/src/main/python/ApplicationLauncher.py' % base def _fake_application_started(self): self.application_started = True
def test_parses_timestring(self): rmi_launcher = ApplicationLauncher(application, '1 second') assert_equals(1, rmi_launcher.timeout)
def setUp(self): self.rmi_launcher = ApplicationLauncher(application) self.rmi_launcher.db_path = '/tempfile' self.os_library = _FakeOperatingSystemLibrary() self.rmi_launcher.operating_system = self.os_library