Skip to main content

Fastest

Creates unit tests from examples in the docstring and more.

Codacy Badge Scrutinizer_Badge Coverage Status Build_Status Current_Version Python_Version

Install

$ pip install fastest

Usage

$ fastest

watches all .py files and creates coverage for entire project.

$ fastest --path=$(pwd) --source=py_module

where path is the the project root, and source is same as the value passed to the command coverage run -m unittest --source=$source test

$ fastest --exclude=dont_check_this_dir/*,these__*.py

To exclude files/folders use --exclude and the file watcher will ignore them. The test/* folder that faster creates is excluded by default.

$ fastest --poll-duration=10

Builds files, runs tests and coverage every 10s, default = 1s

Things that happen when you run python main.py --path=$(pwd):

  1. Checks for a test file at the project root, it creates if it doesn't find one.
  2. Watches .py files for changes.
  3. Creates unittests if a function has examples in its docstrings like so:
# .
# ├──module_a
# ├──module_b
#    └── utils.py
#
def add(x, y):
    """
    ----
    examples:
    1) add(3, 4) -> 7
    """
    return x + y

This will create a unittest in the test directory, assertEqual(add(3, 4), 7) within Class test_<file>_<function>(self) (for the given directory, tree: Class test_utils_add(self))

  1. Runs all tests that are created.
  2. Creates a coverage report (in html format).
  3. Print the link to the coverage reports' index.html.

How to make best use of Fastest

  1. Keep your functions light:
    • Be paranoid about separation of concerns.
    • Too many conditions are a hint that you might need another function.
    • Complex loops and if-else are not scalable code, a single mistake would take that tower down and feature additions would involve someone going through that brain-teaser.
  2. Use libraries but wrap them with your own functions. Like: Use requests or the inevitable database? wrap them with your own functions.
    • Helps with adding customizations in one place (configuring things like base url, and similar configs)
    • Helps mocking so that entire code-base can be unit tested.
  3. Docstrings may get outdated if your work pace is too fast to maintain quality documentation. Now adding examples now would help you create tests which prevents your descriptions from going stale, if the tests fail, probably the documentation needs a second look too. This is enforced within Fastest, as documentation IS contributing to tests.

Examples:

  1. Allows creation of variables within the docstrings, which includes lambda functions!
    def quick_maths(a, b):
       """
       ----
       examples:
       @let 
       a = {
           'apples': 3,
           'oranges': 4
       }
       @end
       
       1) quick_maths(a['apples'], a['oranges']) -> 7
       ----
       """
       return a + b
    
  2. You can run any valid python code within @let--@end blocks.
  3. Can include installed modules external to your project.
    def current_time():
       """
       ---
       examples:
       @need
       from datetime import datetime
       @end
       1) current_time() -> datetime.now()
       """
       return datetime.now()
    
  4. If types are added to docstring, Fastest will create tests for checking type of the value returned against empty of arguments.
    def chain_strings(str1, str2):
        """
        :param str1: str
        :param str2: str
        :return: str
        """
        return str1 + str2
    
    Fastest will create a assertInstanceIs(chain_strings('', ''), str) for the above snippet.
  5. To create an assertRaises test-case:
    def crashes_sometimes(input_string):
       """
       ----
       examples: 
    
       !! crashes_sometimes(None) -> ValueError
       ----
       """
       if not input_string:
           raise ValueError
       return input_string
    
    The syntax marked with !! crashes_sometimes(None) -> ValueError handles exceptions that the code throws

Goals for Fastest

  • Help maintaining tests, code-coverage and documentation.
  • Help with performance issues within code.
  • Provide testability score for code.
  • Test functions for auto-generated inputs where the code would crash.

Fastest uses itself for creating tests and manages a 100% on the coverage!

Metadata

Release files for fastest 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastest 0.3.1
File Size Uploaded
fastest-0.3.1.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastest 0.3.1
File Interpreter ABI Platform
fastest-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 64.9 kB

Release files / fastest-0.3.1.tar.gz

Download URL fastest-0.3.1.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f69d61a956d1246c0da160c383e13fcdc7aa2089fd375a84a58173b12f164821
BLAKE2b-256 checksum
How to use checksums
71a86fd564cffe543c5795fcad5a49390152eb98eae7e50942bacb5cc04417e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.5.6 Linux/4.15.0-45-generic

Release files / fastest-0.3.1-py3-none-any.whl

Download URL fastest-0.3.1-py3-none-any.whl
Size 48.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
145e7b004b43d0313ec593d1e3931c5dbc194534b2d8e27a5624257789a816cb
BLAKE2b-256 checksum
How to use checksums
268a57ba6e883a9aa5c49485f5e2baf947b9eaa55f8e1cd295dc2c30dbbd38cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.5.6 Linux/4.15.0-45-generic

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page