Skip to content

Commit

Permalink
Merge pull request giampaolo#608 from Infinidat/master
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
giampaolo committed Mar 15, 2015
2 parents 1a5e238 + 7308356 commit 241c6ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions psutil/_psutil_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args)
unsigned int len = sizeof(cpu_set_t);
long pid;
int i;
PyObject* py_retlist;
PyObject *py_cpu_num;
PyObject* py_retlist = NULL;
PyObject *py_cpu_num = NULL;

if (!PyArg_ParseTuple(args, "i", &pid))
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class Priority(enum.IntEnum):
pmmap_ext = namedtuple(
'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields))
ntpinfo = namedtuple(
'ntpinfo', ['num_handles', 'ctx_switches', 'user_time', 'kernel_time',
'create_time', 'num_threads', 'io_rcount', 'io_wcount',
'io_rbytes', 'io_wbytes'])
'ntpinfo', ['num_handles', 'ctx_switches', 'user_time', 'kernel_time',
'create_time', 'num_threads', 'io_rcount', 'io_wcount',
'io_rbytes', 'io_wbytes'])

# set later from __init__.py
NoSuchProcess = None
Expand Down
11 changes: 8 additions & 3 deletions test/_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ def test_process_name(self):
def test_process_create_time(self):
time_ps = ps("ps --no-headers -o start -p %s" % self.pid).split(' ')[0]
time_psutil = psutil.Process(self.pid).create_time()
if SUNOS:
time_psutil = round(time_psutil)
time_psutil_tstamp = datetime.datetime.fromtimestamp(
time_psutil).strftime("%H:%M:%S")
self.assertEqual(time_ps, time_psutil_tstamp)
# sometimes ps shows the time rounded up instead of down, so we check
# for both possible values
round_time_psutil = round(time_psutil)
round_time_psutil_tstamp = datetime.datetime.fromtimestamp(
round_time_psutil).strftime("%H:%M:%S")
self.assertIn(time_ps, [time_psutil_tstamp, round_time_psutil_tstamp])

def test_process_exe(self):
ps_pathname = ps("ps --no-headers -o command -p %s" %
Expand Down Expand Up @@ -218,6 +221,8 @@ def call(p, attr):
'send_signal', 'wait', 'children', 'as_dict']
if LINUX and get_kernel_version() < (2, 6, 36):
ignored_names.append('rlimit')
if LINUX and get_kernel_version() < (2, 6, 23):
ignored_names.append('num_ctx_switches')
for name in dir(psutil.Process):
if (name.startswith('_') or name in ignored_names):
continue
Expand Down
10 changes: 8 additions & 2 deletions test/test_psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@ def wait_for_file(fname, timeout=GLOBAL_TIMEOUT, delete_file=True):
try:
with open(fname, "r") as f:
data = f.read()
if not data:
continue
if delete_file:
os.remove(fname)
return data
except IOError:
time.sleep(0.001)
raise RuntimeError("timed out (couldn't create file)")
raise RuntimeError("timed out (couldn't read file)")


def reap_children(search_all=False):
Expand Down Expand Up @@ -710,6 +712,10 @@ def test_cpu_count(self):
self.assertEqual(logical, len(psutil.cpu_times(percpu=True)))
self.assertGreaterEqual(logical, 1)
#
with open("/proc/cpuinfo") as fd:
cpuinfo_data = fd.read()
if "physical id" not in cpuinfo_data:
raise unittest.SkipTest("cpuinfo doesn't include physical id")
physical = psutil.cpu_count(logical=False)
self.assertGreaterEqual(physical, 1)
self.assertGreaterEqual(logical, physical)
Expand Down Expand Up @@ -2495,9 +2501,9 @@ def test_(self):

def setUp(self):
safe_remove(TESTFN)
TestProcess.setUp(self)
os.setegid(1000)
os.seteuid(1000)
TestProcess.setUp(self)

def tearDown(self):
os.setegid(self.PROCESS_UID)
Expand Down

0 comments on commit 241c6ba

Please sign in to comment.