Skip to content

Commit 0c5ac7e

Browse files
committed
Add new test
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 413d99a commit 0c5ac7e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tests/test_license_expression.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,13 @@ def test_dedup_licensexpressions_can_be_simplified_3(self):
696696
expected = l.parse('mit')
697697
assert result == expected
698698

699+
def test_dedup_licensexpressions_works_with_subexpressions(self):
700+
l = Licensing()
701+
exp = l.parse('(mit OR gpl-2.0) AND mit AND bsd-new AND (mit OR gpl-2.0)')
702+
result = l.dedup(exp)
703+
expected = l.parse('(mit OR gpl-2.0) AND mit AND bsd-new')
704+
assert result == expected
705+
699706
def test_simplify_and_equivalent_and_contains(self):
700707
l = Licensing()
701708
expr2 = l.parse(' GPL-2.0 or (mit and LGPL-2.1) or bsd Or GPL-2.0 or (mit and LGPL-2.1)')
@@ -940,21 +947,17 @@ def test_parse_invalid_expression_with_repeated_trailing_or_raise_exception(self
940947
}
941948
assert expected == _parse_error_as_dict(pe)
942949

943-
@expectedFailure
944-
def test_parse_invalid_expression_with_single_trailing_or_raise_exception(self):
950+
def test_parse_invalid_expression_drops_single_trailing_or(self):
945951
licensing = Licensing()
946952
expression = 'mit or mit or'
947-
try:
948-
licensing.parse(expression, simple=False)
949-
self.fail('Exception not raised')
950-
except ParseError as pe:
951-
expected = {
952-
'error_code': PARSE_INVALID_OPERATOR_SEQUENCE,
953-
'position': 14,
954-
'token_string': 'or',
955-
'token_type': TOKEN_OR
956-
}
957-
assert expected == _parse_error_as_dict(pe)
953+
e = licensing.parse(expression, simple=False)
954+
assert str(e) == 'mit OR mit'
955+
956+
def test_parse_invalid_expression_drops_single_trailing_or2(self):
957+
licensing = Licensing()
958+
expression = 'mit or mit or'
959+
e = licensing.parse(expression, simple=True)
960+
assert str(e) == 'mit OR mit'
958961

959962
def test_parse_invalid_expression_with_single_trailing_and_raise_exception(self):
960963
licensing = Licensing()

0 commit comments

Comments
 (0)