def setUp(self):
        self.user = getpass.getuser()
        self.node = platform.node()
        self.name = self.node.replace('.', '_')
        self.python = find_python()
        self.cluster = None

        if sys.platform == 'win32' or self.user not in SSH_USERS:
            self.skip_ssh = True
        else:
            self.skip_ssh = False

        self.machines = []
        if self.node.startswith('gxterm'):
            # User environment assumed OK on this GRC cluster front-end.
            for i in range(1, 55):
                self.machines.append({'hostname':'gx%02d' % i,
                                      'python':self.python})
        else:
            self.machines.append({'hostname':self.node,
                                  'python':self.python})

        # Ensure we aren't held up by local host load problems.
        for allocator in ResourceAllocationManager.list_allocators():
            if allocator.name == 'LocalHost':
                self.local = allocator
                self.local.max_load = 10
                break
        else:
            raise RuntimeError('No LocalHost allocator!?')
    def test_main_module(self):
        if MODULE_NAME == '__main__':
            return

        # Ensure that __main__ translation is correctly handled.
        logging.debug('')
        logging.debug('test_main_module')

        # Find correct python.
        python = find_python()
        logging.debug('    Using python: %s' % python)

        orig_dir = os.getcwd()
        os.chdir(PY_DIR)
        try:
            cmdline = [python, 'test_egg_save.py']
            stdout = open('main_handling.out', 'w')
            retcode = subprocess.call(cmdline, stdout=stdout,
                                      stderr=subprocess.STDOUT)
            stdout.close()
            stdout = open('main_handling.out', 'r')
            for line in stdout:
                logging.debug('    %s' % line.rstrip())
            stdout.close()
            os.remove('main_handling.out')
        finally:
            os.chdir(orig_dir)

        self.assertEqual(retcode, 0)
    def test_main_module(self):
        if MODULE_NAME == '__main__':
            return

        # Ensure that __main__ translation is correctly handled.
        logging.debug('')
        logging.debug('test_main_module')

        # Find correct python.
        python = find_python()
        logging.debug('    Using python: %s' % python)

        orig_dir = os.getcwd()
        os.chdir(PY_DIR)
        try:
            cmdline = [python, 'test_egg_save.py']
            stdout = open('main_handling.out', 'w')
            retcode = subprocess.call(cmdline, stdout=stdout,
                                      stderr=subprocess.STDOUT)
            stdout.close()
            stdout = open('main_handling.out', 'r')
            for line in stdout:
                logging.debug('    %s' % line.rstrip())
            stdout.close()
            os.remove('main_handling.out')
        finally:
            os.chdir(orig_dir)

        self.assertEqual(retcode, 0)
    def setUp(self):
        # Save existing RAM instance and force a rebuild.
        self.orig_ram = RAM._RAM
        RAM._RAM = None
        RAM.configure('')

        self.user = getpass.getuser()
        self.node = platform.node()
        self.name = self.node.replace('.', '_')
        self.python = find_python()
        self.cluster = None

        if sys.platform == 'win32' or self.user not in SSH_USERS:
            self.skip_ssh = True
        else:
            self.skip_ssh = False

        self.machines = []
        self.machines.append({'hostname': self.node,
                              'python': self.python})

        # Ensure we aren't held up by local host load problems.
        for allocator in RAM.list_allocators():
            if allocator.name == 'LocalHost':
                self.local = allocator
                self.local.max_load = 10
                break
        else:
            raise RuntimeError('No LocalHost allocator!?')
    def setUp(self):
        # Save existing RAM instance and force a rebuild.
        self.orig_ram = RAM._RAM
        RAM._RAM = None
        RAM.configure('')

        self.user = getpass.getuser()
        self.node = platform.node()
        self.name = self.node.replace('.', '_')
        self.python = find_python()
        self.cluster = None

        if sys.platform == 'win32' or self.user not in SSH_USERS:
            self.skip_ssh = True
        else:
            self.skip_ssh = False

        self.machines = []
        self.machines.append({'hostname': self.node, 'python': self.python})

        # Ensure we aren't held up by local host load problems.
        for allocator in RAM.list_allocators():
            if allocator.name == 'LocalHost':
                self.local = allocator
                self.local.max_load = 10
                break
        else:
            raise RuntimeError('No LocalHost allocator!?')
