def test_vv_implies_nocapture(self): task = Task() cmd = task.command( prego_cmd % '-vv test/fixtures/output.py:OutputFixture.test_print_text') task.assert_that(cmd.stdout.content, contains_string('OutputFixture printed this'))
def test_for(self): task = Task() for i, retcode in [(0, 2), (1, 0), (2, 2)]: task.command('ls -%s' % i, cwd='/tmp', expected=retcode, timeout=None)
def test_set_read_var(self): init() context.port = 2030 task = Task() cmd = task.command('echo $port') task.assert_that(cmd.stdout.content, contains_string('2030')) commit()
def test_default_timeout(self): init() context.timeout = 3 task = Task() task.command('true') commit() self.assertEquals(task.lastcmd.timeout, 3)
def test_default_signal(self): init() context.signal = signal.SIGINT task = Task() cmd = task.command('sleep 5', timeout=1) try: commit() self.fail() except TestFailed: self.assertEquals(cmd.returncode, -signal.SIGINT)
def test_show_log_on_fail_command(self): task = Task(desc='fail') cmd = task.command(nose + 'examples/examples.py:Test.test_cmd_false_true', expected=1) strings = [ "TestFailed: assert that command A.0 expected returncode 0, but was 1", ">> begin captured logging <<", "[FAIL] A Task end - elapsed:" ] for s in strings: task.assert_that(cmd.stderr.content, contains_string(s))
def test_keep_going_off(self): task = Task() cmd = task.command( prego_cmd % 'examples/examples.py:Test.test_cmd_wrong_true_and_ls', expected=1) strings = [ "[ ok ] A.0 Command 'wrong' code (0:127)", "assert that command A.0 expected returncode 0, but was 127", "[ -- ] A.3 Command 'true'", "[ -- ] A.5 assert that command A.3 returncode 0", ] for s in strings: task.assert_that(cmd.stderr.content, contains_string(s))
def test_print_outs_on_fail(self): task = Task() task.command(prego_cmd % '-peo examples/examples.py:Test.test_cmd_fail_with_outs', expected=1) task.assert_that(task.lastcmd.stderr.content, contains_string("A.0.out| STDOUT")) task.assert_that(task.lastcmd.stderr.content, contains_string("A.3.err| STDERR"))
def test_escape_linebreaks_on_log(self): task = Task() task.command( prego_cmd % '-v test/integration/cases.py:multiline_commands.test_writing_out') task.assert_that(task.lastcmd.stderr.content, contains_string("hi\\nbye\\nagain"))
def test_env(self): init() context.env = {'PREGO_SAMPLE': 'hello'} task = Task() task.command('echo $PREGO_SAMPLE') task.assert_that(task.lastcmd.stdout.content, contains_string('hello')) commit()
def test_default_cwd(self): init() context.cwd = '/tmp' task = Task() task.command('pwd') task.assert_that(task.lastcmd.stdout.content, contains_string('/tmp')) commit()
def test_default_env(self): init() context.env = {'MY_ENV_VAR': '42'} task = Task() task.command('echo $MY_ENV_VAR') task.assert_that(task.lastcmd.stdout.content, contains_string('42')) commit()
def test_old_config(self): ripio = Task() ripio.command( 'bin/ripio --config test/fixtures/deprecated.conf create gh:ripio-test/foo', expected=1) ripio.assert_that( ripio.lastcmd.stdout.content, hamcrest.contains_string('AccessDenied: github:ripio-test/foo'))
def test_bitbucket_private_no_creds(self): ripio = Task() ripio.command( 'bin/ripio --config /dev/null clone bb:ripio-test/private', expected=1, timeout=10) ripio.assert_that(ripio.lastcmd.stdout.content, hamcrest.contains_string('AccessDenied'))
def run_server(self, prog): server = Task(detach=True) server.assert_that(localhost, is_not(listen_port(context.port, proto='udp'))) server.command('./{0} $port'.format(prog), timeout=15, expected=None) clients = self.run_clients() wait_clients(clients)
def run_server(self, prog): server = Task('server', detach=True) server.assert_that(localhost, is_not(listen_port(context.port, proto='tcp'))) server.command("./{0} $port".format(prog), expected=None) clients = self.run_clients() wait_clients(clients)
def run_clients(self): Task().wait_that(localhost, listen_port(context.port, proto='tcp')) clients = [] for i in range(10): req = 'hello-%s' % i client = Task('client', detach=True) client.command('echo %s | ./TCP_client.py localhost $port' % req) client.assert_that(client.lastcmd.stdout.content, contains_string("Reply is '" + req.upper())) clients.append(client) return clients
def test_help(self): for fname in glob.glob('*.py'): if 'stress' in fname or 'client' in fname: continue app = Task() app.command('./{}'.format(fname), expected=1) app.assert_that( app.lastcmd.stdout.content, contains_string('Usage: ./{} <port>'.format(fname)))
def test_github_private_no_creds(self): ripio = Task() ripio.command( 'bin/ripio --config /dev/null clone gh:ripio-test/private', expected=1, timeout=10) ripio.assert_that( ripio.lastcmd.stdout.content, hamcrest.contains_string( 'RepositoryNotFound: github:ripio-test/private'))
def test_no_detach_no_timeout(self): task = Task(detach=True) cmd = task.command( prego_cmd % '-v test/integration/advices.py:Timeout.test_no_detach_no_timeout', expected=None) task.wait_that( cmd.stderr.content, contains_string( "A.0 No timeout command in a non detached task could block forever!" )) Task().delay()
def run_with_config(self, mode, browser=None): write_config_file(mode, browser) server = Task(detach=True) server.command('python -m SimpleHTTPServer 8000', expected=-15, timeout=None) tester = Task() tester.wait_that(localhost, listen_port(8000)) tester.command('nosetests -v test/tests.py', timeout=60) Task().command('killall chromedriver', expected=None, timeout=None) return tester
def test_writing_out(self): task = Task() task.command('echo -e "hi\nbye\nagain"')
def test_writing_err(self): task = Task() task.command('echo -e "hi\nbye\nagain" >&2')
def test_client_server(self): context.cwd = '$testdir' servertask = Task('server', detach=True) server = servertask.command('%s Server --Ice.Config=Server.config' % java, signal=2, expected=130) servertask.assert_that(server.stdout.content, contains_string('Hello World!')) clientside = Task('client') clientside.wait_that(server, running()) clientside.wait_that(server.stdout.content, contains_string('printer1')) clientside.command('%s Client "$(head -1 %s)"' % (java, server.stdout.path))
def test_factorial(self): Task().command('make clean all') server = Task('server', detach=True) server.command('./factorial_server', expected=-15) client = Task('client') client.assert_that(server, running()) client.command('./factorial_client localhost 8') client.assert_that(client.lastcmd.stdout.content, hamcrest.contains_string('factorial(8): 40320'))
def test_pre_post(self): task = Task() task.assert_that(Variable('SHELL'), exists()) task.assert_that(File('/etc/fstab'), exists()) task.command('cp /etc/fstab /tmp/') task.generate_files('/tmp/fstab') task.command('ls / > /tmp/kk') # shell=True) task.generate_files('/tmp/kk') task.assert_that( File('/tmp/kk').content, all_of(contains_string('sbin'), contains_string('home'), contains_string('boot')))
def test_make_printer(self): client = Task() client.command('./client.py --Ice.Config=locator.config factory', cwd='icegrid-factory')
def make_client_server(self, client, server): servertask = Task('server', detach=True) server = servertask.command('{} --Ice.Config=Server.config'.format(server), cwd='$testdir', signal=2) servertask.assert_that(server.stdout.content, contains_string('Hello World!')) clientside = Task('client') clientside.wait_that(server, running()) clientside.wait_that(server.stdout.content, contains_string('printer1')) clientside.command('{} "$(head -1 {})"'.format(client, server.stdout.path), cwd='$testdir')
def start_selenium_server(self): Se = Task(detach=True) Se.command('java -jar selenium-server-standalone-2.31.0.jar', expected=143, timeout=None) Task().wait_that(localhost, listen_port(4444))
def test_noauto_log_stderr_when_stderr_flag(self): task = Task() cmd = task.command(prego_cmd % '-ve examples/command-outs.py:OK.test_ls_stderr') task.assert_that(cmd.stderr.content, contains_string('A.0.err| /etc/passwd'))
def test_netcat(self): ctx.port = 2000 server = Task(desc='netcat server', detach=True) server.assert_that(Package('nmap'), installed()) server.assert_that(localhost, hamcrest.is_not(listen_port(ctx.port))) cmd = server.command('ncat -l -p $port') server.assert_that(cmd.stdout.content, hamcrest.contains_string('bye')) client = Task(desc='netcat client') client.wait_that(server, running()) client.wait_that(localhost, listen_port(ctx.port)) client.command('ncat -c "echo bye" localhost $port')
def test_auto_log_stdout(self): task = Task() cmd = task.command( prego_cmd % '-vo examples/command-outs.py:OK.test_ls_stdout_auto') task.assert_that(cmd.stderr.content, contains_string('A.0.out| /etc/passwd'))