test_unitywebgl.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from unittest import TestCase
  2. from docutils.core import publish_string
  3. from docutils.parsers.rst import directives
  4. from unitywebgl import config
  5. from unitywebgl.UnityGameDirective import UnityWebgl
  6. class TestUnityWebgl(TestCase):
  7. def test_directive_basic(self):
  8. # test directive html output with default template
  9. # and settings
  10. directives.register_directive('unitywebgl', UnityWebgl)
  11. config.GAMES_ROOT_DIR = '/test_games_root'
  12. config.TEMPLATE_PATH = '/test_template_path/template'
  13. config.DEFAULT_WIDTH = 960
  14. config.DEFAULT_HEIGHT = 600
  15. html =['<link rel="stylesheet" href="/test_template_path/template/style.css">',
  16. '<script src="/test_template_path/template/UnityProgress.js">',
  17. '<script src="/test_games_root/testgame/Build/UnityLoader.js">',
  18. '<script>\n var gameInstance = UnityLoader.instantiate("gameContainer", "/test_games_root/testgame/Build/testgame.json", {onProgress: UnityProgress});\n </script>',
  19. '<div id="gameContainer" style="width: 960px; height: 600px; left: 50%; transform: translateX(-50%);"></div>']
  20. res = publish_string('.. unitywebgl:: testgame', writer_name='html', settings_overrides={'output_encoding': 'unicode'})
  21. passed = True
  22. for line in html:
  23. if line not in res:
  24. passed = False
  25. break
  26. assert passed
  27. def test_directive_with_params(self):
  28. # test directive html output with all optional parameters,
  29. # default template and settings
  30. directives.register_directive('unitywebgl', UnityWebgl)
  31. config.GAMES_ROOT_DIR = 'test_games_root'
  32. config.TEMPLATE_PATH = 'test_template_path'
  33. config.DEFAULT_WIDTH = 960
  34. config.DEFAULT_HEIGHT = 600
  35. html =['<link rel="stylesheet" href="/games2/template2/style.css">',
  36. '<script src="/games2/template2/UnityProgress.js">',
  37. '<script src="/games2/testgame/Build/UnityLoader.js">',
  38. '<script>\n var gameInstance = UnityLoader.instantiate("gameContainer", "/games2/testgame/Build/testgame.json", {onProgress: UnityProgress});\n </script>',
  39. '<div id="gameContainer" style="width: 640px; height: 480px; left: 50%; transform: translateX(-50%);"></div>']
  40. d = '.. unitywebgl:: testgame\n\t:gameroot: /games2\n\t:template: /games2/template2\n\t:width: 640\n\t:height: 480'
  41. res = publish_string(d, writer_name='html', settings_overrides={'output_encoding': 'unicode'})
  42. passed = True
  43. for line in html:
  44. if line not in res:
  45. passed = False
  46. break
  47. assert passed