|
@@ -0,0 +1,74 @@
|
|
|
|
|
+#!/usr/bin/env python3
|
|
|
|
|
+"""
|
|
|
|
|
+Comprehensive test for license detection to ensure our fix doesn't break other cases.
|
|
|
|
|
+"""
|
|
|
|
|
+
|
|
|
|
|
+import sys
|
|
|
|
|
+import os
|
|
|
|
|
+
|
|
|
|
|
+# Add src to path
|
|
|
|
|
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
|
+
|
|
|
|
|
+from autusm.metadata import MetadataExtractor
|
|
|
|
|
+
|
|
|
|
|
+def test_license_detection():
|
|
|
|
|
+ """Test license detection with various license texts."""
|
|
|
|
|
+ extractor = MetadataExtractor()
|
|
|
|
|
+
|
|
|
|
|
+ # Test cases: (description, content, expected_license)
|
|
|
|
|
+ test_cases = [
|
|
|
|
|
+ ("LGPL-2.1", """ GNU LESSER GENERAL PUBLIC LICENSE
|
|
|
|
|
+ Version 2.1, February 1999
|
|
|
|
|
+
|
|
|
|
|
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
|
|
|
|
+ Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
|
+ of this license document, but changing it is not allowed.""", "LGPL-2.1"),
|
|
|
|
|
+
|
|
|
|
|
+ ("GPL-3.0", """ GNU GENERAL PUBLIC LICENSE
|
|
|
|
|
+ Version 3, 29 June 2007
|
|
|
|
|
+
|
|
|
|
|
+ Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
|
+ Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
|
+ of this license document, but changing it is not allowed.""", "GPL-3.0"),
|
|
|
|
|
+
|
|
|
|
|
+ ("GPL-2.0", """ GNU GENERAL PUBLIC LICENSE
|
|
|
|
|
+ Version 2, June 1991
|
|
|
|
|
+
|
|
|
|
|
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
|
|
|
|
+ Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
|
+ of this license document, but changing it is not allowed.""", "GPL-2.0"),
|
|
|
|
|
+
|
|
|
|
|
+ ("MIT", """MIT License
|
|
|
|
|
+
|
|
|
|
|
+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, and to permit persons to whom the Software is
|
|
|
|
|
+furnished to do so, subject to the following conditions:""", "MIT"),
|
|
|
|
|
+
|
|
|
|
|
+ ("Apache-2.0", """Apache License
|
|
|
|
|
+Version 2.0, January 2004
|
|
|
|
|
+http://www.apache.org/licenses/
|
|
|
|
|
+
|
|
|
|
|
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION""", "Apache-2.0"),
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ print("Testing license detection...")
|
|
|
|
|
+ all_passed = True
|
|
|
|
|
+
|
|
|
|
|
+ for description, content, expected in test_cases:
|
|
|
|
|
+ result = extractor._identify_license_type(content)
|
|
|
|
|
+ status = "✓" if result == expected else "✗"
|
|
|
|
|
+ print(f"{status} {description}: Expected {expected}, Got {result}")
|
|
|
|
|
+ if result != expected:
|
|
|
|
|
+ all_passed = False
|
|
|
|
|
+
|
|
|
|
|
+ if all_passed:
|
|
|
|
|
+ print("\nAll tests passed!")
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("\nSome tests failed!")
|
|
|
|
|
+ sys.exit(1)
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
|
+ test_license_detection()
|