summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py2
-rw-r--r--Lib/unittest/test/testmock/testmagicmethods.py10
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 6b7f293..1a6c1a6 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1713,6 +1713,7 @@ magic_methods = (
"complex int float index "
"round trunc floor ceil "
"bool next "
+ "fspath "
)
numerics = (
@@ -1760,6 +1761,7 @@ _calculate_return_value = {
'__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 = {
diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py
index 5ab9597..69dfe60 100644
--- a/Lib/unittest/test/testmock/testmagicmethods.py
+++ b/Lib/unittest/test/testmock/testmagicmethods.py
@@ -1,5 +1,6 @@
import math
import unittest
+import os
import sys
from unittest.mock import Mock, MagicMock, _magics
@@ -293,6 +294,15 @@ class TestMockingMagicMethods(unittest.TestCase):
# 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):