def test_command_does_not_exist(self): """Check that CommandDoesNotExist works properly""" cmd_name = "test_{}".format(time.time()) with self.assertRaises(exceptions.CommandDoesNotExist) as context: cmd = Command(cmd_name) raise exceptions.CommandDoesNotExist(cmd) self.assertEqual(str(context.exception), 'Command "{}" does not exist'.format(cmd_name))
def test_command_properties(self): """Check all command properties""" cmd_name = 'ls' args = ('-l', '/tmp') cmd = Command(cmd_name)(*args) self.assertEqual(cmd.command, cmd_name) self.assertEqual(cmd.arguments, ' '.join(args))
def __getattr__(cls, item): """Returns either own field or shell command object""" # NOTE(albartash): The next check ensures we wouldn't have troubles # in getting own fields even if forgetting to define # a related property for that. if item in cls.__own_fields__: return cls.__dict__[item] cls._last_command = Command(item) return cls._last_command
def test_command_base_representation(self): """Check command general representation""" args = ('-l', '-a', '/tmp') command = Command('ls')(*args) self.assertEqual(repr(command), ' '.join((command.command, ) + args))
def test_string_representation(self): """Check command string representation""" value = str(time.time()) cmd = 'echo' command = Command(cmd)(value) self.assertEqual(str(command), "{} {}".format(cmd, value))
def test_command_output(self): """Check command output property""" value = str(time.time()) command = Command('echo')(value) output = decode_stream(command.output) self.assertEqual(output, "{}\n".format(value))
def test_non_existing_command(self): """Check when command does not exist""" with self.assertRaises(CommandDoesNotExist): Command('random_{}'.format(time.time()))()
def test_existing_command(self): """Check that existing command runs correctly""" command = Command('ls') command(self.tmp_folder) self.assertEqual(command.return_code, 0)