Package: fastest
FastestCreates unit tests from examples in the docstring and more.Install$pipinstallfastestUsage$fastestwatches all .py files and creates coverage for entire project.$fastest--path=$(pwd)--source=py_modulewherepathis the the project root, andsourceis same as the value passed to the commandcoverage run -m unittest --source=$source test$fastest--exclude=dont_check_this_dir/*,these__*.pyTo exclude files/folders use--excludeand the file watcher will ignore them.
Thetest/*folder thatfastercreates is excluded by default.$fastest--poll-duration=10Builds files, runs tests and coverage every10s, default =1sThings that happen when you runpython main.py --path=$(pwd):Checks for atestfile at the project root, it creates if it doesn't find one.Watches.pyfiles for changes.Creates unittests if a function has examples in its docstrings like so:# .# ├──module_a# ├──module_b#    └── utils.py#defadd(x,y):"""----examples:1) add(3, 4) -> 7"""returnx+yThis will create a unittest in thetestdirectory,assertEqual(add(3, 4), 7)withinClass test_<file>_<function>(self)(for the given directory, tree:Class test_utils_add(self))Runs all tests that are created.Creates a coverage report (in html format).Print the link to the coverage reports' index.html.How to make best use of FastestKeep yourfunctionslight:Be paranoid about separation of concerns.Too many conditions are a hint that you might need another function.Complex loops andif-elseare not scalable code, a single mistake would
take that tower down and feature additions would involve someone going through
that brain-teaser.Use libraries but wrap them with your own functions. Like: Userequestsor 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.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 documentationIScontributing to tests.Examples:Allows creation of variables within the docstrings, which includes lambda functions!defquick_maths(a,b):"""----examples:@leta = {'apples': 3,'oranges': 4}@end1) quick_maths(a['apples'], a['oranges']) -> 7----"""returna+bYou can run any valid python code within@let--@endblocks.Can include installed modules external to your project.defcurrent_time():"""---examples:@needfrom datetime import datetime@end1) current_time() -> datetime.now()"""returndatetime.now()If types are added to docstring, Fastest will create tests
for checking type of the value returned against empty of arguments.defchain_strings(str1,str2):""":param str1: str:param str2: str:return: str"""returnstr1+str2Fastest will create aassertInstanceIs(chain_strings('', ''), str)for the above snippet.To create anassertRaisestest-case:defcrashes_sometimes(input_string):"""----examples:!! crashes_sometimes(None) -> ValueError----"""ifnotinput_string:raiseValueErrorreturninput_stringThe syntax marked with!! crashes_sometimes(None) -> ValueErrorhandles exceptions
that the code throwsGoals for FastestHelp 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!