Exemple #1
0
    def test_run_event_as_function(self):
        events = {'>': function_events_callback}

        (data, exitstatus) = wexpect.run('cmd',
                                         withexitstatus=True,
                                         events=events,
                                         timeout=10)
        assert exitstatus == 0
    def test_constructor(self):
        '''This tests that the constructor will work and give
        the same results for different styles of invoking __init__().
        This assumes that the root directory / is static during the test.
        '''
        p1 = wexpect.spawn('uname -m -n -p -r -s -v')
        p1.expect(wexpect.EOF)
        p2 = wexpect.spawn('uname', ['-m', '-n', '-p', '-r', '-s', '-v'])
        p2.expect(wexpect.EOF)
        self.assertEqual(p1.before, p2.before)
        self.assertEqual(str(p1).splitlines()[1:9], str(p2).splitlines()[1:9])

        run_result = wexpect.run('uname -m -n -p -r -s -v')
        self.assertEqual(run_result, p2.before)
Exemple #3
0
    def test_run_event_as_string(self):
        re_flags = re.DOTALL | re.MULTILINE
        events = {
            # second match on 'abc', echo 'def'
            re.compile('abc.*>', re_flags):
            'echo "def"\r\n',
            # final match on 'def': exit
            re.compile('def.*>', re_flags):
            'exit\r\n',
            # first match on 'GO:' prompt, echo 'abc'
            re.compile('Microsoft.*>', re_flags):
            'echo "abc"\r\n'
        }

        (data, exitstatus) = wexpect.run('cmd',
                                         withexitstatus=True,
                                         events=events,
                                         timeout=5)
        assert exitstatus == 0
Exemple #4
0
import wexpect

child = wexpect.run("ssh [email protected] 'ls -l'",
                    events={'(?i)password': '******'})
print child
Exemple #5
0
 def test_run_event_typeerror(self):
     events = {'>': -1}
     with self.assertRaises(TypeError):
         wexpect.run('cmd', withexitstatus=True, events=events, timeout=10)
Exemple #6
0
def authenticator_code(steamctl, user):
    cmd = printcmd(f"{steamctl} authenticator code {user}")
    output, exitstatus = xexpect.run(cmd, withexitstatus=True)
    if (exitstatus):
        raise Exception("steamctl exitstatus: " + str(exitstatus))
    return strcast(output).strip()
Exemple #7
0
def authenticator_remove(steamctl, user):
    # Remove existing authenticator, if any
    cmd = printcmd(f"{steamctl} authenticator remove --force {user}")
    output, exitstatus = xexpect.run(cmd, withexitstatus=True)
    print(strcast(output))
Exemple #8
0
def verify_auth_remembered(steamctl):
    cmd = printcmd(f"{steamctl} depot info -a 238960")
    output, exitstatus = xexpect.run(cmd, withexitstatus=True)
    # print(strcast(output))
    if (exitstatus):
        raise Exception("steamctl exitstatus: " + str(exitstatus))
    print(strcast(child.after), end='')


def logexpect(child, *args, **kwargs):
    ret = child.expect(*args, **kwargs)
    logprompt(child)
    return ret


cwd = os.path.dirname(os.path.abspath(__file__))
child = xexpect.spawn("python input-getpass-cli.py", cwd=cwd)
logexpect(child, "Here is an input")
child.sendline("input abc123")
logexpect(child, "Your input: input abc123")

logexpect(child, "Here is a getpass")
logexpect(child, "Password:"******"password xyz098")
logexpect(child, "Goodbye")
exitcode = child.wait()
print()
print()
print('exit:', exitcode)

output2, exitcode2 = xexpect.run("python --version",
                                 cwd=cwd,
                                 withexitstatus=True)
print()
print(strcast(output2))
print('exit2:', exitcode2)