コード例 #1
0
ファイル: test_env.py プロジェクト: jkeyes/enver
def test_help_env_parser():
    # test running the parser from the command line with system
    # arguments and environment variables

    sys.argv = ['', 'help']

    stdout = sys.stdout  # save stdout
    sys.stdout = StringIO()  # redirect stdout

    # run the parser
    enver.run(Env())

    # check the output
    output = sys.stdout.getvalue()
    ok_('VAR_1: Variable 1 Help' in output)
    ok_('VAR_2: Variable 2 Help' in output)

    # reset sys.stdout
    sys.stdout = stdout
コード例 #2
0
ファイル: test_env.py プロジェクト: jkeyes/enver
def test_dump_env_parser():
    # test running the parser from the command line with system
    # arguments and environment variables

    sys.argv = ['', 'dump']

    stdout = sys.stdout  # save stdout
    sys.stdout = StringIO()  # redirect stdout

    # run the parser
    enver.run(Env())

    # no environment variables means nothing set
    output = sys.stdout.getvalue()
    ok_('VAR_1=__NOT SET__' in output)
    ok_('VAR_2=__NOT SET__' in output)

    # reset the output buffer
    sys.stdout.truncate(0)

    # set an environment variable
    os.environ['VAR_2'] = '123'
    try:
        # run the parser
        enver.run(Env())

        # one of the environment variables is set
        output = sys.stdout.getvalue()
        ok_('VAR_1=__NOT SET__' in output)
        ok_('VAR_2=123' in output)
    finally:
        # clean up the environment
        del os.environ['VAR_2']

    # reset sys.stdout
    sys.stdout = stdout