示例#6
0
    def test_main_module(self):
        #something about new windows machine configuration
        #makes this test fail only when the test is run remotely
        #and only on windows.  skipping for now.
        #if sys.platform == 'win32' or sys.platform == 'win64':
        #now failing on linux and anaconda as well
        raise nose.SkipTest("networkx update required some numpy libraries that make test fail.")

        if MODULE_NAME == '__main__':
            return

        # Ensure that __main__ translation is correctly handled.
        logging.debug('')
        logging.debug('test_main_module')

        # Find correct python.
        python = find_python()
        logging.debug('    Using python: %s' % python)

        orig_dir = os.getcwd()

        os.chdir(PY_DIR)
        try:
            cmdline = [python, os.path.join(TestCase.directory,
                                           'test_egg_save.py')]
            stdout = open('main_handling.out', 'w')
            retcode = subprocess.call(cmdline, stdout=stdout,
                                      stderr=subprocess.STDOUT)
            stdout.close()
            stdout = open('main_handling.out', 'r')
            for line in stdout:
                logging.debug('    %s' % line.rstrip())
            stdout.close()
            os.remove('main_handling.out')
        finally:
            os.chdir(orig_dir)

        self.assertEqual(retcode, 0)
示例#7
0
    def setUp(self):
        self.user = getpass.getuser()
        self.node = platform.node()
        self.name = self.node.replace('.', '_')
        self.python = find_python()
        self.cluster = None

        if sys.platform == 'win32' or self.user not in SSH_USERS:
            self.skip_ssh = True
        else:
            self.skip_ssh = False

        self.machines = []
        self.machines.append({'hostname': self.node, 'python': self.python})

        # Ensure we aren't held up by local host load problems.
        for allocator in ResourceAllocationManager.list_allocators():
            if allocator.name == 'LocalHost':
                self.local = allocator
                self.local.max_load = 10
                break
        else:
            raise RuntimeError('No LocalHost allocator!?')
    def setUp(self):
        self.user = getpass.getuser()
        self.node = platform.node()
        self.name = self.node.replace('.', '_')
        self.python = find_python()
        self.cluster = None

        if sys.platform == 'win32' or self.user not in SSH_USERS:
            self.skip_ssh = True
        else:
            self.skip_ssh = False

        self.machines = []
        self.machines.append({'hostname':self.node,
                              'python':self.python})

        # Ensure we aren't held up by local host load problems.
        for allocator in ResourceAllocationManager.list_allocators():
            if allocator.name == 'LocalHost':
                self.local = allocator
                self.local.max_load = 10
                break
        else:
            raise RuntimeError('No LocalHost allocator!?')
    def test_install_load(self):
        # Creates egg.
        # Installs in special directory.
        # Tries to load and run from installed egg in various ways.
        logging.debug('')
        logging.debug('test_install_load')

        # Find correct python.
        python = find_python()
        logging.debug('    Using python: %s' % python)

        # Write to egg.
        egg_info = self.model.save_to_egg(self.model.name, next_egg(),
                                          py_dir=PY_DIR,
                                          child_objs=self.child_objs)
        self.egg_name = egg_info[0]

        # Create directory for installation.
        install_dir = os.path.join(os.getcwd(), 'install_dir')
        if os.path.exists(install_dir):
            shutil.rmtree(install_dir, onerror=onerror)
        os.mkdir(install_dir)
        try:
            # Create special installer script.
            # This basically does an easy_install.
            installer = os.path.join(install_dir, 'installer.py')
            out = open(installer, 'w')
            out.write("""\
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools>=0.6c8','console_scripts','easy_install'
__requires__ = 'setuptools>=0.6c8'
import os
import sys
from pkg_resources import load_entry_point

#print
#print 'Installer Environment:'
#for name, val in sorted(os.environ.items(), key=lambda item: item[0]):
#    print '    %s = %r' % (name, val)
#print

sys.exit(
   load_entry_point('setuptools>=0.6c8', 'console_scripts', 'easy_install')()
)
""")
            out.close()

            # Install via subprocess with PYTHONPATH set (for easy_install).
            logging.debug('Installing via subprocess...')
            env = os.environ.copy()
            path = env.get('PYTHONPATH', '')
            if path:
                path += os.pathsep
            path += install_dir
            env['PYTHONPATH'] = path

            #            logging.debug('Test Environment:')
            #            for name, val in sorted(env.items(), key=lambda item: item[0]):
            #                logging.debug('    %s = %r', name, val)

            cmdline = [python, installer, '-d', install_dir, self.egg_name]

            stdout = open(os.path.join(install_dir, 'installer.out'), 'w')
            retcode = subprocess.call(cmdline, env=env,
                                      stdout=stdout, stderr=subprocess.STDOUT)
            stdout.close()
            stdout = open(os.path.join(install_dir, 'installer.out'), 'r')
            for line in stdout:
                logging.debug('    %s', line.rstrip())
            stdout.close()
            self.assertEqual(retcode, 0)

            # Load full model and run.
            package_name = self.model.name
            entry_name = ''
            retcode = self.load_n_run(python, install_dir,
                                      package_name, entry_name)
            self.assertEqual(retcode, 0)

            # Load just the Oddball component and run.
            entry_name = self.model.Oddball.get_pathname()
            retcode = self.load_n_run(python, install_dir,
                                      package_name, entry_name)
            self.assertEqual(retcode, 0)

            # Try a non-existent package.
            code = "Component.load_from_eggpkg('no-such-pkg', 'no-such-entry')"
            assert_raises(self, code, globals(), locals(),
                          pkg_resources.DistributionNotFound, 'no-such-pkg')

            # Try a non-existent entry point.
            egg_path = os.path.join(install_dir, self.egg_name)
            sys.path.append(egg_path)
            orig_ws = pkg_resources.working_set
            pkg_resources.working_set = pkg_resources.WorkingSet()
            code = "Component.load_from_eggpkg(package_name, 'no-such-entry')"
            msg = "No 'openmdao.component' 'no-such-entry' entry point."
            try:
                assert_raises(self, code, globals(), locals(), RuntimeError, msg)
            finally:
                sys.path.pop()
                pkg_resources.working_set = orig_ws

        finally:
            shutil.rmtree(install_dir, onerror=onerror)
    def test_install_load(self):
        # Creates egg.
        # Installs in special directory.
        # Tries to load and run from installed egg in various ways.
        logging.debug('')
        logging.debug('test_install_load')

        # Find correct python.
        python = find_python()
        logging.debug('    Using python: %s' % python)

        # Write to egg.
        egg_info = self.model.save_to_egg(self.model.name, next_egg(),
                                          py_dir=PY_DIR,
                                          child_objs=self.child_objs)
        self.egg_name = egg_info[0]

        # Create directory for installation.
        install_dir = os.path.join(os.getcwd(), 'install_dir')
        if os.path.exists(install_dir):
            shutil.rmtree(install_dir, onerror=onerror)
        os.mkdir(install_dir)
        try:
            # Create special installer script.
            # This basically does an easy_install.
            installer = os.path.join(install_dir, 'installer.py')
            out = open(installer, 'w')
            out.write("""\
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools>=0.6c8','console_scripts','easy_install'
__requires__ = 'setuptools>=0.6c8'
import os
import sys
from pkg_resources import load_entry_point

#print
#print 'Installer Environment:'
#for name, val in sorted(os.environ.items(), key=lambda item: item[0]):
#    print '    %s = %r' % (name, val)
#print

sys.exit(
   load_entry_point('setuptools>=0.6c8', 'console_scripts', 'easy_install')()
)
""")
            out.close()

            # Install via subprocess with PYTHONPATH set (for easy_install).
            logging.debug('Installing via subprocess...')
            env = os.environ.copy()
            path = env.get('PYTHONPATH', '')
            if path:
                path += os.pathsep
            path += install_dir
            env['PYTHONPATH'] = path

