New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make all test properties dynamic, and support much easier ways to set them #101
Comments
@mariusmagureanu I feel like you might have some good ideas on this one -- any notions? |
To support this, we need to extend the content-handler into a 'resolver' class that deals with more complex variable use/binding I think. It also needs to offer pythonic APIs, because that is likely the bit that will be modified the soonest. |
Validators need to support this for expected values, so you can use actual variables in your expected value tests, per #135 - without the nasty templates hack :( Tentatively rescheduling this as part of the 1.8.0 milestone, but something will need to be cut -- hard decisions there. |
Gathering implementation thoughts: This is going to be kind of complex and might take a couple prototypes to get right. Probably ties with #75 to some extent. In ANY case we're going to PURGE WITH FIRE the horrors of the current properties methods (with get/set/realize per field) and save grief by embedding it into our Test/Benchmark class instance or somehow using a local context. Solution: use of with-statement to embed the Context for transparent use by class? Kind of a hacky example for this #!/usr/bin/env python
# Hacky example
#!/usr/bin/env python
class contextbinding:
bindings = None
original = None
def __init__(self, key, value):
self.bindings = dict()
self.bindings[key] = value
def __enter__(self):
try:
self.original = bound
except NameError:
pass
global bound
bound = self.bindings
def __exit__(self, etype, value, traceback):
global bound
bound = self.original
pass
def get_bound(variable_name):
try:
return bound[variable_name]
except NameError:
pass
except KeyError:
pass
try:
return self.bound[variable_name]
except NameError:
pass
except KeyError:
pass
print("Variable not declared and needs binding: {0}".format(variable_name))
return None
# Demonstrate bindings option using a context?
keyname = 'original val'
print(get_bound('keyname'))
bound = {'keyname': 'awesome'}
print(get_bound('keyname'))
with contextbinding('keyname','goober') as lolbindingslol:
print(get_bound('keyname'))
print(get_bound('keyname')) Simplest approach:
Harder approach:
Coupling with parsing:
Ex something like: TestConfig():
myparser = ParserClass(my_allowed_options)
def parse(config):
for option in config:
parserclass.parse(self_to_set_up, config_option) # handles dynamic stuffs
def configure():
pass # Implementation & API TBD, this would be the pythonic/fluent API though. |
As a user of PyRestTest, I'd like to be able to set all test properties dynamically so I don't repeat myself. It would also be nice to make use of generators and variable simpler, and support raw values (not just strings for templates).
Nice to have: extensible templating, using something such as Jinja2.
Suggested syntax:
Better/shorter syntaxes for this (I.E. look at ansible)
Challenges:
Work Items:
For nice-to-have:
Example:
Work Items
The text was updated successfully, but these errors were encountered: