mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-35022: unittest.mock.MagicMock now also supports __fspath__ (GH-9960)
The MagicMock class supports many magic methods, but not __fspath__. To ease testing with modules such as os.path, this function is now supported by default.
This commit is contained in:
parent
1770d1c512
commit
6c83d9f4a7
4 changed files with 18 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue