depswriter_test.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2010 The Closure Library Authors. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS-IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Unit test for depswriter."""
  17. __author__ = 'johnlenz@google.com (John Lenz)'
  18. import unittest
  19. import depswriter
  20. class MockSource(object):
  21. """Mock Source file."""
  22. def __init__(self, provides, requires):
  23. self.provides = set(provides)
  24. self.requires = set(requires)
  25. self.is_goog_module = False
  26. def __repr__(self):
  27. return 'MockSource %s' % self.provides
  28. class DepsWriterTestCase(unittest.TestCase):
  29. """Unit test for depswriter."""
  30. def testMakeDepsFile(self):
  31. sources = {}
  32. sources['test.js'] = MockSource(['A'], ['B', 'C'])
  33. deps = depswriter.MakeDepsFile(sources)
  34. self.assertEqual(
  35. 'goog.addDependency(\'test.js\', [\'A\'], [\'B\', \'C\'], false);\n',
  36. deps)
  37. def testMakeDepsFileUnicode(self):
  38. sources = {}
  39. sources['test.js'] = MockSource([u'A'], [u'B', u'C'])
  40. deps = depswriter.MakeDepsFile(sources)
  41. self.assertEqual(
  42. 'goog.addDependency(\'test.js\', [\'A\'], [\'B\', \'C\'], false);\n',
  43. deps)
  44. if __name__ == '__main__':
  45. unittest.main()