diff options
author | Max BeĢlanger <aeromax@gmail.com> | 2018-10-25 14:48:58 -0700 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-04-30 08:39:55 +0100 |
commit | 55971296dc33650318a6397b21d4c4296a8dbca1 (patch) | |
tree | 28920f1b7aa06ba51428ffb4f569e714bd9089f2 /mock/tests/testmagicmethods.py | |
parent | d42410a09aeac50d5bb8a84bc1ab97dfd70ce909 (diff) | |
download | mock-55971296dc33650318a6397b21d4c4296a8dbca1.tar.gz |
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.
Backports: 6c83d9f4a72905d968418bef670bb3091d2744db
Signed-off-by: Chris Withers <chris@simplistix.co.uk>
Needed some re-working as this can only work and apply on Python 3
Diffstat (limited to 'mock/tests/testmagicmethods.py')
-rw-r--r-- | mock/tests/testmagicmethods.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mock/tests/testmagicmethods.py b/mock/tests/testmagicmethods.py index 1056b2a..705b9d1 100644 --- a/mock/tests/testmagicmethods.py +++ b/mock/tests/testmagicmethods.py @@ -12,6 +12,7 @@ except NameError: long = int import math +import os import sys import textwrap import unittest @@ -361,6 +362,17 @@ class TestMockingMagicMethods(unittest.TestCase): self.assertEqual(mock, object()) + def test_magic_methods_fspath(self): + mock = MagicMock() + if six.PY2: + self.assertRaises(AttributeError, lambda: mock.__fspath__) + else: + 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): |