Skip to main content

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.

Project description

StrongMock

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.

Functionality/Usage

Basic

instead of unittest.mock.patch use strongmock.strongpatch

More advanced features

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.

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).

strongpatch.object

Same as patch.object, but does the same advanced replacement as strongpatch

strongpatch.multiple

Same as patch.multiple, but does the same advanced replacement as strongpatch

Async

Also works on async functions, with similar stronger patching

Safety

Some care has been taken to avoid crashes and breakage, but the user does have full control. One word answer - no.

Working and usage

strongpatch

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.

strongpatch.mock_imports

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)

strongpatch.equal_basic_objects

We dump the bytes from objsrc to objdst

huh?

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")

Links

PyPi
GitHub

License

StrongMock is licensed under the Unlicense. See the LICENSE file for details.

Official theme music

When using these methods, it is recommended that you listen to this for better code.
Kai's Theme Epic Version (Slowed + BassBoosted)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strongmock-0.0.6.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

strongmock-0.0.6-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file strongmock-0.0.6.tar.gz.

File metadata

  • Download URL: strongmock-0.0.6.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for strongmock-0.0.6.tar.gz
Algorithm Hash digest
SHA256 5f48c5db66f1043a33994ea3c54f9ee49a253770e33185cc08e0d9ba4ab2309a
MD5 609e2e184291a03792576ae55eedae86
BLAKE2b-256 8e6e9a53f1113c954e7a9dc182858963ff7966265cf2a985c584de9b27725c3c

See more details on using hashes here.

File details

Details for the file strongmock-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: strongmock-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for strongmock-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b106bb8b27de77ec343c1c07318f621768e214cb077acdb0704d8f11590274c1
MD5 d0268a9f25d15b8c0b282d45c5ee64ba
BLAKE2b-256 d88284af306202b4cbed6ae35d7241bc76eb2c8b3b26de6094a7f2f40bb0fbba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page