Skip to content

Commit

Permalink
chore: test with Python 3.12 (#2270)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jul 31, 2023
1 parent 46b1006 commit fc85c02
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ jobs:
python-version: 3.11

- name: Create wheels + run tests
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.14.1
env:
CIBW_ARCHS: "${{ matrix.archs }}"
CIBW_PRERELEASE_PYTHONS: True

- name: Upload wheels
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ XXXX-XX-XX
instead of OverflowError. (patch by Xuehai Pan)
- 2268_: ``bytes2human()`` utility function was unable to properly represent
negative values.
- 2252_: [Windows]: `psutil.disk_usage`_ fails on Python 3.12+. (patch by Matthieu Darbois)

5.9.5
=====
Expand Down
29 changes: 25 additions & 4 deletions psutil/arch/windows/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ PyObject *
psutil_disk_usage(PyObject *self, PyObject *args) {
BOOL retval;
ULARGE_INTEGER _, total, free;

#if PY_MAJOR_VERSION <= 2
char *path;

if (PyArg_ParseTuple(args, "u", &path)) {
Expand All @@ -55,23 +57,42 @@ psutil_disk_usage(PyObject *self, PyObject *args) {

// on Python 2 we also want to accept plain strings other
// than Unicode
#if PY_MAJOR_VERSION <= 2
PyErr_Clear(); // drop the argument parsing error
if (PyArg_ParseTuple(args, "s", &path)) {
Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceEx(path, &_, &total, &free);
Py_END_ALLOW_THREADS
goto return_;
}
#endif

return NULL;

return_:
if (retval == 0)
return PyErr_SetFromWindowsErrWithFilename(0, path);
else
return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
#else
PyObject *py_path;
wchar_t *path;

if (!PyArg_ParseTuple(args, "U", &py_path)) {
return NULL;
}

path = PyUnicode_AsWideCharString(py_path, NULL);
if (path == NULL) {
return NULL;
}

Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceExW(path, &_, &total, &free);
Py_END_ALLOW_THREADS

PyMem_Free(path);

if (retval == 0)
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, 0, py_path);
#endif
return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
}


Expand Down
6 changes: 3 additions & 3 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,12 @@ def test_num_fds(self):
def test_num_ctx_switches(self):
p = psutil.Process()
before = sum(p.num_ctx_switches())
for _ in range(500000):
for _ in range(2):
time.sleep(0.05) # this shall ensure a context switch happens
after = sum(p.num_ctx_switches())
if after > before:
return
raise self.fail(
"num ctx switches still the same after 50.000 iterations")
raise self.fail("num ctx switches still the same after 2 iterations")

def test_ppid(self):
p = psutil.Process()
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_cpu_times(self):
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
self.assertEqual(total, sum(times))
self.assertAlmostEqual(total, sum(times))
str(times)
# CPU times are always supposed to increase over time
# or at least remain the same and that's because time
Expand Down Expand Up @@ -388,7 +388,7 @@ def test_per_cpu_times(self):
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
self.assertEqual(total, sum(times))
self.assertAlmostEqual(total, sum(times))
str(times)
self.assertEqual(len(psutil.cpu_times(percpu=True)[0]),
len(psutil.cpu_times(percpu=False)))
Expand Down

0 comments on commit fc85c02

Please sign in to comment.