Giter Site home page Giter Site logo

deathbeds / sweet Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 39 KB

Testing for interactive programming

Home Page: https://mybinder.org/v2/gh/deathbeds/sweet/master?filepath=readme.ipynb

Python 36.35% Jupyter Notebook 63.65%
testing ipython jupyter doctest unittest hypothesis

sweet's Introduction

testing and typing is Sweet

Binder

Sweet is an easy way to test interactive code. It combines unittest, doctest, and hypothesis to promoting better code health.

    if __name__ == '__main__':
        %reload_ext sweet

Because creating a function or class should do more than create a name.

    def test_no_params():
        """This function is tested because it has no parameters.  It is executed using FunctionTestCase

        >>> assert True

        The docstring is also tested.
        """
        assert True
<sweet.test.Result run=2 errors=0 failures=0>
    ct = 0
    def when_there_are_annotations(x: int):
        global ct
        ct +=1
        return x
<sweet.test.Result run=1 errors=0 failures=0>
    def after_hypothesis():
        global ct
        assert ct > 0
<sweet.test.Result run=1 errors=0 failures=0>

Interactive typing

Using monkeytype

    %load_ext sweet.typing
    def f(x):
        return str(x)
    %typing
    f(10)
    f(10.)
    f('asdf')
    f(__import__('pandas').util.testing.makeDataFrame())
    after_hypothesis()
    %typing readme.pyi
    __import__('IPython').display.Pretty(filename='readme.pyi')
The sweet.typing extension is already loaded. To reload it, use:
  %reload_ext sweet.typing





from pandas.core.frame import DataFrame
from typing import Union


def after_hypothesis() -> None: ...


def f(x: Union[float, DataFrame, str, int]) -> str: ...

Developer.

    if __name__ == '__main__':
        !jupyter nbconvert --to markdown readme.ipynb
        from sweet import Sweet
        result = Sweet().run()
        print(f"""The readme shows the {result}""")
        print(f"""and the source shows the {Sweet(module='sweet').run(result)}""")
        print("๐Ÿ†")

sweet's People

Contributors

tonyfast avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.