#!/usr/bin/env python # encoding: utf-8 import pexpect.pexpect as pexpect import os import sys from pdb import set_trace as debug pexpect.run('rm /var/lib/sqlite3/portalDB/upload.neurovigil.db') child=pexpect.spawn('./manage.py syncdb') child.expect('yes/no') child.sendline("yes") child.expect(": ") child.sendline("lee") child.expect("address:") child.sendline('*****@*****.**') child.expect("Password:"******"staticmouseveganlight") child.expect("again\):") child.sendline("staticmouseveganlight") print child.read() PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.dirname(PROJECT_DIR)) os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' os.environ['PYTHONPATH'] = PROJECT_DIR from django.contrib.auth.models import User #from upload.models import *
def create_expect(self): kwargs = {} if self.timeout is not None: kwargs['timeout'] = self.timeout self.ex = pexpect.spawn(self.cmd, self.args, **kwargs) if self.debug: self.logfile = os.tmpfile() self.ex.logfile_read = self.logfile if not hasattr(self.ex, 'ret'): def ret(self, value): self.ret_value = value self.ex.ret_value = None self.ex.ret = types.MethodType(ret, self.ex) if not hasattr(self.ex, 'expect_ex'): def expect_ex(self, opts): wait_and_send_patterns, wait_and_send_cmds = zip(*opts[:-1]) wait_and_send_patterns = list(wait_and_send_patterns) end_pattern = opts[-1] if not isinstance(end_pattern, basestring): end_pattern = end_pattern[0] wait_and_send_patterns.insert(0, end_pattern) while True: index = self.expect(wait_and_send_patterns) if index == 0: break else: self.sendline(wait_and_send_cmds[index - 1]) self.ex.expect_ex = types.MethodType(expect_ex, self.ex) if not hasattr(self.ex, 'linesep'): self.ex.linesep = self.linesep def sendline(self, s=''): n = self.send(s) n = n + self.send(self.linesep) return n self.ex.sendline = types.MethodType(sendline, self.ex)
def run_one_test(self, testname): testdir = os.path.join('tests', testname) testbuilddir = os.path.join('build', testname) templatedir = os.path.join('pistachio', 'user', 'apps', 'nest_template') nestdir = os.path.join('pistachio', 'user', 'apps', 'nest') # Prepare test directory and create library. if os.path.exists(testbuilddir): shutil.rmtree(testbuilddir) os.mkdir(testbuilddir) # Copy all test files into build dir for pathname in glob.glob('%s/*' % (testdir)): destpath = os.path.join(testbuilddir, os.path.basename(pathname)) shutil.copyfile(pathname, destpath) # Build 'libnest_extras.a' self.nest_extras_build(testbuilddir) # Copy 'libnest_extras.a' to Pistachio build dir. nest_extras_src = os.path.join(testbuilddir, 'libnest_extras.a') nest_extras_dst = os.path.join('build', 'user', 'lib', 'libnest_extras.a') shutil.copyfile(nest_extras_src, nest_extras_dst) # Build Pistachio userland with new files self.pistachio_rebuild_user() # Create a boot disk boot_pathname = self.bootdisk_create() # Import a test-specific script if necessary. imp_info = imp.find_module('expect', [testdir]) testmodule = imp.load_module('expect', *imp_info) # Test the system cmdline = QEMU_CMD % (boot_pathname) child = pexpect.spawn(cmdline) # ... and use the test-specific script as well: testmodule.test(child)
def run_one_test(self, testname): testdir = os.path.join("tests", testname) testbuilddir = os.path.join("build", testname) templatedir = os.path.join("pistachio", "user", "apps", "nest_template") nestdir = os.path.join("pistachio", "user", "apps", "nest") # Prepare test directory and create library. if os.path.exists(testbuilddir): shutil.rmtree(testbuilddir) os.mkdir(testbuilddir) # Copy all test files into build dir for pathname in glob.glob("%s/*" % (testdir)): destpath = os.path.join(testbuilddir, os.path.basename(pathname)) shutil.copyfile(pathname, destpath) # Build 'libnest_extras.a' self.nest_extras_build(testbuilddir) # Copy 'libnest_extras.a' to Pistachio build dir. nest_extras_src = os.path.join(testbuilddir, "libnest_extras.a") nest_extras_dst = os.path.join("build", "user", "lib", "libnest_extras.a") shutil.copyfile(nest_extras_src, nest_extras_dst) # Build Pistachio userland with new files self.pistachio_rebuild_user() # Create a boot disk boot_pathname = self.bootdisk_create() # Import a test-specific script if necessary. imp_info = imp.find_module("expect", [testdir]) testmodule = imp.load_module("expect", *imp_info) # Test the system cmdline = QEMU_CMD % (boot_pathname) child = pexpect.spawn(cmdline) # ... and use the test-specific script as well: testmodule.test(child)