Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /calkit_calkit /calkit /tests /test_licenses.py
| """Tests for the ``licenses`` module.""" | |
| from calkit.licenses import ( | |
| LICENSE_TEMPLATE_DUAL, | |
| detect_license_ids, | |
| find_license_file, | |
| ) | |
| # A standard MIT license file, as generated by GitHub. Note that it says | |
| # "MIT License" and never "The MIT License", which is what regressed in | |
| # https://github.com/calkit/calkit/issues/919. | |
| MIT_TEXT = """MIT License | |
| Copyright (c) 2026 Jane Doe | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software. | |
| """ | |
| APACHE_TEXT = """ Apache License | |
| Version 2.0, January 2004 | |
| http://www.apache.org/licenses/ | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| """ | |
| BSD3_TEXT = """BSD 3-Clause License | |
| Copyright (c) 2026, Jane Doe | |
| Redistribution and use in source and binary forms, with or without | |
| modification, are permitted provided that the following conditions are met: | |
| 1. Redistributions of source code must retain the above copyright notice. | |
| 2. Redistributions in binary form must reproduce the above copyright notice. | |
| 3. Neither the name of the copyright holder nor the names of its contributors | |
| may be used to endorse or promote products derived from this software. | |
| """ | |
| BSD2_TEXT = """BSD 2-Clause License | |
| Copyright (c) 2026, Jane Doe | |
| Redistribution and use in source and binary forms, with or without | |
| modification, are permitted provided that the following conditions are met: | |
| 1. Redistributions of source code must retain the above copyright notice. | |
| 2. Redistributions in binary form must reproduce the above copyright notice. | |
| """ | |
| GPL3_TEXT = """ GNU GENERAL PUBLIC LICENSE | |
| Version 3, 29 June 2007 | |
| Copyright (C) 2007 Free Software Foundation, Inc. | |
| """ | |
| CC_BY_TEXT = """Creative Commons Attribution 4.0 International (CC BY 4.0) | |
| To view a copy of this license, visit | |
| https://creativecommons.org/licenses/by/4.0/ | |
| """ | |
| ISC_TEXT = """ISC License | |
| Copyright (c) 2026 Jane Doe | |
| Permission to use, copy, modify, and/or distribute this software for any | |
| purpose with or without fee is hereby granted. | |
| """ | |
| def test_detect_license_ids(): | |
| # The standard MIT license from issue 919 must be detected | |
| assert detect_license_ids(MIT_TEXT) == ["mit"] | |
| # Calkit's own dual license should yield both MIT and CC-BY-4.0 | |
| dual = LICENSE_TEMPLATE_DUAL.format(year=2026, copyright_holder="Jane Doe") | |
| assert detect_license_ids(dual) == ["mit", "cc-by-4.0"] | |
| # Other common single licenses | |
| assert detect_license_ids(APACHE_TEXT) == ["apache-2.0"] | |
| assert detect_license_ids(GPL3_TEXT) == ["gpl-3.0"] | |
| assert detect_license_ids(CC_BY_TEXT) == ["cc-by-4.0"] | |
| assert detect_license_ids(ISC_TEXT) == ["isc"] | |
| # The 3-clause and 2-clause BSD markers overlap; ensure they are | |
| # disambiguated by the "Neither the name of" clause | |
| assert detect_license_ids(BSD3_TEXT) == ["bsd-3-clause"] | |
| assert detect_license_ids(BSD2_TEXT) == ["bsd-2-clause"] | |
| # Line wrapping in the middle of a marker phrase should not matter | |
| wrapped = "MIT License\n\nPermission is hereby granted, free of\ncharge, " | |
| wrapped += "to any person obtaining a copy of this software" | |
| assert detect_license_ids(wrapped) == ["mit"] | |
| # Unknown or empty text yields nothing | |
| assert detect_license_ids("Totally custom proprietary license") == [] | |
| assert detect_license_ids("") == [] | |
| def test_find_license_file(tmp_dir): | |
| assert find_license_file() is None | |
| (tmp_dir / "LICENSE.md").write_text("MIT License") | |
| assert find_license_file() == "LICENSE.md" | |
| # A plain LICENSE file takes priority over other candidates | |
| (tmp_dir / "LICENSE").write_text("MIT License") | |
| assert find_license_file() == "LICENSE" | |
Xet Storage Details
- Size:
- 4 kB
- Xet hash:
- 7d152d9b1ba2a393ddd140524238a51ddd352eaaf202185476a81ceb55a0094e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.