
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
StrongMock is a powerful mocking library for Python that leverages low-level ctypes functionality to provide extensive mocking capabilities. Some care may be needed while using this.
Ever wanted Unlimited Power while patching things ?
StrongMock is a powerful mocking library for Python that leverages low-level ctypes functionality to provide extensive mocking capabilities. Some care may be needed while using this.
from unittest.mock import patch
use from strongmock import strongpatch
.strongpatch
is an alias for patch
in the module, meaning from strongmock import patch
can also be used.unittest.mock
are present in strongmock
.isinstance
compatibility - limited to Mock
, MagicMock
and AsyncMock
.strongpatch.equal_basic_objects
Can make floats / ints / True False and other basic objects equal to each other.
This customization of the equality behavior of basic objects can be useful when you have to test very very specific edge cases, maybe something governing program flow etc. Can also be used as a context manager.
strongpatch.mock_imports
Replaces imports with Magicmock, takes in a tuple of strings, optional parameter override which decides if we override existing imports as well (True by default). Can also be used as a context manager.
Also works on async functions, with similar stronger patching
Some care has been taken to avoid crashes and breakage, but the user does have full control. One word answer - no.
This applies when the target of a strongmock.strongpatch
is a function defined in python with a __code__
attribute. For other cases (methods in a class, classes, lbrary functions in c, etc.), the behaviour is the same as unittest.patch
.
This will patch the __code__
attribute of the function to call the mock, meaning that references will also have the functionality of mock.
This can be extremely convenient in some cases.
We can pass testcases that need imports inside them
class TestImportPatch(unittest.TestCase):
@strongpatch.mock_imports(("somelib_abcd",))
def test_import_somelib_abcd(self):
import somelib_abcd
self.assertIsInstance(somelib_abcd.somefn(), MagicMock)
We dump the bytes from objsrc to objdst, meaning we can do basically do True = False
or 1 = 2
(not ==
as in comparison but =
as in assignment)
Yes, you can now pass these testcases.
import unittest
from strongmock import strongpatch
class StrongMockDemoTest(unittest.TestCase):
@strongpatch.equal_basic_objects(False, True)
def test_truefalse_patch_0(self):
if True != False:
raise RuntimeError("TRUEFALSE PATCH FAILED")
StrongMock is licensed under the Unlicense. See the LICENSE file for details.
When using these methods, it is recommended that you listen to this for better code.
Kai's Theme Epic Version (Slowed + BassBoosted)
FAQs
StrongMock is a powerful mocking library for Python that leverages low-level ctypes functionality to provide extensive mocking capabilities. Some care may be needed while using this.
We found that strongmock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.