def test_unsuccessful_execute(self): cmd = ("ls", "/foo",) self.assertRaises(exc.ExecutionError, utils.execute, *cmd) exp = exc.ExecutionError(stderr='ls: /foo: No such file or directory\n', stdout='', return_code=1, cmd=str.join(" ", cmd)) try: utils.execute(*cmd) except exc.ExecutionError, e: self.assertEqual(str(e), str(exp))
def command(*cmd, **kwargs): split_char = kwargs.pop('split_char', "\n") res = str.split(utils.execute(*cmd, **kwargs).strip(), split_char) return res if len(res) > 1 else res[0]
def test_successful_execute(self): exp = [f[2] for f in os.walk("tests/data")][0] self.assertEqual(exp, str.split(utils.execute("ls", "tests/data")))