'Enumerate users from the wtmp file.'

def testEnumerateUsersLinux(self):

    if (platform.system() != 'Linux'):
        return
    path = os.path.join(self.base_path, 'VFSFixture/var/log/wtmp')
    old_open = __builtin__.open
    old_listdir = os.listdir
    def MockedOpen(requested_path, mode='rb'):
        if ('wtmp' in requested_path):
            self.assertEqual(requested_path, '/var/log/wtmp')
            return old_open(path)
        return old_open(requested_path, mode)
    __builtin__.open = MockedOpen
    os.listdir = (lambda x: ['wtmp'])
    try:
        results = self.RunAction(linux.EnumerateUsers)
    finally:
        __builtin__.open = old_open
        os.listdir = old_listdir
    found = 0
    for result in results:
        self.assertNotEqual('runlevel', result.username)
        if (result.username == 'user1'):
            found += 1
            self.assertEqual(result.last_logon, (1296552099 * 1000000))
        elif (result.username == 'user2'):
            found += 1
            self.assertEqual(result.last_logon, (1296552102 * 1000000))
        elif (result.username == 'user3'):
            found += 1
            self.assertEqual(result.last_logon, (1296569997 * 1000000))
    self.assertEqual(found, 3)
