svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 326 forks source link

v2 Part 1: Refactor nightmarish parsing configuration to be DRY and elegant #75

Open svanoort opened 9 years ago

svanoort commented 9 years ago

The way parsing is handled for the core tests is a nightmare and seriously impedes the ability to extend pyresttest. We have a special case for each parse option, and the handling of command-line, test-level, and testset options is completely bonkers, since has separate parsing code.

Let's apply lessons learnt to fix this. Instead of the long, brutish mess of parsing (and test of the parsing), let's apply the lessons learned in the validator classes, and apply a registry + dynamic parse function method. But, let's do it better since type coercion is required.

Use registries:

RESERVED_KEYWORDS = set('test', 'blah', 'bleh')  # Cannot be used as a macro name
MACROS = {test: parse_test, benchmark: parse_benchmark}  # Consider carefully
STEPS = {}  # Currently not used, used when run methods get subdivided, these will be components of a macro
OPTIONS = {   # Can occur at global, macro, or testset level
  'name': (coerce_function, type, default, duplicate_allowed)
}

Need to think about options, but items will be iteratively run through each dictionary looking for matches and then handed to parse functions. For options, if duplicates are added, they'll be combined together.

For the command-line ("global") arguments, they need to get mapped to an option too, but it'll be more flexible.

This also acts as a useful and compatibility-maintaining precursor to the nested context structure from https://github.com/svanoort/pyresttest/issues/45.

Work Items

svanoort commented 9 years ago

If we want to keep the class elements... each class can define its own parse table? Something like SYNTAX_ELEMENTS. Then we can use this to do parsing?

svanoort commented 9 years ago

Addendum: let's add the ability to add documentation strings to these! Then we can use a generator & template for syntax documentation. One less place to make changes when extending the framework.

svanoort commented 9 years ago

Proposal:

svanoort commented 9 years ago

For autodocumented code, use Sphinx, helpful links:

https://codeandchaos.wordpress.com/2012/07/30/sphinx-autodoc-tutorial-for-dummies/ http://thomas-cokelaer.info/tutorials/sphinx/docstring_python.html https://pythonhosted.org/an_example_pypi_project/sphinx.html

svanoort commented 8 years ago

Kicking back to 1.8 milestone: collision with the Unicode/Python 3 compatibility/test coverage for that means this is just too much to take on at the moment.