Skip to content

Commit df2bfaf

Browse files
committed
Conditional skip for MicroPython.
1 parent c866652 commit df2bfaf

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<meta name="viewport" content="width=device-width,initial-scale=1.0">
1010

1111
<!-- PyScript CSS -->
12-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.6.1/core.css">
12+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
1313

1414
<!-- This script tag bootstraps PyScript -->
15-
<script type="module" src="https://pyscript.net/releases/2024.6.1/core.js"></script>
15+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
1616
</head>
1717
<body>
1818
<h1>MicroMock test suite (MicroPython)</h1>

index2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<meta name="viewport" content="width=device-width,initial-scale=1.0">
1010

1111
<!-- PyScript CSS -->
12-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.6.1/core.css">
12+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
1313

1414
<!-- This script tag bootstraps PyScript -->
15-
<script type="module" src="https://pyscript.net/releases/2024.6.1/core.js"></script>
15+
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
1616
</head>
1717
<body>
1818
<h1>MicroMock test suite (Pyodide)</h1>

tests/test_patch_target.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def test_patch_target_function():
8989
patch_target(target, old_function)
9090

9191

92-
@upytest.skip("This doesn't seem to work. Check with Damien.")
92+
@upytest.skip(
93+
"This doesn't work because of a MicroPython bug. Damien to fix.",
94+
when=upytest.is_micropython,
95+
)
9396
def test_patch_target_class_method():
9497
"""
9598
The target path is a dotted string with a colon, pointing to a method in a

umock.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,16 @@ def __getattr__(self, name):
314314
name.
315315
"""
316316
if name.startswith("_") or name in _RESERVED_MOCK_ATTRIBUTES:
317+
# Special attributes are handled as normal attributes.
317318
return self.__dict__.get(name)
318319
elif name in self.__dict__:
320+
# Existing attributes are returned as is.
319321
return self.__dict__[name]
320322
elif "_spec" in self.__dict__ and name not in self._spec:
323+
# If the attribute is not in the spec then raise an AttributeError.
321324
raise AttributeError(f"Mock object has no attribute '{name}'.")
322325
else:
326+
# Otherwise, create a new mock object for the attribute.
323327
new_mock = Mock()
324328
setattr(self, name, new_mock)
325329
return new_mock
@@ -574,14 +578,18 @@ def __getattr__(self, name):
574578
name.
575579
"""
576580
if name.startswith("_") or name in _RESERVED_MOCK_ATTRIBUTES:
581+
# Special attributes are handled as normal attributes.
577582
return self.__dict__.get(name)
578583
elif name in self.__dict__:
584+
# Existing attributes are returned as is.
579585
return self.__dict__[name]
580586
elif "_spec" in self.__dict__ and name not in self._spec:
587+
# If the attribute is not in the spec then raise an AttributeError.
581588
raise AttributeError(
582589
f"AsyncMock object has no attribute '{name}'."
583590
)
584591
else:
592+
# Otherwise, create a new mock object for the attribute.
585593
new_mock = AsyncMock()
586594
setattr(self, name, new_mock)
587595
return new_mock
@@ -625,7 +633,10 @@ def wrapper(*args, **kwargs):
625633

626634
def __enter__(self):
627635
"""
628-
Replace the target attribute with new.
636+
Replace the target attribute with self.new.
637+
638+
If self.new is None, a new Mock object is created with the supplied
639+
kwargs and bound to self.new before the target is replaced.
629640
"""
630641
self.new = self.new or Mock(**self.kwargs)
631642
self._old = patch_target(self.target, self.new)
@@ -669,9 +680,9 @@ def patch_target(target, replacement):
669680
parts = attributes.split(".")
670681
for part in parts[:-1]:
671682
parent = getattr(parent, part)
672-
# Get the original object that we're going to replace (so we can return
673-
# it).
683+
# Get the original target object that we're going to replace (so we can
684+
# return it).
674685
old_object = getattr(parent, target_name)
675-
# Replace the target attribute with the replacement.
686+
# Replace the target with the replacement.
676687
setattr(parent, target_name, replacement)
677688
return old_object

0 commit comments

Comments
 (0)