'Tests for the PsCmdParser class.'

def testPsCmdParser(self):

    parser = linux_cmd_parser.PsCmdParser()
    content = open(os.path.join(self.base_path, 'pscmd.out'), 'rb').read()
    args = ['h', '-ewwo', 'pid,ppid,comm,ruid,uid,suid,rgid,gid,sgid,user,tty,stat,nice,thcount,pcpu,rss,vsz,pmem,cmd']
    processes = list(parser.Parse('/bin/ps', args, content, '', 0, 5, None))
    self.assertEqual(5, len(processes))
    process = None
    for process in processes:
        self.assertTrue(isinstance(process, rdf_client.Process))
    self.assertEquals(136095, process.pid)
    self.assertEquals('ps', process.name)
    self.assertEquals(27262, process.effective_uid)
    self.assertEquals('usernam', process.username)
    self.assertEquals('pts/0', process.terminal)
    self.assertEquals(0.0, process.user_cpu_time)
    self.assertEquals(920, process.RSS_size)
    args.insert(0, 'ps')
    self.assertEquals(args, process.cmdline)
    content = open(os.path.join(self.base_path, 'psefcmd.out'), 'rb').read()
    args = ['-ef']
    processes = list(parser.Parse('/bin/ps', args, content, '', 0, 5, None))
    self.assertEqual(6, len(processes))
    process = None
    for process in processes:
        self.assertTrue(isinstance(process, rdf_client.Process))
    self.assertEquals(337492, process.pid)
    self.assertEquals(592357, process.ppid)
    self.assertEquals('ps', process.name)
    self.assertEquals('usernam', process.username)
    self.assertEquals('pts/0', process.terminal)
    self.assertEquals(0.0, process.cpu_percent)
    args.insert(0, 'ps')
    self.assertEquals(args, process.cmdline)
