tag-expressions 2.0.1


pip install tag-expressions

  Latest version

Released: Nov 23, 2024

Project Links

Meta
Author: Timo Furrer

Classifiers

Development Status
  • 5 - Production/Stable

Environment
  • Console

License
  • OSI Approved :: GNU General Public License v3 or later (GPLv3+)

Operating System
  • MacOS :: MacOS X
  • POSIX
  • POSIX :: Linux

Programming Language
  • Python
  • Python :: 2
  • Python :: 2.7
  • Python :: 3
  • Python :: 3.3
  • Python :: 3.4
  • Python :: 3.5
  • Python :: 3.6
  • Python :: 3.7
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: Implementation
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Software Development :: Testing

Package to evaluate logical tag expressions by using a modified version of the Shunting Yard algorithm. This package is a Python port of cucumbers tag expression.

It’s also used by radish.

Build Status PyPI package version PyPI python versions

Installing

$ pip install tag-expressions

Here is a tease

>>> from tagexpressions import parse
>>>
>>> expression = '( a and b ) or ( c and d )'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( a and b ) or ( c and d ) )
>>>
>>> data = ['a', 'b', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c']
>>> assert compiled_expression.evaluate(data) == False
>>>
>>>
>>> expression = 'not a or b and not c or not d or e and f'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )
>>>
>>> data = ['b', 'e', 'f']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == False

Usage

Available operators

  • or - “or” conjunction of two given variables

  • and - “and” conjunction of two given variables

  • not - negation of a single variable

Every other token given in an infix is considered a variable.

Operator precedence

From high to low:

  • ()

  • or

  • and

  • not

Wheel compatibility matrix

Platform Python 3
any

Files in release

No dependencies