Пример #1
0
 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()
Пример #2
0
 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()
Пример #3
0
    def test_fail_by_timeout(self):
        prego.init()
        task = prego.Task()
        task.command('sleep 2', timeout=1, expected=None)
        task.run()

        self.assertEquals(Status.FAIL, task.status)
Пример #4
0
 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()
Пример #5
0
 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()
Пример #6
0
 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()
Пример #7
0
 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()
Пример #8
0
    def test_fail(self):
        prego.init()
        task = prego.Task()
        task.command("false")
        task.run()

        self.assertEquals(Status.FAIL, task.status)
Пример #9
0
    def test_ls_ok(self):
        prego.init()
        task = prego.Task()
        task.command('ls')
        task.run()

        self.assertEquals(Status.OK, task.status)
Пример #10
0
    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)
Пример #11
0
    def test_default_timeout(self):
        init()
        context.timeout = 3
        task = Task()
        task.command('true')

        commit()
        self.assertEquals(task.lastcmd.timeout, 3)
Пример #12
0
    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()
Пример #13
0
 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()
Пример #14
0
    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()
Пример #15
0
 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()
Пример #16
0
    def test_logging_output(self):
        prego.init()
        task = prego.Task()
        cmd = task.command('python test/utils/log.py hi')
        task.assert_that(cmd.stderr.content, hamcrest.contains_string('hi'))
        task.run()

        self.assertIn('hi', cmd.stderr.read())
        self.assertEquals(Status.OK, task.status)
Пример #17
0
    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)
Пример #18
0
    def test_stdout_was_closed(self):
        prego.init()
        out = BytesIO()
        out.name = "bytes-io"

        task = prego.Task()
        task.command(u'echo hi', stdout=out)
        task.run()

        self.assert_(out.closed)
Пример #19
0
    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)
Пример #20
0
    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()
Пример #21
0
    def test_stdout_with_bytesio(self):
        class FakeFile:
            closed = False

            def __init__(self):
                self.buff = bytes()

            def write(self, data):
                self.buff += data

        prego.init()
        out = FakeFile()
        out.name = "bytes-io"

        task = prego.Task()
        task.command('echo hi', stdout=out)
        task.run()

        self.assertIn(b'hi', out.buff)
Пример #22
0
    def test_stdout_with_filename(self):
        prego.init()
        fname = '/tmp/task-out'

        try:
            os.remove(fname)
        except OSError:
            pass

        task = prego.Task()
        task.command("echo hi", stdout=fname)
        task.assert_that(
            prego.File('/tmp/task-out').content,
            hamcrest.contains_string('hi'))

        task.run()

        content = open(fname).read()

        self.assert_(os.path.exists(fname))
        self.assertIn('hi', content)
Пример #23
0
 def test_file_exists_in_cwd(self):
     prego.init()
     t = prego.Task()
     t.assert_that(prego.File('test/$testfilename'), prego.exists())
     prego.commit()
Пример #24
0
 def test_fail_cmd(self):
     prego.init()
     test = prego.Task()
     test.command('false')
     prego.commit()
Пример #25
0
 def test_2_cmds(self):
     prego.init()
     task = prego.Task()
     task.command('true')
     task.command('ls')
     prego.commit()
Пример #26
0
 def test_meet_default_timeout(self):
     prego.init()
     task = prego.Task()
     task.command('sleep 2')
     prego.commit()
Пример #27
0
    def test_no_commands_is_ok(self):
        prego.init()
        task = prego.Task()
        task.run()

        self.assertEquals(Status.OK, task.status)
Пример #28
0
 def test_zero_tasks_is_ok(self):
     prego.init()
     prego.commit()
     self.assertEquals(0, len(gvars.tasks))
Пример #29
0
 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()
Пример #30
0
 def test_init(self):
     prego.init()
     prego.Task().command('true')
     prego.init()
     self.assertEquals(0, len(gvars.tasks))