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_non_exising_file_contains(self): prego.init() t = prego.Task() t.assert_that( prego.File('/tmp/kk').content, hamcrest.is_not(hamcrest.contains_string('SOMETHING'))) prego.commit()
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_cmd_fail_with_outs(self): prego.init() task = prego.Task() task.command('echo STDOUT') task.command('echo STDERR >&2') task.command('false') prego.commit()
def test_file_contains(self): open('/tmp/prego-content', 'wt').write('this a sample file for prego') prego.init() t = prego.Task() t.assert_that( prego.File('/tmp/prego-content').content, hamcrest.contains_string('sample file')) prego.commit()
def test_default_timeout(self): init() context.timeout = 3 task = Task() task.command('true') commit() self.assertEquals(task.lastcmd.timeout, 3)
def test_ok(self): prego.init() task = prego.Task() cmd = task.command('echo hi') task.assert_that(cmd, prego.exits_with(0)) prego.commit() self.assertEquals(Status.OK, task.status)
def test_file_compare(self): prego.init() a = prego.File('/etc/passwd') b = prego.File('/etc/fstab') t = prego.Task() t.assert_that(a, hamcrest.is_not(b)) prego.commit()
def test_cmd_wrong_true_and_ls(self): prego.init() task = prego.Task() task.command('wrong') task.command('true') task2 = prego.Task() task2.command('ls') prego.commit()
def test_file_permissions(self): prego.init() t = prego.Task() t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o644)) t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o200)) t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o400)) t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o440)) t.assert_that(prego.File('/etc/fstab'), prego.has_permissions(0o004)) prego.commit()
def test_task_is_killed_by_specified_signal(self): prego.init() task = prego.Task() cmd = task.command('sleep 5', signal=SIGINT, timeout=1) try: prego.commit() self.fail() except prego.TestFailed: self.assertEquals(cmd.returncode, -SIGINT)
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_file_compare2(self): with open('/tmp/a', 'w') as fd: fd.write("foobar") with open('/tmp/b', 'w') as fd: fd.write("foobar") prego.init() t = prego.Task() t.assert_that(prego.File('/tmp/a'), hamcrest.is_(prego.File('/tmp/b'))) prego.commit()
def test_err_contains_explicit_filename(self): prego.init() task = prego.Task() cmd = task.command('echo hi >&2', stderr='/tmp/somename.err') task.assert_that(cmd.stderr.content, hamcrest.contains_string('hi')) prego.commit()
def test_z_read_missing(self): init() task = Task() cmd = task.command('echo $port') task.assert_that(cmd.stdout.content, is_not(contains_string('2030'))) commit()
def test_file_exists_in_cwd(self): prego.init() t = prego.Task() t.assert_that(prego.File('test/$testfilename'), prego.exists()) prego.commit()
def test_fail_cmd(self): prego.init() test = prego.Task() test.command('false') prego.commit()
def test_2_cmds(self): prego.init() task = prego.Task() task.command('true') task.command('ls') prego.commit()
def test_meet_default_timeout(self): prego.init() task = prego.Task() task.command('sleep 2') prego.commit()
def test_zero_tasks_is_ok(self): prego.init() prego.commit() self.assertEquals(0, len(gvars.tasks))
def test_out_contains__explicit_filename(self): prego.init() task = prego.Task() cmd = task.command('echo hi', stdout='/tmp/somename.out') task.assert_that(cmd.stdout.content, hamcrest.contains_string('hi')) prego.commit()
def test_cmd_false_true(self): prego.init() task = prego.Task() task.command('false') task.command('true') prego.commit()
def test_out_contains__AUTO(self): prego.init() task = prego.Task() cmd = task.command('echo hi', stdout=prego.AUTO) task.assert_that(cmd.stdout.content, hamcrest.contains_string('hi')) prego.commit()
def test_file_compare_fail(self): prego.init() t = prego.Task() t.assert_that(prego.File('/etc/fstab'), hamcrest.is_not(prego.File('/etc/passwd'))) prego.commit()
def test_err_contains__implicit(self): prego.init() task = prego.Task() cmd = task.command('echo hi >&2') task.assert_that(cmd.stderr.content, hamcrest.contains_string('hi')) prego.commit()