grappa-py / grappa

Behavior-oriented, expressive, human-friendly Python assertion library for the 21st century
http://grappa.rtfd.io
MIT License
134 stars 15 forks source link

Conditional assertions for more fine-grained logic #35

Open tomas-fp opened 7 years ago

tomas-fp commented 7 years ago

New API method:

if grappa.when(should.be.os('centos')):
    'nginx' | should.be.running
    80 | should.be.listening
    'eth0' | should.have.interface

if not grappa.when(should.be.os('ubuntu')):
    'apache' | should.be.running
    8080 | should.be.listening

if '/opt' | grappa.when(should.path.exists):
    '/opt/foo' | should.directory.exists
    '/opt' | should.have.subdirectories(['log', 'app', 'run'])
ab-anand commented 6 years ago

Hi @h2non , I wanted to work on it. Can you please tell me how should I approach it?

h2non commented 6 years ago

This is not a trivial feature. Basically, one idea to implement what is on the examples above would be maintaining a global state everytime grappa.when is invoked in order to change the assertions behavior: avoid them to raise an exception, and instead store it internally so grappa.when can evaluate it accordingly. Just an idea anyway.

ab-anand commented 6 years ago

Hey thanks @h2non I'm working on it :)