PageRenderTime 219ms CodeModel.GetById 92ms RepoModel.GetById 13ms app.codeStats 0ms

/hyde/tests/ext/test_uglify.py

http://github.com/hyde/hyde
Python | 78 lines | 54 code | 15 blank | 9 comment | 0 complexity | 96c1468d2730e6019495e5de8b28f692 MD5 | raw file
Possible License(s): MIT
  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.model import Expando
  8. from hyde.generator import Generator
  9. from hyde.site import Site
  10. from fswrap import File, Folder
  11. from hyde.tests.util import assert_no_diff
  12. UGLIFY_SOURCE = File(__file__).parent.child_folder('uglify')
  13. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  14. class TestUglify(object):
  15. def setUp(self):
  16. TEST_SITE.make()
  17. TEST_SITE.parent.child_folder(
  18. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  19. JS = TEST_SITE.child_folder('content/media/js')
  20. JS.make()
  21. UGLIFY_SOURCE.copy_contents_to(JS)
  22. def tearDown(self):
  23. TEST_SITE.delete()
  24. def test_can_uglify(self):
  25. s = Site(TEST_SITE)
  26. s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
  27. s.config.mode = "production"
  28. source = TEST_SITE.child('content/media/js/jquery.js')
  29. target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
  30. gen = Generator(s)
  31. gen.generate_resource_at_path(source)
  32. assert target.exists
  33. expected = UGLIFY_SOURCE.child_file('expected-jquery.js').read_all()
  34. # TODO: Very fragile. Better comparison needed.
  35. text = target.read_all()
  36. assert_no_diff(expected, text)
  37. def test_uglify_with_extra_options(self):
  38. s = Site(TEST_SITE)
  39. s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
  40. s.config.mode = "production"
  41. s.config.uglify = Expando(dict(args={"comments":"/http\:\/\/jquery.org\/license/"}))
  42. source = TEST_SITE.child('content/media/js/jquery.js')
  43. target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
  44. gen = Generator(s)
  45. gen.generate_resource_at_path(source)
  46. assert target.exists
  47. expected = UGLIFY_SOURCE.child_file('expected-jquery-nc.js').read_all()
  48. # TODO: Very fragile. Better comparison needed.
  49. text = target.read_all()
  50. assert_no_diff(expected, text)
  51. def test_no_uglify_in_dev_mode(self):
  52. s = Site(TEST_SITE)
  53. s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
  54. s.config.mode = "dev"
  55. source = TEST_SITE.child('content/media/js/jquery.js')
  56. target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
  57. gen = Generator(s)
  58. gen.generate_resource_at_path(source)
  59. assert target.exists
  60. expected = UGLIFY_SOURCE.child_file('jquery.js').read_all()
  61. # TODO: Very fragile. Better comparison needed.
  62. text = target.read_all()
  63. assert_no_diff(expected, text)