test_license_comprehensive.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python3
  2. """
  3. Comprehensive test for license detection to ensure our fix doesn't break other cases.
  4. """
  5. import sys
  6. import os
  7. # Add src to path
  8. sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
  9. from autusm.metadata import MetadataExtractor
  10. def test_license_detection():
  11. """Test license detection with various license texts."""
  12. extractor = MetadataExtractor()
  13. # Test cases: (description, content, expected_license)
  14. test_cases = [
  15. ("LGPL-2.1", """ GNU LESSER GENERAL PUBLIC LICENSE
  16. Version 2.1, February 1999
  17. Copyright (C) 1991, 1999 Free Software Foundation, Inc.
  18. Everyone is permitted to copy and distribute verbatim copies
  19. of this license document, but changing it is not allowed.""", "LGPL-2.1"),
  20. ("GPL-3.0", """ GNU GENERAL PUBLIC LICENSE
  21. Version 3, 29 June 2007
  22. Copyright (C) 2007 Free Software Foundation, Inc.
  23. Everyone is permitted to copy and distribute verbatim copies
  24. of this license document, but changing it is not allowed.""", "GPL-3.0"),
  25. ("GPL-2.0", """ GNU GENERAL PUBLIC LICENSE
  26. Version 2, June 1991
  27. Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  28. Everyone is permitted to copy and distribute verbatim copies
  29. of this license document, but changing it is not allowed.""", "GPL-2.0"),
  30. ("MIT", """MIT License
  31. Permission is hereby granted, free of charge, to any person obtaining a copy
  32. of this software and associated documentation files (the "Software"), to deal
  33. in the Software without restriction, including without limitation the rights
  34. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  35. copies of the Software, and to permit persons to whom the Software is
  36. furnished to do so, subject to the following conditions:""", "MIT"),
  37. ("Apache-2.0", """Apache License
  38. Version 2.0, January 2004
  39. http://www.apache.org/licenses/
  40. TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION""", "Apache-2.0"),
  41. ]
  42. print("Testing license detection...")
  43. all_passed = True
  44. for description, content, expected in test_cases:
  45. result = extractor._identify_license_type(content)
  46. status = "✓" if result == expected else "✗"
  47. print(f"{status} {description}: Expected {expected}, Got {result}")
  48. if result != expected:
  49. all_passed = False
  50. if all_passed:
  51. print("\nAll tests passed!")
  52. else:
  53. print("\nSome tests failed!")
  54. sys.exit(1)
  55. if __name__ == "__main__":
  56. test_license_detection()