#            logging.debug('Test Environment:')
#            for name, val in sorted(env.items(), key=lambda item: item[0]):
#                logging.debug('    %s = %r', name, val)

            cmdline = [python, installer, '-d', install_dir, self.egg_name]

            stdout = open(os.path.join(install_dir, 'installer.out'), 'w')
            retcode = subprocess.call(cmdline, env=env,
                                      stdout=stdout, stderr=subprocess.STDOUT)
            stdout.close()
            stdout = open(os.path.join(install_dir, 'installer.out'), 'r')
            for line in stdout:
                logging.debug('    %s', line.rstrip())
            stdout.close()
            self.assertEqual(retcode, 0)

            # Load full model and run.
            package_name = self.model.name
            entry_name = ''
            retcode = self.load_n_run(python, install_dir,
                                      package_name, entry_name)
            self.assertEqual(retcode, 0)

            # Load just the Oddball component and run.
            entry_name = self.model.Oddball.get_pathname()
            retcode = self.load_n_run(python, install_dir,
                                      package_name, entry_name)
            self.assertEqual(retcode, 0)

            # Try a non-existent package.
            code = "Component.load_from_eggpkg('no-such-pkg', 'no-such-entry')"
            assert_raises(self, code, globals(), locals(),
                          pkg_resources.DistributionNotFound, 'no-such-pkg')

            # Try a non-existent entry point.
            egg_path = os.path.join(install_dir, self.egg_name)
            sys.path.append(egg_path)
            orig_ws = pkg_resources.working_set
            pkg_resources.working_set = pkg_resources.WorkingSet()
            code = "Component.load_from_eggpkg(package_name, 'no-such-entry')"
            msg = "No 'openmdao.component' 'no-such-entry' entry point."
            try:
                assert_raises(self, code, globals(), locals(), RuntimeError, msg)
            finally:
                sys.path.pop()
                pkg_resources.working_set = orig_ws

        finally:
            shutil.rmtree(install_dir, onerror=onerror)
