import osgtest.library.core as core
import osgtest.library.osgunittest as osgunittest
import pprint
import errno

class TestGridProxyInit(osgunittest.OSGTestCase):

    def test_00_list_proxies(self):
        command = ('ls', '-lF', '/tmp/x509up_u*')
        status, stdout, _ = core.system(command, 'List proxies')
        core.log_message(stdout)

    def test_01_grid_proxy_init(self):
        core.state['proxy.created'] = False
        core.skip_ok_unless_installed('globus-proxy-utils')
        command = ('grid-proxy-init', '-debug')
        password = core.options.password + '\n'
        try:
            core.check_system(command, 'Run grid-proxy-init', user=True,
                              stdin=password)
        except OSError, e:
            attributes = {}
            for x in dir(e):
                attributes[x] = getattr(e,x, None)
            core.log_message(pprint.pformat(attributes))
            raise
        core.state['proxy.created'] = True

    def test_02_grid_proxy_info(self):
        core.skip_ok_unless_installed('globus-proxy-utils')
        self.skip_bad_unless(core.state['proxy.created'], 'missing proxy')
        command = ('grid-proxy-info', '-debug')
        core.check_system(command, 'Run grid-proxy-info', user=True)

import osgtest.library.core as core
import osgtest.library.osgunittest as osgunittest

class TestGridProxyInit(osgunittest.OSGTestCase):

    def test_01_remove_proxy(self):
        core.skip_ok_unless_installed('globus-proxy-utils')
        # If there is no pre-existing proxy file, the following command will
        # produce error output and have exit status 1; because this is the
        # expected (but not the only valid) case, do not check the output or
        # exit status.  This test exists only to clear out a pre-existing proxy.
        command = ('grid-proxy-destroy', '-debug')
        core.system(command, user=True)

    def test_02_grid_proxy_init_no_password(self):
        core.skip_ok_unless_installed('globus-proxy-utils')
        command = ('grid-proxy-init', '-debug')
        exit_status, _, _ = core.system(command, user=True)
        if exit_status == 0:
            core.system(('grid-proxy-destroy',), user=True)
            self.fail('grid-proxy-init succeeded with no password')

    def test_03_grid_proxy_init(self):
        core.state['proxy.created'] = False
        core.skip_ok_unless_installed('globus-proxy-utils')
        command = ('grid-proxy-init', '-debug')
        password = core.options.password + '\n'
        core.check_system(command, 'Normal grid-proxy-init', user=True, stdin=password)
        core.state['proxy.created'] = True

    def test_04_grid_proxy_info(self):
        core.skip_ok_unless_installed('globus-proxy-utils')
        self.skip_bad_unless(core.state['proxy.created'], 'Proxy creation failed')
        command = ('grid-proxy-info', '-debug')
        core.check_system(command, 'Normal grid-proxy-info', user=True)

Extend the grid-proxy-init tests to destroy a pre-existing proxy first, then test for failure without a password. Tidied up a bit.