コード例 #1
0
    def test_quickstart(self):
        # All options.
        argv = ['quickstart', 'foobar', '-c', 'FooBar', '-g', 'component',
                '-v', '1.1', '-d', self.tdir]
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_quickstart(parser, options, args)
        self.assertEqual(retval, 0)
        fandd = find_files(self.tdir, showdirs=True)
        self.assertEqual(set([os.path.basename(f) for f in fandd]), 
                         set(['foobar', 'src', 'docs', 'setup.cfg', 'setup.py',
                              'MANIFEST.in', '__init__.py', 'conf.py',
                              'usage.rst', 'index.rst',
                              'srcdocs.rst', 'pkgdocs.rst', 'foobar.py', 
                              'README.txt',
                              'test','test_foobar.py']))

        # Errors.
        code = 'plugin_quickstart(parser, options, args)'
        assert_raises(self, code, globals(), locals(), OSError,
                      "Can't create directory '%s' because it already exists."
                      % os.path.join(self.tdir, 'foobar'))

        argv = ['quickstart', 'foobar', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_quickstart(parser, options, args)
        self.assertEqual(retval, -1)
コード例 #2
0
    def test_quickstart(self):
        # All options.
        argv = [
            'quickstart', 'foobar', '-c', 'FooBar', '-g', 'component', '-v',
            '1.1', '-d', self.tdir
        ]
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_quickstart(parser, options, args)
        self.assertEqual(retval, 0)
        fandd = find_files(self.tdir, showdirs=True)
        self.assertEqual(
            set([os.path.basename(f) for f in fandd]),
            set([
                'foobar', 'src', 'docs', 'setup.cfg', 'setup.py',
                'MANIFEST.in', '__init__.py', 'conf.py', 'usage.rst',
                'index.rst', 'srcdocs.rst', 'pkgdocs.rst', 'foobar.py',
                'README.txt', 'test', 'test_foobar.py'
            ]))

        # Errors.
        code = 'plugin_quickstart(parser, options, args)'
        assert_raises(
            self, code, globals(), locals(), OSError,
            "Can't create directory '%s' because it already exists." %
            os.path.join(self.tdir, 'foobar'))

        argv = ['quickstart', 'foobar', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_quickstart(parser, options, args)
        self.assertEqual(retval, -1)
コード例 #3
0
    def test_build_docs(self):
        logging.debug('')
        logging.debug('test_build_docs')

        argv = ['quickstart', 'foobar', '-v', '1.1', '-d', self.tdir]
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        plugin_quickstart(parser, options, args)

        orig_dir = os.getcwd()
        os.chdir(os.path.join(self.tdir, 'foobar'))
        orig_stdout = sys.stdout
        orig_stderr = sys.stderr
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        try:
            argv = ['build_docs', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_build_docs(parser, options, args)
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)

        # Errors.
        argv = ['build_docs', 'foobar', 'no-such-directory', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_build_docs(parser, options, args)
        self.assertEqual(retval, -1)

        argv = ['build_docs', 'foobar', 'no-such-directory']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'plugin_build_docs(parser, options, args)'
        distdir = os.path.join(os.getcwd(), 'no-such-directory')
        assert_raises(self, code, globals(), locals(), IOError,
                      "directory '%s' does not exist" % distdir)

        distdir = os.path.join(self.tdir, 'foobar')
        os.remove(os.path.join(distdir, 'setup.py'))
        argv = ['build_docs', 'foobar', distdir]
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'plugin_build_docs(parser, options, args)'
        assert_raises(self, code, globals(), locals(), IOError,
                      "directory '%s' does not contain 'setup.py'" % distdir)
コード例 #4
0
    def test_build_docs(self):
        logging.debug('')
        logging.debug('test_build_docs')

        argv = ['quickstart', 'foobar', '-v', '1.1', '-d', self.tdir]
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        plugin_quickstart(parser, options, args)

        orig_dir = os.getcwd()
        os.chdir(os.path.join(self.tdir, 'foobar'))
        orig_stdout = sys.stdout
        orig_stderr = sys.stderr
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        try:
            argv = ['build_docs', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_build_docs(parser, options, args)
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)

        # Errors.
        argv = ['build_docs', 'foobar', 'no-such-directory', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_build_docs(parser, options, args)
        self.assertEqual(retval, -1)

        argv = ['build_docs', 'foobar', 'no-such-directory']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'plugin_build_docs(parser, options, args)'
        distdir = os.path.join(os.getcwd(), 'no-such-directory')
        assert_raises(self, code, globals(), locals(), IOError,
                      "directory '%s' does not exist" % distdir)

        distdir = os.path.join(self.tdir, 'foobar')
        os.remove(os.path.join(distdir, 'setup.py'))
        argv = ['build_docs', 'foobar', distdir]
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'plugin_build_docs(parser, options, args)'
        assert_raises(self, code, globals(), locals(), IOError,
                      "directory '%s' does not contain 'setup.py'" % distdir)
コード例 #5
0
    def test_docs(self):
        argv = ['docs', 'no-such-plugin']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'find_docs_url(options.plugin_dist_name)'
        assert_raises(self, code, globals(), locals(), RuntimeError,
                      "Can't locate package/module 'no-such-plugin'")

        argv = ['docs', 'subprocess']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        url = find_docs_url(options.plugin_dist_name)
        expected = os.path.join(os.path.dirname(sys.modules['subprocess'].__file__),
                                'sphinx_build', 'html', 'index.html')
        self.assertEqual(url, expected)
コード例 #6
0
    def test_makedist(self):
        # Errors.
        argv = ['makedist', 'foobar', 'distdir', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_makedist(parser, options, args)
        self.assertEqual(retval, -1)

        argv = ['makedist', 'no-such-directory']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'plugin_makedist(parser, options, args)'
        distdir = os.path.join(os.getcwd(), 'no-such-directory')
        assert_raises(self, code, globals(), locals(), IOError,
                      "directory '%s' does not exist" % distdir)
コード例 #7
0
    def test_makedist(self):
        # Errors.
        argv = ['makedist', 'foobar', 'distdir', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_makedist(parser, options, args)
        self.assertEqual(retval, -1)

        argv = ['makedist', 'no-such-directory']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'plugin_makedist(parser, options, args)'
        distdir = os.path.join(os.getcwd(), 'no-such-directory')
        assert_raises(self, code, globals(), locals(), IOError,
                      "directory '%s' does not exist" % distdir)
コード例 #8
0
 def test_install(self):
     # Errors.
     argv = ['install', 'no-such-plugin', 'stuff']
     parser = _get_plugin_parser()
     options, args = parser.parse_known_args(argv)
     retval = plugin_install(parser, options, args)
     self.assertEqual(retval, -1)
コード例 #9
0
 def test_install(self):
     # Errors.
     argv = ['install', 'no-such-plugin', 'stuff']
     parser = _get_plugin_parser()
     options, args = parser.parse_known_args(argv)
     retval = plugin_install(parser, options, args)
     self.assertEqual(retval, -1)
コード例 #10
0
    def test_docs(self):
        argv = ['docs', 'no-such-plugin']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        code = 'find_docs_url(options.plugin_dist_name)'
        assert_raises(self, code, globals(), locals(), RuntimeError,
                      "Can't locate package/module 'no-such-plugin'")

        argv = ['docs', 'subprocess']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        url = find_docs_url(options.plugin_dist_name)
        expected = os.path.join(
            os.path.dirname(sys.modules['subprocess'].__file__),
            'sphinx_build', 'html', 'index.html')
        self.assertEqual(url, expected)
コード例 #11
0
 def test_quickstart(self):
     argv = ['quickstart', 'foobar', '-v', '1.1', '-d', self.tdir]
     options = _get_plugin_parser().parse_args(argv)
     plugin_quickstart(options)
     fandd = find_files(self.tdir, nodirs=False)
     self.assertEqual(set([os.path.basename(f) for f in fandd]), 
                      set(['foobar', 'src', 'docs', 'setup.cfg', 'setup.py',
                           'MANIFEST.in', '__init__.py', 'conf.py', 'usage.rst', 'index.rst',
                           'srcdocs.rst', 'pkgdocs.rst', 'foobar.py', 
                           'README.txt',
                           'test','test_foobar.py']))
コード例 #12
0
    def test_list(self):
        logging.debug('')
        logging.debug('test_list')

        orig_stdout = sys.stdout
        orig_stderr = sys.stderr
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        try:
            argv = ['list']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_list(parser, options, args)
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
        # Just a selection from each category.
        expected = [
            'openmdao.lib.architectures.bliss.BLISS',
            'openmdao.lib.casehandlers.caseset.CaseArray',
            'openmdao.lib.components.broadcaster.Broadcaster',
            'openmdao.lib.datatypes.array.Array',
            'openmdao.lib.differentiators.finite_difference.FiniteDifference',
            'openmdao.lib.doegenerators.central_composite.CentralComposite',
            'openmdao.lib.drivers.broydensolver.BroydenSolver',
            'openmdao.lib.surrogatemodels.kriging_surrogate.KrigingSurrogate',
            'openmdao.main.assembly.Assembly'
        ]
        for plugin in expected:
            self.assertTrue(plugin in captured_stdout)

        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        try:
            argv = ['list', '-g', 'driver', '--builtin']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_list(parser, options, args)
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
        if 'openmdao.lib.drivers.doedriver.DOEdriver' not in captured_stdout:
            self.fail('-g driver filter failed to include')
        if 'openmdao.main.assembly.Assembly' in captured_stdout:
            self.fail('-g driver filter failed to exclude')

        # Errors.
        argv = ['list', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_list(parser, options, args)
        self.assertEqual(retval, -1)
コード例 #13
0
def run_openmdao_suite(argv=None):
    """This function is exported as a script that is runnable as part of
    an OpenMDAO virtual environment as openmdao test.

    This function wraps nosetests, so any valid nose args should also
    work here.
    """
    if argv is None:
        argv = sys.argv

    #Add any default packages/directories to search for tests to tlist.
    tlist = _get_openmdao_packages()

    break_check = ['--help', '-h', '--all']

    covpkg = False  # if True, --cover-package was specified by the user

    # check for args not starting with '-'
    args = argv[:]
    for i, arg in enumerate(args):
        if arg.startswith('--cover-package'):
            covpkg = True
        if (i > 0 and not arg.startswith('-')) or arg in break_check:
            break
    else:
        args.append("--all")

    args.append('--exe')  # by default, nose will skip any .py files that are
    # executable. --exe prevents this behavior

    # Clobber cached data in case Python environment has changed.
    base = os.path.expanduser(os.path.join('~', '.openmdao'))
    for name in ('eggsaver.dat', 'fileanalyzer.dat'):
        path = os.path.join(base, name)
        if os.path.exists(path):
            os.remove(path)

    # Avoid having any user-defined resources causing problems during testing.
    os.environ['OPENMDAO_RAMFILE'] = ''

    if '--with-coverage' in args:
        args.append('--cover-erase')
        if '--all' in args and not covpkg:
            for pkg in tlist:
                opt = '--cover-package=%s' % pkg
                if opt not in args:
                    args.append(opt)

            # Better coverage if we clobber credential data.
            path = os.path.join(base, 'keys')
            if os.path.exists(path):
                os.remove(path)

    # this tells it to enable the console in the environment so that
    # the logger will print output to stdout. This helps greatly when
    # debugging openmdao scripts running in separate processes.
    if '--enable_console' in args:
        args.remove('--enable_console')
        os.environ['OPENMDAO_ENABLE_CONSOLE'] = '1'

    if '--all' in args:
        args.remove('--all')
        args.extend(tlist)

    if '--plugins' in args:
        args.remove('--plugins')
        from openmdao.main.plugin import plugin_install, _get_plugin_parser
        argv = ['install', '--all']
        parser = _get_plugin_parser()
        options, argz = parser.parse_known_args(argv)
        plugin_install(parser, options, argz)

    # some libs we use call multiprocessing.cpu_count() on import, which can
    # raise NotImplementedError, so try to monkeypatch it here to return 1 if
    # that's the case
    try:
        import multiprocessing
        multiprocessing.cpu_count()
    except ImportError:
        pass
    except NotImplementedError:
        multiprocessing.cpu_count = lambda: 1


#    _trace_atexit()
    nose.run_exit(argv=args)
コード例 #14
0
    def test_list(self):
        logging.debug('')
        logging.debug('test_list')

        orig_stdout = sys.stdout
        orig_stderr = sys.stderr
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        try:
            argv = ['list']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_list(parser, options, args)
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
        # Just a selection from each category.
        expected = ['openmdao.lib.architectures.bliss.BLISS',
                    'openmdao.lib.casehandlers.caseset.CaseArray',
                    'openmdao.lib.components.broadcaster.Broadcaster',
                    'openmdao.lib.datatypes.array.Array',
                    'openmdao.lib.differentiators.finite_difference.FiniteDifference',
                    'openmdao.lib.doegenerators.central_composite.CentralComposite',
                    'openmdao.lib.drivers.broydensolver.BroydenSolver',
                    'openmdao.lib.surrogatemodels.kriging_surrogate.KrigingSurrogate',
                    'openmdao.main.assembly.Assembly']
        for plugin in expected:
            self.assertTrue(plugin in captured_stdout)

        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        try:
            argv = ['list', '-g', 'driver', '--builtin']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_list(parser, options, args)
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
        if 'openmdao.lib.drivers.doedriver.DOEdriver' not in captured_stdout:
            self.fail('-g driver filter failed to include')
        if 'openmdao.main.assembly.Assembly' in captured_stdout:
            self.fail('-g driver filter failed to exclude')

        # Errors.
        argv = ['list', 'stuff']
        parser = _get_plugin_parser()
        options, args = parser.parse_known_args(argv)
        retval = plugin_list(parser, options, args)
        self.assertEqual(retval, -1)
コード例 #15
0
    def test_basic(self):
        logging.debug('')
        logging.debug('test_basic')

        # Just run through a complete cycle.
        orig_dir = os.getcwd()
        orig_stdout = sys.stdout
        orig_stderr = sys.stderr

        # Quickstart.
        logging.debug('')
        logging.debug('quickstart')
        os.chdir(self.tdir)
        try:
            argv = ['quickstart', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_quickstart(parser, options, args)
            self.assertEqual(retval, 0)
            fandd = find_files(self.tdir, showdirs=True)
            self.assertEqual(set([os.path.basename(f) for f in fandd]), 
                             set(['foobar', 'src', 'docs', 'setup.cfg', 'setup.py',
                                  'MANIFEST.in', '__init__.py', 'conf.py',
                                  'usage.rst', 'index.rst',
                                  'srcdocs.rst', 'pkgdocs.rst', 'foobar.py', 
                                  'README.txt',
                                  'test','test_foobar.py']))
        finally:
            os.chdir(orig_dir)

        # Makedist.
        logging.debug('')
        logging.debug('makedist')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        logdata = ''
        os.chdir(os.path.join(self.tdir, 'foobar'))
        try:
            argv = ['makedist']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_makedist(parser, options, args, capture='makedist.out')
            with open('makedist.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
            if sys.platform == 'win32':
                self.assertTrue(os.path.exists('foobar-0.1.zip'))
            else:
                self.assertTrue(os.path.exists('foobar-0.1.tar.gz'))
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        # Existing distribution error.
        logging.debug('')
        logging.debug('makedist error')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        os.chdir(os.path.join(self.tdir, 'foobar'))
        try:
            argv = ['makedist']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_makedist(parser, options, args, capture='makedist.out')
            with open('makedist.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, -1)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)
        self.assertTrue('already exists' in captured_stderr)

        # Install
        logging.debug('')
        logging.debug('install')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        logdata = ''
        os.chdir(self.tdir)
        try:
            argv = ['install', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_install(parser, options, args, capture='install.out')
            with open('install.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        try:
            # List in subprocess to grab updated package environment.
            logging.debug('')
            logging.debug('list')
            os.chdir(self.tdir)
            stdout = open('list.out', 'w')
            try:
                check_call(('plugin', 'list', '-g', 'driver', '-g', 'component',
                            '--external'), stdout=stdout, stderr=STDOUT)
            finally:
                stdout.close()
                with open('list.out', 'r') as inp:
                    captured_stdout = inp.read()
                os.remove('list.out')
                os.chdir(orig_dir)
                logging.debug('captured subprocess output:')
                logging.debug(captured_stdout)
            self.assertTrue('foobar.foobar.Foobar' in captured_stdout)

            # Docs.
            logging.debug('')
            logging.debug('docs')
            argv = ['docs', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            url = find_docs_url(options.plugin_dist_name)
            expected = os.path.join(self.tdir, 'foobar', 'src', 'foobar',
                                    'sphinx_build', 'html', 'index.html')
            self.assertEqual(os.path.realpath(url), os.path.realpath(expected))
        finally:
            # Uninstall
            logging.debug('')
            logging.debug('uninstall')
            with open('pip.in', 'w') as out:
                out.write('y\n')
            stdin = open('pip.in', 'r')
            stdout = open('pip.out', 'w')
            # On EC2 Windows, 'pip' generates an absurdly long temp directory
            # name, apparently to allow backing-out of the uninstall.
            # The name is so long Windows can't handle it. So we try to
            # avoid that by indirectly influencing mkdtemp().
            env = os.environ.copy()
            env['TMP'] = os.path.expanduser('~')
            try:
                check_call(('pip', 'uninstall', 'foobar'), env=env,
                           stdin=stdin, stdout=stdout, stderr=STDOUT)
            finally:
                stdin.close()
                stdout.close()
                with open('pip.out', 'r') as inp:
                    captured_stdout = inp.read()
                os.remove('pip.in')
                os.remove('pip.out')
                logging.debug('captured stdout:')
                logging.debug(captured_stdout)

        # Show removed.
        logging.debug('')
        logging.debug('list removed')
        os.chdir(self.tdir)
        stdout = open('list.out', 'w')
        try:
            check_call(('plugin', 'list', '--external'),
                       stdout=stdout, stderr=STDOUT)
        finally:
            stdout.close()
            with open('list.out', 'r') as inp:
                captured_stdout = inp.read()
            os.remove('list.out')
            os.chdir(orig_dir)
            logging.debug('captured subprocess output:')
            logging.debug(captured_stdout)
        self.assertFalse('foobar.foobar.Foobar' in captured_stdout)
コード例 #16
0
def run_openmdao_suite(argv=None):
    """This function is exported as a script that is runnable as part of
    an OpenMDAO virtual environment as openmdao test.
    
    This function wraps nosetests, so any valid nose args should also
    work here.
    """
    if argv is None:
        argv = sys.argv

    #Add any default packages/directories to search for tests to tlist.
    tlist = _get_openmdao_packages()

    break_check = ['--help', '-h', '--all']

    covpkg = False  # if True, --cover-package was specified by the user

    # check for args not starting with '-'
    args = argv[:]
    for i, arg in enumerate(args):
        if arg.startswith('--cover-package'):
            covpkg = True
        if (i > 0 and not arg.startswith('-')) or arg in break_check:
            break
    else:  # no non '-' args, so assume they want to run the default test suite
        # in a release install, default is the set of tests specified in release_tests.cfg
        if not is_dev_install() or '--small' in args:
            if '--small' in args:
                args.remove('--small')
            args.extend([
                '-c',
                os.path.join(os.path.dirname(__file__), 'release_tests.cfg')
            ])
        else:  # in a dev install, default is all tests
            args.append('--all')

    args.append('--exe')  # by default, nose will skip any .py files that are
    # executable. --exe prevents this behavior

    # Clobber cached data in case Python environment has changed.
    base = os.path.expanduser(os.path.join('~', '.openmdao'))
    for name in ('eggsaver.dat', 'fileanalyzer.dat'):
        path = os.path.join(base, name)
        if os.path.exists(path):
            os.remove(path)

    # Avoid having any user-defined resources causing problems during testing.
    ResourceAllocationManager.configure('')

    if '--with-coverage' in args:
        args.append('--cover-erase')
        if '--all' in args and not covpkg:
            for pkg in tlist:
                opt = '--cover-package=%s' % pkg
                if opt not in args:
                    args.append(opt)

            # Better coverage if we clobber credential data.
            path = os.path.join(base, 'keys')
            if os.path.exists(path):
                os.remove(path)

    # this tells it to enable the console in the environment so that
    # the logger will print output to stdout. This helps greatly when
    # debugging openmdao scripts running in separate processes.
    if '--enable_console' in args:
        args.remove('--enable_console')
        os.environ['OPENMDAO_ENABLE_CONSOLE'] = '1'

    if '--all' in args:
        args.remove('--all')
        args.extend(tlist)

    if '--plugins' in args:
        args.remove('--plugins')
        from openmdao.main.plugin import plugin_install, _get_plugin_parser
        argv = ['install', '--all']
        parser = _get_plugin_parser()
        options, argz = parser.parse_known_args(argv)
        plugin_install(parser, options, argz)

    # The default action should be to run the GUI functional tests.
    # The 'win32' test here is to allow easily changing the default for Windows
    # where testing still has occasional problems not terminating on EC2.
    if sys.platform == 'win32':
        do_gui_tests = False
    else:
        do_gui_tests = True

    # run GUI functional tests, overriding default action
    if '--gui' in args:
        args.remove('--gui')
        do_gui_tests = True

    # skip GUI functional tests, overriding default action
    if '--skip-gui' in args:
        args.remove('--skip-gui')
        do_gui_tests = False

    if not do_gui_tests:
        os.environ['OPENMDAO_SKIP_GUI'] = '1'

    # some libs we use call multiprocessing.cpu_count() on import, which can
    # raise NotImplementedError, so try to monkeypatch it here to return 1 if
    # that's the case
    try:
        import multiprocessing
        multiprocessing.cpu_count()
    except ImportError:
        pass
    except NotImplementedError:
        multiprocessing.cpu_count = lambda: 1


#    _trace_atexit()
    nose.run_exit(argv=args)
コード例 #17
0
    def test_basic(self):
        logging.debug('')
        logging.debug('test_basic')

        # Just run through a complete cycle.
        orig_dir = os.getcwd()
        orig_stdout = sys.stdout
        orig_stderr = sys.stderr

        # Quickstart.
        logging.debug('')
        logging.debug('quickstart')
        os.chdir(self.tdir)
        try:
            argv = ['quickstart', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_quickstart(parser, options, args)
            self.assertEqual(retval, 0)
            fandd = find_files(self.tdir, showdirs=True)
            self.assertEqual(
                set([os.path.basename(f) for f in fandd]),
                set([
                    'foobar', 'src', 'docs', 'setup.cfg', 'setup.py',
                    'MANIFEST.in', '__init__.py', 'conf.py', 'usage.rst',
                    'index.rst', 'srcdocs.rst', 'pkgdocs.rst', 'foobar.py',
                    'README.txt', 'test', 'test_foobar.py'
                ]))
        finally:
            os.chdir(orig_dir)

        # Makedist.
        logging.debug('')
        logging.debug('makedist')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        logdata = ''
        os.chdir(os.path.join(self.tdir, 'foobar'))
        try:
            argv = ['makedist']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_makedist(parser,
                                     options,
                                     args,
                                     capture='makedist.out')
            with open('makedist.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
            if sys.platform == 'win32':
                self.assertTrue(os.path.exists('foobar-0.1.zip'))
            else:
                self.assertTrue(os.path.exists('foobar-0.1.tar.gz'))
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        # Existing distribution error.
        logging.debug('')
        logging.debug('makedist error')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        os.chdir(os.path.join(self.tdir, 'foobar'))
        try:
            argv = ['makedist']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_makedist(parser,
                                     options,
                                     args,
                                     capture='makedist.out')
            with open('makedist.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, -1)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)
        self.assertTrue('already exists' in captured_stderr)

        # Install
        logging.debug('')
        logging.debug('install')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        logdata = ''
        os.chdir(self.tdir)
        try:
            argv = ['install', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_install(parser,
                                    options,
                                    args,
                                    capture='install.out')
            with open('install.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        try:
            # List in subprocess to grab updated package environment.
            logging.debug('')
            logging.debug('list')
            os.chdir(self.tdir)
            stdout = open('list.out', 'w')
            try:
                check_call(('plugin', 'list', '-g', 'driver', '-g',
                            'component', '--external'),
                           stdout=stdout,
                           stderr=STDOUT)
            finally:
                stdout.close()
                with open('list.out', 'r') as inp:
                    captured_stdout = inp.read()
                os.remove('list.out')
                os.chdir(orig_dir)
                logging.debug('captured subprocess output:')
                logging.debug(captured_stdout)
            self.assertTrue('foobar.foobar.Foobar' in captured_stdout)

            # Docs.
            logging.debug('')
            logging.debug('docs')
            argv = ['docs', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            url = find_docs_url(options.plugin_dist_name)
            # Strip off the file protocol header
            url = url.replace('file://', '')
            expected = os.path.join(self.tdir, 'foobar', 'src', 'foobar',
                                    'sphinx_build', 'html', 'index.html')
            self.assertEqual(os.path.realpath(url), os.path.realpath(expected))
        finally:
            # Uninstall
            logging.debug('')
            logging.debug('uninstall')
            pip_in = os.path.join(self.tdir, 'pip.in')
            pip_out = os.path.join(self.tdir, 'pip.out')
            with open(pip_in, 'w') as out:
                out.write('y\n')
            stdin = open(pip_in, 'r')
            stdout = open(pip_out, 'w')
            # On EC2 Windows, 'pip' generates an absurdly long temp directory
            # name, apparently to allow backing-out of the uninstall.
            # The name is so long Windows can't handle it. So we try to
            # avoid that by indirectly influencing mkdtemp().
            env = os.environ.copy()
            env['TMP'] = os.path.expanduser('~')
            try:
                # the following few lines are to prevent the system level pip
                # from being used instead of the local virtualenv version.
                pipexe = 'pip-%d.%d' % (sys.version_info[0],
                                        sys.version_info[1])
                pipexe = find_in_path(pipexe)
                if pipexe is None:
                    pipexe = 'pip'
                check_call((pipexe, 'uninstall', 'foobar'),
                           env=env,
                           stdin=stdin,
                           stdout=stdout,
                           stderr=STDOUT)
            finally:
                stdin.close()
                stdout.close()
                with open(pip_out, 'r') as inp:
                    captured_stdout = inp.read()
                logging.debug('captured stdout:')
                logging.debug(captured_stdout)

        # Show removed.
        logging.debug('')
        logging.debug('list removed')
        os.chdir(self.tdir)
        stdout = open('list.out', 'w')
        try:
            check_call(('plugin', 'list', '--external'),
                       stdout=stdout,
                       stderr=STDOUT)
        finally:
            stdout.close()
            with open('list.out', 'r') as inp:
                captured_stdout = inp.read()
            os.remove('list.out')
            os.chdir(orig_dir)
            logging.debug('captured subprocess output:')
            logging.debug(captured_stdout)
        self.assertFalse('foobar.foobar.Foobar' in captured_stdout)
コード例 #18
0
ファイル: testing.py プロジェクト: hitej/meta-core
def run_openmdao_suite(argv=None):
    """This function is exported as a script that is runnable as part of
    an OpenMDAO virtual environment as openmdao test.
    
    This function wraps nosetests, so any valid nose args should also
    work here.
    """
    if argv is None:
        argv = sys.argv

    # Add any default packages/directories to search for tests to tlist.
    tlist = _get_openmdao_packages()

    break_check = ["--help", "-h", "--all"]

    covpkg = False  # if True, --cover-package was specified by the user

    # check for args not starting with '-'
    args = argv[:]
    for i, arg in enumerate(args):
        if arg.startswith("--cover-package"):
            covpkg = True
        if (i > 0 and not arg.startswith("-")) or arg in break_check:
            break
    else:  # no non '-' args, so assume they want to run the default test suite
        # in a release install, default is the set of tests specified in release_tests.cfg
        if not is_dev_install() or "--small" in args:
            if "--small" in args:
                args.remove("--small")
            args.extend(["-c", os.path.join(os.path.dirname(__file__), "release_tests.cfg")])
        else:  # in a dev install, default is all tests
            args.append("--all")

    args.append("--exe")  # by default, nose will skip any .py files that are
    # executable. --exe prevents this behavior

    # Clobber cached data in case Python environment has changed.
    base = os.path.expanduser(os.path.join("~", ".openmdao"))
    for name in ("eggsaver.dat", "fileanalyzer.dat"):
        path = os.path.join(base, name)
        if os.path.exists(path):
            os.remove(path)

    # Avoid having any user-defined resources causing problems during testing.
    os.environ["OPENMDAO_RAMFILE"] = ""

    if "--with-coverage" in args:
        args.append("--cover-erase")
        if "--all" in args and not covpkg:
            for pkg in tlist:
                opt = "--cover-package=%s" % pkg
                if opt not in args:
                    args.append(opt)

            # Better coverage if we clobber credential data.
            path = os.path.join(base, "keys")
            if os.path.exists(path):
                os.remove(path)

    # this tells it to enable the console in the environment so that
    # the logger will print output to stdout. This helps greatly when
    # debugging openmdao scripts running in separate processes.
    if "--enable_console" in args:
        args.remove("--enable_console")
        os.environ["OPENMDAO_ENABLE_CONSOLE"] = "1"

    if "--all" in args:
        args.remove("--all")
        args.extend(tlist)

    if "--plugins" in args:
        args.remove("--plugins")
        from openmdao.main.plugin import plugin_install, _get_plugin_parser

        argv = ["install", "--all"]
        parser = _get_plugin_parser()
        options, argz = parser.parse_known_args(argv)
        plugin_install(parser, options, argz)

    # The default action should be to run the GUI functional tests.
    # The 'win32' test here is to allow easily changing the default for Windows.
    if sys.platform == "win32":
        do_gui_tests = True
    else:
        do_gui_tests = True

    # run GUI functional tests, overriding default action
    if "--gui" in args:
        args.remove("--gui")
        do_gui_tests = True

    # skip GUI functional tests, overriding default action
    if "--skip-gui" in args:
        args.remove("--skip-gui")
        do_gui_tests = False

    if not do_gui_tests:
        os.environ["OPENMDAO_SKIP_GUI"] = "1"

    # some libs we use call multiprocessing.cpu_count() on import, which can
    # raise NotImplementedError, so try to monkeypatch it here to return 1 if
    # that's the case
    try:
        import multiprocessing

        multiprocessing.cpu_count()
    except ImportError:
        pass
    except NotImplementedError:
        multiprocessing.cpu_count = lambda: 1

    #    _trace_atexit()
    nose.run_exit(argv=args)
コード例 #19
0
def run_openmdao_suite(argv=None):
    """This function is exported as a script that is runnable as part of
    an OpenMDAO virtual environment as openmdao test.

    This function wraps nosetests, so any valid nose args should also
    work here.
    """
    if argv is None:
        argv = sys.argv

    #Add any default packages/directories to search for tests to tlist.
    tlist = _get_openmdao_packages()

    break_check = ['--help', '-h', '--all']

    covpkg = False  # if True, --cover-package was specified by the user

    # check for args not starting with '-'
    args = argv[:]
    for i, arg in enumerate(args):
        if arg.startswith('--cover-package'):
            covpkg = True
        if (i > 0 and not arg.startswith('-')) or arg in break_check:
            break
    else:
        args.append("--all")

    args.append('--exe')  # by default, nose will skip any .py files that are
                          # executable. --exe prevents this behavior

    # Clobber cached data in case Python environment has changed.
    base = os.path.expanduser(os.path.join('~', '.openmdao'))
    for name in ('eggsaver.dat', 'fileanalyzer.dat'):
        path = os.path.join(base, name)
        if os.path.exists(path):
            os.remove(path)

    # Avoid having any user-defined resources causing problems during testing.
    os.environ['OPENMDAO_RAMFILE'] = ''

    if '--with-coverage' in args:
        args.append('--cover-erase')
        if '--all' in args and not covpkg:
            for pkg in tlist:
                opt = '--cover-package=%s' % pkg
                if opt not in args:
                    args.append(opt)

            # Better coverage if we clobber credential data.
            path = os.path.join(base, 'keys')
            if os.path.exists(path):
                os.remove(path)

    # this tells it to enable the console in the environment so that
    # the logger will print output to stdout. This helps greatly when
    # debugging openmdao scripts running in separate processes.
    if '--enable_console' in args:
        args.remove('--enable_console')
        os.environ['OPENMDAO_ENABLE_CONSOLE'] = '1'

    if '--all' in args:
        args.remove('--all')
        args.extend(tlist)

    if '--plugins' in args:
        args.remove('--plugins')
        from openmdao.main.plugin import plugin_install, _get_plugin_parser
        argv = ['install', '--all']
        parser = _get_plugin_parser()
        options, argz = parser.parse_known_args(argv)
        plugin_install(parser, options, argz)

    # some libs we use call multiprocessing.cpu_count() on import, which can
    # raise NotImplementedError, so try to monkeypatch it here to return 1 if
    # that's the case
    try:
        import multiprocessing
        multiprocessing.cpu_count()
    except ImportError:
        pass
    except NotImplementedError:
        multiprocessing.cpu_count = lambda: 1

#    _trace_atexit()
    nose.run_exit(argv=args)
コード例 #20
0
    def test_basic(self):
        #Testing in pythonxy fails due to the pip version
        if sys.platform == 'win32':
          pipvers = pip.__version__
          if pipvers.__contains__("xy"):
             raise nose.SkipTest("PythonXY's pip name is non-standard 'pip-2.7xy' and causes test failure when 'pip-2.7' is searched for and not found.")

        logging.debug('')
        logging.debug('test_basic')

        # Just run through a complete cycle.
        orig_dir = os.getcwd()
        orig_stdout = sys.stdout
        orig_stderr = sys.stderr

        # Quickstart.
        logging.debug('')
        logging.debug('quickstart')
        os.chdir(self.tdir)
        try:
            argv = ['quickstart', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_quickstart(parser, options, args)
            self.assertEqual(retval, 0)
            fandd = find_files(self.tdir, showdirs=True)
            self.assertEqual(set([os.path.basename(f) for f in fandd]),
                             set(['foobar', 'src', 'docs', 'setup.cfg', 'setup.py',
                                  'MANIFEST.in', '__init__.py', 'conf.py',
                                  'usage.rst', 'index.rst',
                                  'srcdocs.rst', 'pkgdocs.rst', 'foobar.py',
                                  'README.txt', '_static',
                                  'test', 'test_foobar.py']))
        finally:
            os.chdir(orig_dir)

        # Makedist.
        logging.debug('')
        logging.debug('makedist')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        logdata = ''
        os.chdir(os.path.join(self.tdir, 'foobar'))
        try:
            argv = ['makedist']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_makedist(parser, options, args, capture='makedist.out')
            with open('makedist.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
            if sys.platform == 'win32':
                self.assertTrue(os.path.exists('foobar-0.1.zip'))
            else:
                self.assertTrue(os.path.exists('foobar-0.1.tar.gz'))
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        # Overwrite existing distribution.
        logging.debug('')
        logging.debug('makedist overwrite')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        os.chdir(os.path.join(self.tdir, 'foobar'))
        try:
            argv = ['makedist']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_makedist(parser, options, args, capture='makedist.out')
            with open('makedist.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        # Install
        logging.debug('')
        logging.debug('install')
        sys.stdout = cStringIO.StringIO()
        sys.stderr = cStringIO.StringIO()
        logdata = ''
        os.chdir(self.tdir)
        try:
            argv = ['install', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            retval = plugin_install(parser, options, args, capture='install.out')
            with open('install.out', 'r') as inp:
                logdata = inp.read()
            self.assertEqual(retval, 0)
        finally:
            captured_stdout = sys.stdout.getvalue()
            captured_stderr = sys.stderr.getvalue()
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            os.chdir(orig_dir)
            logging.debug('captured stdout:')
            logging.debug(captured_stdout)
            logging.debug('captured stderr:')
            logging.debug(captured_stderr)
            logging.debug('captured subprocess output:')
            logging.debug(logdata)

        try:
            # List in subprocess to grab updated package environment.
            logging.debug('')
            logging.debug('list')
            os.chdir(self.tdir)
            stdout = open('list.out', 'w')
            try:
                check_call(('plugin', 'list', '-g', 'driver', '-g', 'component',
                            '--external'), stdout=stdout, stderr=STDOUT)
            finally:
                stdout.close()
                with open('list.out', 'r') as inp:
                    captured_stdout = inp.read()
                os.remove('list.out')
                os.chdir(orig_dir)
                logging.debug('captured subprocess output:')
                logging.debug(captured_stdout)
            self.assertTrue('foobar.foobar.Foobar' in captured_stdout)

            # Docs.
            logging.debug('')
            logging.debug('docs')
            argv = ['docs', 'foobar']
            parser = _get_plugin_parser()
            options, args = parser.parse_known_args(argv)
            url = find_docs_url(options.plugin_dist_name)
            # Strip off the file protocol header
            url = url.replace('file://', '')
            expected = os.path.join(self.tdir, 'foobar', 'src', 'foobar',
                                    'sphinx_build', 'html', 'index.html')
            self.assertEqual(os.path.realpath(url), os.path.realpath(expected))
        finally:
            # Uninstall
            logging.debug('')
            logging.debug('uninstall')
            pip_in = os.path.join(self.tdir, 'pip.in')
            pip_out = os.path.join(self.tdir, 'pip.out')
            with open(pip_in, 'w') as out:
                out.write('y\n')
            stdin = open(pip_in, 'r')
            stdout = open(pip_out, 'w')
            # On EC2 Windows, 'pip' generates an absurdly long temp directory
            # name, apparently to allow backing-out of the uninstall.
            # The name is so long Windows can't handle it. So we try to
            # avoid that by indirectly influencing mkdtemp().
            env = os.environ.copy()
            env['TMP'] = os.path.expanduser('~')
            try:
                # the following few lines are to prevent the system level pip
                # from being used instead of the local virtualenv version.
                pipexe = 'pip'
                pipexe = find_in_path(pipexe)
                if pipexe is None:
                    pipexe = 'pip'
                check_call((pipexe, 'uninstall', 'foobar'), env=env,
                           stdin=stdin, stdout=stdout, stderr=STDOUT)
            finally:
                stdin.close()
                stdout.close()
                with open(pip_out, 'r') as inp:
                    captured_stdout = inp.read()
                logging.debug('captured stdout:')
                logging.debug(captured_stdout)

        # Show removed.
        logging.debug('')
        logging.debug('list removed')
        os.chdir(self.tdir)
        stdout = open('list.out', 'w')
        try:
            check_call(('plugin', 'list', '--external'),
                       stdout=stdout, stderr=STDOUT)
        finally:
            stdout.close()
            with open('list.out', 'r') as inp:
                captured_stdout = inp.read()
            os.remove('list.out')
            os.chdir(orig_dir)
            logging.debug('captured subprocess output:')
            logging.debug(captured_stdout)
        self.assertFalse('foobar.foobar.Foobar' in captured_stdout)