Skip to content

Commit

Permalink
Add test cases for spdx
Browse files Browse the repository at this point in the history
Copy over old test cases from poetry repository.
  • Loading branch information
abn committed Mar 27, 2020
1 parent fbfcda7 commit 493ae5d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Empty file added tests/spdx/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions tests/spdx/test_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from poetry.core.spdx import license_by_id


def test_classifier_name():
license = license_by_id("lgpl-3.0-or-later")

assert (
license.classifier_name
== "GNU Lesser General Public License v3 or later (LGPLv3+)"
)


def test_classifier_name_no_classifer_osi_approved():
license = license_by_id("LiLiQ-R-1.1")

assert license.classifier_name is None


def test_classifier_name_no_classifer():
license = license_by_id("Leptonica")

assert license.classifier_name == "Other/Proprietary License"


def test_classifier():
license = license_by_id("lgpl-3.0-or-later")

assert license.classifier == (
"License :: "
"OSI Approved :: "
"GNU Lesser General Public License v3 or later (LGPLv3+)"
)


def test_classifier_no_classifer_osi_approved():
license = license_by_id("LiLiQ-R-1.1")

assert license.classifier == "License :: OSI Approved"


def test_classifier_no_classifer():
license = license_by_id("Leptonica")

assert license.classifier == "License :: Other/Proprietary License"


def test_proprietary_license():
license = license_by_id("Proprietary")

assert "License :: Other/Proprietary License" == license.classifier
43 changes: 43 additions & 0 deletions tests/spdx/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

from poetry.core.spdx import license_by_id


def test_license_by_id():
license = license_by_id("MIT")

assert license.id == "MIT"
assert license.name == "MIT License"
assert license.is_osi_approved
assert not license.is_deprecated

license = license_by_id("LGPL-3.0-or-later")

assert license.id == "LGPL-3.0-or-later"
assert license.name == "GNU Lesser General Public License v3.0 or later"
assert license.is_osi_approved
assert not license.is_deprecated


def test_license_by_id_is_case_insensitive():
license = license_by_id("mit")

assert license.id == "MIT"

license = license_by_id("miT")

assert license.id == "MIT"


def test_license_by_id_with_full_name():
license = license_by_id("GNU Lesser General Public License v3.0 or later")

assert license.id == "LGPL-3.0-or-later"
assert license.name == "GNU Lesser General Public License v3.0 or later"
assert license.is_osi_approved
assert not license.is_deprecated


def test_license_by_id_invalid():
with pytest.raises(ValueError):
license_by_id("invalid")

0 comments on commit 493ae5d

Please sign in to comment.