示例#11
0
def check_save_load(comp,
                    py_dir=None,
                    test_dir='test_dir',
                    cleanup=True,
                    logfile=None):
    """Convenience routine to check that saving & reloading `comp` works.

    comp: Component
        The component to check.

    py_dir: string or None
        The directory in which to find local Python modules.

    test_dir: string
        Name of a scratch directory to unpack in.

    cleanup: bool
        If True, the scratch directory will be removed after the test.

    logfile: string or None
        Name of file for logging progress.

    Creates an egg in the current directory, unpacks it in `test_dir`
    via a separate process, and then loads and runs the component in
    another subprocess.  Returns the first non-zero subprocess exit code,
    or zero if everything succeeded.
    """
    assert isinstance(comp, Component)

    old_level = comp.log_level
    comp.log_level = LOG_DEBUG
    name = comp.name or get_default_name(comp, comp.parent)
    start = time.time()
    egg_info = comp.save_to_egg(name, 'CSL.1', py_dir=py_dir)
    egg_name = egg_info[0]
    elapsed = time.time() - start
    size = os.path.getsize(egg_name)
    print '\nSaved %d bytes in %.2f seconds (%.2f bytes/sec)' % \
          (size, elapsed, size / elapsed)

    orig_dir = os.getcwd()
    if os.path.exists(test_dir):
        shutil.rmtree(test_dir, onerror=onerror)
    os.mkdir(test_dir)
    os.chdir(test_dir)
    egg_path = os.path.join('..', egg_name)

    try:
        print '\nUnpacking %s in subprocess...' % egg_name
        if logfile:
            stdout = open(logfile, 'w')
        else:
            stdout = None
        stderr = subprocess.STDOUT

        python = find_python()
        print '    python:', python
        unpacker = 'unpack.py'
        out = open(unpacker, 'w')
        out.write("""\
from openmdao.main.api import Component
Component.load_from_eggfile(r'%s')
""" % egg_path)
        out.close()
        args = [python, unpacker]

        retcode = subprocess.call(args,
                                  env=os.environ,
                                  stdout=stdout,
                                  stderr=stderr)
        print '    retcode', retcode
        if retcode == 0:
            print '\nRunning in subprocess...'
            os.chdir(name)
            retcode = subprocess.call([python, name + '_loader.py'],
                                      stdout=stdout,
                                      stderr=stderr)
            print '    retcode', retcode
        if logfile:
            stdout.close()
    finally:
        os.chdir(orig_dir)
        comp.log_level = old_level
        if cleanup:
            os.remove(egg_name)
            shutil.rmtree(test_dir, onerror=onerror)

    return retcode
