Giter Site home page Giter Site logo

haarcuba / testix Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 3.0 376 KB

Mocking framework for Python with *exact* Scenarios

License: MIT License

Python 40.95% Shell 0.27% Ruby 1.87% Vim Script 56.91%
mock mocking-framework python unit-testing unittest

testix's People

Contributors

haarcuba avatar yoav-magen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

testix's Issues

create expectation from FakeObject

this is an extension of the __dynamic__ functionality.
I want this to be possible:

for i in range(10):
    dynamicly_named_mock = Fake(f'name_{i}')
    s.__from_fake__(dyamically_named_mock).some_method( 'arg1', 'arg2', ... )

currently only this works:

for i in range(10):
    dynamicly_named_mock = Fake(f'name_{i}')
    s.__dynamic__(f'name_{i}').some_method( 'arg1', 'arg2', ... )

support class property

when we use properties in classes, it's unclear how to fake it in our tests.

today, to set a property in some object I use:

### this code can happen anywhere before the flow
the_object = Fake('the_object')
the_object.some_property = 'some_value'

### now we return this object
s.the_flow() >> Fake('the_object')

i suggest adding kwargs to Fake class, so i can use Fake like this:

s.the_flow() >> Fake('the_object', some_property='some_value',... )

phase 2

create some more documentation

support contexts natively

something like

with s.tempfile.TemporaryFile() as f
       s.__from_fake__(f).read()

       run_some_code()

and the code is

with tempfile.TemporaryFile() as f:
    f.read()

function call expectations are reversed

e.g.:

E       testix: ExpectationException                                                                                                                                         
E       testix details:                                                                                                                                                      
E       expected: tempfile.NamedTemporaryFile()                                                                                                                              
E       actual  : tempfile.NamedTemporaryFile(mode = 'w')    

but the test specified mode="w" and the code called without it.
in short, the actual and expected are reversed here.

improve docs

  • explain on how strings can be used to represent object that are only "passed around"
  • add advanced features docs

enforce awaiting on async expectations

e.g.

    @pytest.mark.asyncio
    async def test_async_context_managers(self):
        with scenario.Scenario('async context managers') as s:
            s.__async_with__.open('/path/to/file', 'rw') >> fake.Fake('my_file')
            s.__await_on__.my_file.read(500) >> 'some text'
            s.my_file.seek(0)
            s.__await_on__.my_file.write('more text')

            open_mock = fake.Fake('open')
            async with open_mock('/path/to/file', 'rw') as my_file:
                assert await my_file.read(500) == 'some text'
                my_file.seek(0)
                my_file.write('more text')
                # ^^^^ this line should have an await, but we don't catch this

strings displayed incorrectly on failures

e.g.

E       Failed: 
E       testix: ExpectationException
E       testix details:
E       expected: thingy.insert()
E       actual  : thingy.set(status, failed)

it should be actual: thingy.set('status', 'failed')

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.