Best Python code snippet using autotest_python
specification.py
Source:specification.py
...11 raise NotImplementedError()12 def not_specification(self):13 raise NotImplementedError()14 @abstractmethod15 def is_satisfied_by(self, candidate):16 pass17class CompositeSpecification(Specification):18 @abstractmethod19 def is_satisfied_by(self, candidate):20 pass21 def and_specification(self, candidate):22 return AndSpecification(self, candidate)23 def or_specification(self, candidate):24 return OrSpecification(self, candidate)25 def not_specification(self):26 return NotSpecification(self)27class AndSpecification(CompositeSpecification):28 _one = Specification()29 _other = Specification()30 def __init__(self, one, other):31 self._one = one32 self._other = other33 def is_satisfied_by(self, candidate):34 return bool(35 self._one.is_satisfied_by(candidate)36 and self._other.is_satisfied_by(candidate)37 )38class OrSpecification(CompositeSpecification):39 _one = Specification()40 _other = Specification()41 def __init__(self, one, other):42 self._one = one43 self._other = other44 def is_satisfied_by(self, candidate):45 return bool(46 self._one.is_satisfied_by(candidate)47 or self._other.is_satisfied_by(candidate)48 )49class NotSpecification(CompositeSpecification):50 _wrapped = Specification()51 def __init__(self, wrapped):52 self._wrapped = wrapped53 def is_satisfied_by(self, candidate):54 return bool(not self._wrapped.is_satisfied_by(candidate))55class User:56 def __init__(self, super_user=False):57 self.super_user = super_user58class UserSpecification(CompositeSpecification):59 def is_satisfied_by(self, candidate):60 return isinstance(candidate, User)61class SuperUserSpecification(CompositeSpecification):62 def is_satisfied_by(self, candidate):63 return getattr(candidate, "super_user", False)64def main():65 """66 >>> andrey = User()67 >>> ivan = User(super_user=True)68 >>> vasiliy = 'not User instance'69 >>> root_specification = UserSpecification().and_specification(SuperUserSpecification())70 # Is specification satisfied by <name>71 >>> root_specification.is_satisfied_by(andrey), 'andrey'72 (False, 'andrey')73 >>> root_specification.is_satisfied_by(ivan), 'ivan'74 (True, 'ivan')75 >>> root_specification.is_satisfied_by(vasiliy), 'vasiliy'76 (False, 'vasiliy')77 """78if __name__ == "__main__":79 import doctest...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!