Пример #1
0
 def __init__(self):
     self._callbacks = []
     self._model_file = None
     self._vsp = None
     self._excludes = set(['xml_filename', 'write_stereo'])
     base = ExternalCode()
     for key, val in base.items(iotype=not_none):
         self._excludes.add(key)
 def runAllrun(self):
     self.command = [os.path.join(self.foam_case.name,'Allrun')]
     
     if not os.path.exists(self.command[0]):
         return
     
     cDir = os.getcwd()
     os.chdir(self.foam_case.name)
     # Execute the component
     ExternalCode.execute(self)
     os.chdir(cDir)
Пример #3
0
    def test_copy(self):
        logging.debug('')
        logging.debug('test_copy')

        extcode = set_as_top(ExternalCode())

        assert_raises(self, "extcode.copy_inputs('Inputs', '*.inp')",
                      globals(), locals(), RuntimeError,
                      ": inputs_dir 'Inputs' does not exist")

        os.mkdir('Inputs')
        try:
            shutil.copy('sleep.py', os.path.join('Inputs', 'junk.inp'))
            extcode.copy_inputs('Inputs', '*.inp')
            self.assertEqual(os.path.exists('junk.inp'), True)
        finally:
            shutil.rmtree('Inputs', onerror=onerror)
            if os.path.exists('junk.inp'):
                os.remove('junk.inp')

        assert_raises(self, "extcode.copy_results('Outputs', '*.dat')",
                      globals(), locals(), RuntimeError,
                      ": results_dir 'Outputs' does not exist")

        os.mkdir('Outputs')
        try:
            shutil.copy('sleep.py', os.path.join('Outputs', 'junk.dat'))
            extcode.copy_results('Outputs', '*.dat')
            self.assertEqual(os.path.exists('junk.dat'), True)
        finally:
            shutil.rmtree('Outputs', onerror=onerror)
            if os.path.exists('junk.dat'):
                os.remove('junk.dat')
Пример #4
0
    def test_bad_alloc(self):
        logging.debug('')
        logging.debug('test_bad_alloc')

        extcode = set_as_top(ExternalCode())
        extcode.command = ['python', 'sleep.py']
        extcode.resources = {'allocator': 'LocalHost', 'localhost': False}

        assert_raises(self, 'extcode.run()', globals(), locals(), RuntimeError,
                      ': Server allocation failed')
Пример #5
0
    def test_bad_alloc(self):
        logging.debug('')
        logging.debug('test_bad_alloc')

        extcode = set_as_top(ExternalCode())
        extcode.command = ['python', 'sleep.py']
        extcode.resources = {'no_such_resource': 1}

        try:
            extcode.run()
        except RuntimeError as exc:
            self.assertEqual(str(exc), ': Server allocation failed :-(')
        else:
            self.fail('Exected RuntimeError')
Пример #6
0
    def test_timeout(self):
        logging.debug('')
        logging.debug('test_timeout')

        # Set timeout to less than execution time.
        extcode = set_as_top(ExternalCode())
        extcode.timeout = 1
        extcode.command = ['python', 'sleep.py', '5']
        try:
            extcode.run()
        except RunInterrupted as exc:
            self.assertEqual(str(exc), ': Timed out')
            self.assertEqual(extcode.timed_out, True)
        else:
            self.fail('Expected RunInterrupted')
Пример #7
0
    def test_save_load(self):
        logging.debug('')
        logging.debug('test_save_load')

        extcode = set_as_top(ExternalCode())
        extcode.name = 'ExternalCode'
        extcode.timeout = 5
        extcode.command = ['python', 'sleep.py', '1']
        extcode.external_files = [
            FileMetadata(path='sleep.py', input=True, constant=True),
        ]

        # Exercise check_save_load().
        retcode = check_save_load(extcode)
        self.assertEqual(retcode, 0)
Пример #8
0
    def test_badcmd(self):
        logging.debug('')
        logging.debug('test_badcmd')

        # Set command to nonexistant path.
        extcode = set_as_top(ExternalCode())
        extcode.command = ['no-such-command']

        try:
            extcode.run()
        except ValueError as exc:
            msg = ": The command to be executed, 'no-such-command', cannot be found"
            self.assertEqual(str(exc), msg)
            self.assertEqual(extcode.return_code, -999999)
        else:
            self.fail('Expected OSError')
Пример #9
0
    def test_nullcmd(self):
        logging.debug('')
        logging.debug('test_nullcmd')

        # Check response to no command set.
        extcode = set_as_top(ExternalCode())
        extcode.stdout = 'nullcmd.out'
        extcode.stderr = ExternalCode.STDOUT
        try:
            extcode.run()
        except ValueError as exc:
            self.assertEqual(str(exc), ': Empty command list')
        else:
            self.fail('Expected ValueError')
        finally:
            if os.path.exists(extcode.stdout):
                os.remove(extcode.stdout)
Пример #10
0
    def test_badcmd(self):
        logging.debug('')
        logging.debug('test_badcmd')

        # Set command to nonexistant path.
        extcode = set_as_top(ExternalCode())
        extcode.command = ['xyzzy']
        try:
            extcode.run()
        except OSError as exc:
            if sys.platform == 'win32':
                msg = '[Error 2] The system cannot find the file specified'
            else:
                msg = '[Errno 2] No such file or directory'
            self.assertEqual(str(exc), msg)
            self.assertEqual(extcode.return_code, -999999)
        else:
            self.fail('Expected OSError')
Пример #11
0
    def test_badcmd(self):
        logging.debug('')
        logging.debug('test_badcmd')

        # Set command to nonexistant path.
        extcode = set_as_top(ExternalCode())
        extcode.command = ['no-such-command']
        try:
            extcode.run()
        except OSError as exc:
            if sys.platform == 'win32':
                # Apparently XP doesn't include the explanatory text.
                #'[Error 2] The system cannot find the file specified'
                self.assertTrue(str(exc).startswith('[Error 2]'))
            else:
                msg = '[Errno 2] No such file or directory'
                self.assertEqual(str(exc), msg)
            self.assertEqual(extcode.return_code, -999999)
        else:
            self.fail('Expected OSError')