def check_save_load(comp, py_dir=None, test_dir='test_dir', cleanup=True,
                    logfile=None):
    """Convenience routine to check that saving & reloading `comp` works.

    comp: Component
        The component to check.

    py_dir: string or None
        The directory in which to find local Python modules.

    test_dir: string
        Name of a scratch directory to unpack in.

    cleanup: bool
        If True, the scratch directory will be removed after the test.

    logfile: string or None
        Name of file for logging progress.

    Creates an egg in the current directory, unpacks it in `test_dir`
    via a separate process, and then loads and runs the component in
    another subprocess.  Returns the first non-zero subprocess exit code,
    or zero if everything succeeded.
    """
    assert isinstance(comp, Component)

    old_level = comp.log_level
    comp.log_level = LOG_DEBUG
    name = comp.name or get_default_name(comp, comp.parent)
    start = time.time()
    egg_info = comp.save_to_egg(name, 'CSL.1', py_dir=py_dir)
    egg_name = egg_info[0]
    elapsed = time.time() - start
    size = os.path.getsize(egg_name)
    print '\nSaved %d bytes in %.2f seconds (%.2f bytes/sec)' % \
          (size, elapsed, size/elapsed)

    orig_dir = os.getcwd()
    if os.path.exists(test_dir):
        shutil.rmtree(test_dir, onerror=onerror)
    os.mkdir(test_dir)
    os.chdir(test_dir)
    egg_path = os.path.join('..', egg_name)

    try:
        print '\nUnpacking %s in subprocess...' % egg_name
        if logfile:
            stdout = open(logfile, 'w')
        else:
            stdout = None
        stderr = subprocess.STDOUT

        python = find_python()
        print '    python:', python
        unpacker = 'unpack.py'
        out = open(unpacker, 'w')
        out.write("""\
from openmdao.main.api import Component
Component.load_from_eggfile(r'%s')
""" % egg_path)
        out.close()
        args = [python, unpacker]

        retcode = subprocess.call(args, env=os.environ,
                                  stdout=stdout, stderr=stderr)
        print '    retcode', retcode
        if retcode == 0:
            print '\nRunning in subprocess...'
            os.chdir(name)
            retcode = subprocess.call([python, name+'_loader.py'],
                                      stdout=stdout, stderr=stderr)
            print '    retcode', retcode
        if logfile:
            stdout.close()
    finally:
        os.chdir(orig_dir)
        comp.log_level = old_level
        if cleanup:
            os.remove(egg_name)
            shutil.rmtree(test_dir, onerror=onerror)

    return retcode