* Descriptor methods: ``__get__``, ``__set__`` and ``__delete__``
* Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``,
``__getnewargs__``, ``__getstate__`` and ``__setstate__``
+* File system path representation: ``__fspath__``
+
+.. versionchanged:: 3.8
+ Added support for :func:`os.PathLike.__fspath__`.
The following methods exist but are *not* supported as they are either in use
"complex int float index "
"round trunc floor ceil "
"bool next "
+ "fspath "
)
numerics = (
'__hash__': lambda self: object.__hash__(self),
'__str__': lambda self: object.__str__(self),
'__sizeof__': lambda self: object.__sizeof__(self),
+ '__fspath__': lambda self: f"{type(self).__name__}/{self._extract_mock_name()}/{id(self)}",
}
_return_values = {
import math
import unittest
+import os
import sys
from unittest.mock import Mock, MagicMock, _magics
# how to test __sizeof__ ?
+ def test_magic_methods_fspath(self):
+ mock = MagicMock()
+ expected_path = mock.__fspath__()
+ mock.reset_mock()
+
+ self.assertEqual(os.fspath(mock), expected_path)
+ mock.__fspath__.assert_called_once()
+
+
def test_magic_methods_and_spec(self):
class Iterable(object):
def __iter__(self):
--- /dev/null
+:class:`unittest.mock.MagicMock` now supports the ``__fspath__`` method
+(from :class:`os.PathLike`).