File: tests-Fix-import-pattern-for-mock-objects.patch

package info (click to toggle)
bmap-tools 3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 936 kB
  • sloc: python: 5,078; sh: 117; makefile: 8
file content (89 lines) | stat: -rw-r--r-- 4,269 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
From: Simon McVittie <smcv@debian.org>
Date: Thu, 28 Oct 2021 12:23:30 +0100
Subject: tests: Fix import pattern for mock objects

The legacy mock module contains a mock.mock submodule, but unittest.mock
does not contain a redundant unittest.mock.mock. This bug was masked by
the transparent fallback to the legacy mock module.

The actual test only uses mock.patch(), so we can simplify by just
importing the one member that we need.

Fixes: a1ca1172 "tests: Use unittest.mock from Python standard library if possible"
Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: https://github.com/intel/bmap-tools/pull/89
Applied-upstream: 3.7, commit:47908b5389d1f3de9306c0030856b3d3180ade86
---
 tests/test_bmap_helpers.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/test_bmap_helpers.py b/tests/test_bmap_helpers.py
index 56b079e..36c4557 100644
--- a/tests/test_bmap_helpers.py
+++ b/tests/test_bmap_helpers.py
@@ -22,9 +22,9 @@ import os
 import sys
 import tempfile
 try:
-    from unittest.mock import patch, mock
+    from unittest.mock import patch
 except ImportError:     # for Python < 3.3
-    from mock import patch, mock
+    from mock import patch
 try:
     from tempfile import TemporaryDirectory
 except ImportError:     # for Python < 3.2
@@ -76,7 +76,7 @@ class TestBmapHelpers(unittest.TestCase):
                                          delete=True, dir=".", suffix=".txt") as fobj:
             fobj.write("1")
             fobj.flush()
-            mockobj = mock.patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
+            mockobj = patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
             with mockobj:
                 self.assertTrue(BmapHelpers.is_zfs_configuration_compatible())
 
@@ -88,7 +88,7 @@ class TestBmapHelpers(unittest.TestCase):
                                          delete=True, dir=".", suffix=".txt") as fobj:
             fobj.write("0")
             fobj.flush()
-            mockobj = mock.patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
+            mockobj = patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
             with mockobj:
                 self.assertFalse(BmapHelpers.is_zfs_configuration_compatible())
 
@@ -97,7 +97,7 @@ class TestBmapHelpers(unittest.TestCase):
 
         with tempfile.NamedTemporaryFile("a", prefix="testfile_",
                                          delete=True, dir=".", suffix=".txt") as fobj:
-            mockobj = mock.patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
+            mockobj = patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
             with self.assertRaises(BmapHelpers.Error):
                 with mockobj:
                     BmapHelpers.is_zfs_configuration_compatible()
@@ -116,7 +116,7 @@ class TestBmapHelpers(unittest.TestCase):
 
         directory = os.path.dirname(__file__)
         filepath = os.path.join(directory, "BmapHelpers/file/does/not/exist")
-        mockobj = mock.patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", filepath)
+        mockobj = patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", filepath)
         with mockobj:
             self.assertFalse(BmapHelpers.is_zfs_configuration_compatible())
 
@@ -128,7 +128,7 @@ class TestBmapHelpers(unittest.TestCase):
                                          delete=True, dir=".", suffix=".img") as fobj:
             fobj.write("1")
             fobj.flush()
-            mockobj = mock.patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
+            mockobj = patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
             with mockobj:
                 self.assertTrue(BmapHelpers.is_compatible_file_system(fobj.name))
 
@@ -140,7 +140,7 @@ class TestBmapHelpers(unittest.TestCase):
                                          delete=True, dir=".", suffix=".img") as fobj:
             fobj.write("0")
             fobj.flush()
-            mockobj = mock.patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
+            mockobj = patch.object(BmapHelpers, "ZFS_COMPAT_PARAM_PATH", fobj.name)
             with mockobj:
                 self.assertFalse(BmapHelpers.is_compatible_file_system(fobj.name))