self.assertRaises((ValueError, OverflowError), posix.makedev, x, minor)
self.assertRaises((ValueError, OverflowError), posix.makedev, major, x)
- if sys.platform == 'linux' and not support.linked_to_musl():
- NODEV = -1
+ # The following tests are needed to test functions accepting or
+ # returning the special value NODEV (if it is defined). major(), minor()
+ # and makefile() are the only easily reproducible examples, but that
+ # behavior is platform specific -- on some platforms their code has
+ # a special case for NODEV, on others this is just an implementation
+ # artifact.
+ if (hasattr(posix, 'NODEV') and
+ sys.platform.startswith(('linux', 'macos', 'freebsd', 'dragonfly',
+ 'sunos'))):
+ NODEV = posix.NODEV
self.assertEqual(posix.major(NODEV), NODEV)
self.assertEqual(posix.minor(NODEV), NODEV)
self.assertEqual(posix.makedev(NODEV, NODEV), NODEV)
+ def test_nodev(self):
+ # NODEV is not a part of Posix, but is defined on many systems.
+ if (not hasattr(posix, 'NODEV')
+ and (not sys.platform.startswith(('linux', 'macos', 'freebsd',
+ 'dragonfly', 'netbsd', 'openbsd',
+ 'sunos'))
+ or support.linked_to_musl())):
+ self.skipTest('not defined on this platform')
+ self.assertHasAttr(posix, 'NODEV')
+
def _test_all_chown_common(self, chown_func, first_param, stat_func):
"""Common code for chown, fchown and lchown tests."""
def check_stat(uid, gid):
#endif
#endif /* HAVE_EVENTFD && EFD_CLOEXEC */
+#ifdef NODEV
+ if (PyModule_Add(m, "NODEV", _PyLong_FromDev(NODEV))) return -1;
+#endif
+
#if defined(__APPLE__)
if (PyModule_AddIntConstant(m, "_COPYFILE_DATA", COPYFILE_DATA)) return -1;
if (PyModule_AddIntConstant(m, "_COPYFILE_STAT", COPYFILE_STAT)) return -1;