Code Monkey home page Code Monkey logo

typemock's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

inikolaev

typemock's Issues

What's the status of this project?

Hi!

What's the status of this project?
I saw a note that it's still alfa and there haven't been any changes for quite a while already.
Any plans to continue working on it?

Be able to mock functions

Should be able to mock a function. Something like.

def a_function(some_arg: str) -> int:
    pass

with tmock(a_function) as mocked_function:
    when(mocked_function("hello")).then_return(1)

Perform deep copy of passed parameters

Consider the following example:

class MyEntity(BaseModel):
    id: uuid.UUID
    name: Optional[str]


class MyRepository:
    def save(self, entity: MyEntity) -> None:
        pass


class MyService:
    def __init__(self, repository: MyRepository):
        self.__repository = repository

    def run(self, entity: MyEntity):
        self.__repository.save(entity)
        entity.name = 'test'


def test_typemock_deep_copy():
    entity = MyEntity(id=uuid.uuid4())
    entity_copy = entity.copy(deep=True)

    with tmock(MyRepository) as repository:
        when(repository.save(entity)).then_return(None)

    service = MyService(repository)
    service.run(entity_copy)

    verify(repository).save(entity)

Here MyService makes modifications to an entity after a call to repository. When test verifies that the call was made if fails, because it cannot find matching call, because recorded interaction contains a reference to the method arguments instead of making copies.

Mock has the same problem in Python and there's an example of the CopyingMock on the official documentation.

I can try to prepare PR to fix it, or maybe it could be optional, by adding an extra parameter to tmock function. Personally I don't see any harm in making deep copy all the time, there might be some performance concerns though.

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.