test_license.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Test the license creation code"""
  2. import os
  3. import os.path as op
  4. import subprocess
  5. import shutil as sh
  6. import pytest
  7. curdir = op.dirname(op.abspath(__file__))
  8. def test_license():
  9. # Not yes/no answers should error
  10. if op.exists(op.join(curdir, "site", "content", "LICENSE.md")):
  11. os.remove(op.join(curdir, "site", "content", "LICENSE.md"))
  12. cmd_error = ["python", op.join(curdir, "..", "license.py"),
  13. "--path", op.join(curdir, "site", "content"), "--use-license", "blah"]
  14. out = subprocess.call(cmd_error)
  15. assert out == 1
  16. # Answering "yes" should add the CC-BY-SA license
  17. cmd_yes = ["python", op.join(curdir, "..", "license.py"),
  18. "--path", op.join(curdir, "site", "content"), "--use-license", "yes"]
  19. out = subprocess.call(cmd_yes)
  20. path_license = op.join(curdir, 'site', 'content', 'LICENSE.md')
  21. with open(path_license, 'r') as ff:
  22. license_text = ff.read()
  23. assert "Creative Commons Attribution-ShareAlike 4.0 International" in license_text
  24. os.remove(path_license)
  25. # Answering "no" should add an empty license"
  26. cmd_no = ["python", op.join(curdir, "..", "license.py"),
  27. "--path", op.join(curdir, "site", "content"), "--use-license", "no"]
  28. out = subprocess.call(cmd_no)
  29. with open(path_license, 'r') as ff:
  30. license_text = ff.read()
  31. assert len(license_text) == 0