Skip to content

Commit afa6dce

Browse files
authored
Merge pull request #112 from arbassett-qnx/patch-1
Fix LicenseWithExceptionSymbol missing Expression class variables
2 parents 62fa21a + 75d58a5 commit afa6dce

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/license_expression/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ def __init__(self, symbols=tuple(), quiet=True):
257257

258258
# FIXME: this should be instead a super class of all symbols
259259
self.LicenseSymbol = self.Symbol
260+
# LicenseWithExceptionSymbol does not get its internal Expressions mapped durring BooleanAlgebra init
261+
# have to set it after the fact
262+
tf_nao = {
263+
"TRUE": self.TRUE,
264+
"FALSE": self.FALSE,
265+
"NOT": self.NOT,
266+
"AND": self.AND,
267+
"OR": self.OR,
268+
"Symbol": self.Symbol,
269+
}
270+
271+
for name, value in tf_nao.items():
272+
setattr(LicenseWithExceptionSymbol, name, value)
260273

261274
symbols = symbols or tuple()
262275

tests/test_license_expression.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,42 @@ def test_LicenseSymbol(self):
9696
# symbol euqality is based ONLY on the key
9797
assert sym5 == sym6
9898

99+
def test_python_operators_simple(self):
100+
licensing = Licensing()
101+
102+
sym1 = LicenseSymbol('MIT')
103+
sym2 = LicenseSymbol('BSD-2')
104+
105+
assert sym1 & sym2 == licensing.AND(sym1, sym2)
106+
assert sym1 | sym2 == licensing.OR(sym1, sym2)
107+
108+
sym3 = LicenseWithExceptionSymbol(LicenseSymbol("GPL-3.0-or-later"), LicenseSymbol("GCC-exception-3.1"))
109+
110+
# Make sure LicenseWithExceptionSymbol operation work on left and right side
111+
assert sym3 & sym1 == licensing.AND(sym3, sym1)
112+
assert sym1 & sym3 == licensing.AND(sym1, sym3)
113+
assert sym3 | sym1 == licensing.OR(sym3, sym1)
114+
assert sym1 | sym3 == licensing.OR(sym3, sym1)
115+
116+
def test_boolean_expression_operators(self):
117+
118+
# Make sure LicenseWithExceptionSymbol boolean expression are set
119+
assert LicenseWithExceptionSymbol.Symbol is not None
120+
assert LicenseWithExceptionSymbol.TRUE is not None
121+
assert LicenseWithExceptionSymbol.FALSE is not None
122+
assert LicenseWithExceptionSymbol.AND is not None
123+
assert LicenseWithExceptionSymbol.OR is not None
124+
assert LicenseWithExceptionSymbol.NOT is not None
125+
126+
# Make sure LicenseWithExceptionSymbol matches LicenseSymbol
127+
assert LicenseWithExceptionSymbol.Symbol == LicenseSymbol
128+
assert LicenseWithExceptionSymbol.TRUE == LicenseSymbol.TRUE
129+
assert LicenseWithExceptionSymbol.FALSE == LicenseSymbol.FALSE
130+
assert LicenseWithExceptionSymbol.AND == LicenseSymbol.AND
131+
assert LicenseWithExceptionSymbol.OR == LicenseSymbol.OR
132+
assert LicenseWithExceptionSymbol.NOT == LicenseSymbol.NOT
133+
134+
99135

100136
class LicensingTest(TestCase):
101137

0 commit comments

Comments
 (0)