diff --git a/src/license_expression/__init__.py b/src/license_expression/__init__.py index 57acb84..8f5af65 100644 --- a/src/license_expression/__init__.py +++ b/src/license_expression/__init__.py @@ -257,6 +257,19 @@ def __init__(self, symbols=tuple(), quiet=True): # FIXME: this should be instead a super class of all symbols self.LicenseSymbol = self.Symbol + # LicenseWithExceptionSymbol does not get its internal Expressions mapped durring BooleanAlgebra init + # have to set it after the fact + tf_nao = { + "TRUE": self.TRUE, + "FALSE": self.FALSE, + "NOT": self.NOT, + "AND": self.AND, + "OR": self.OR, + "Symbol": self.Symbol, + } + + for name, value in tf_nao.items(): + setattr(LicenseWithExceptionSymbol, name, value) symbols = symbols or tuple() diff --git a/tests/test_license_expression.py b/tests/test_license_expression.py index a2d5c84..7f75d7a 100644 --- a/tests/test_license_expression.py +++ b/tests/test_license_expression.py @@ -96,6 +96,42 @@ def test_LicenseSymbol(self): # symbol euqality is based ONLY on the key assert sym5 == sym6 + def test_python_operators_simple(self): + licensing = Licensing() + + sym1 = LicenseSymbol('MIT') + sym2 = LicenseSymbol('BSD-2') + + assert sym1 & sym2 == licensing.AND(sym1, sym2) + assert sym1 | sym2 == licensing.OR(sym1, sym2) + + sym3 = LicenseWithExceptionSymbol(LicenseSymbol("GPL-3.0-or-later"), LicenseSymbol("GCC-exception-3.1")) + + # Make sure LicenseWithExceptionSymbol operation work on left and right side + assert sym3 & sym1 == licensing.AND(sym3, sym1) + assert sym1 & sym3 == licensing.AND(sym1, sym3) + assert sym3 | sym1 == licensing.OR(sym3, sym1) + assert sym1 | sym3 == licensing.OR(sym3, sym1) + + def test_boolean_expression_operators(self): + + # Make sure LicenseWithExceptionSymbol boolean expression are set + assert LicenseWithExceptionSymbol.Symbol is not None + assert LicenseWithExceptionSymbol.TRUE is not None + assert LicenseWithExceptionSymbol.FALSE is not None + assert LicenseWithExceptionSymbol.AND is not None + assert LicenseWithExceptionSymbol.OR is not None + assert LicenseWithExceptionSymbol.NOT is not None + + # Make sure LicenseWithExceptionSymbol matches LicenseSymbol + assert LicenseWithExceptionSymbol.Symbol == LicenseSymbol + assert LicenseWithExceptionSymbol.TRUE == LicenseSymbol.TRUE + assert LicenseWithExceptionSymbol.FALSE == LicenseSymbol.FALSE + assert LicenseWithExceptionSymbol.AND == LicenseSymbol.AND + assert LicenseWithExceptionSymbol.OR == LicenseSymbol.OR + assert LicenseWithExceptionSymbol.NOT == LicenseSymbol.NOT + + class LicensingTest(TestCase):