boilerplate_test.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # Copyright 2016 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import boilerplate
  16. import unittest
  17. from io import StringIO
  18. import os
  19. import sys
  20. class TestBoilerplate(unittest.TestCase):
  21. """
  22. Note: run this test from the hack/boilerplate directory.
  23. $ python -m unittest boilerplate_test
  24. """
  25. def test_boilerplate(self):
  26. os.chdir("test/")
  27. class Args(object):
  28. def __init__(self):
  29. self.filenames = []
  30. self.rootdir = "."
  31. self.boilerplate_dir = "../"
  32. self.verbose = True
  33. # capture stdout
  34. old_stdout = sys.stdout
  35. sys.stdout = StringIO.StringIO()
  36. boilerplate.args = Args()
  37. ret = boilerplate.main()
  38. output = sorted(sys.stdout.getvalue().split())
  39. sys.stdout = old_stdout
  40. self.assertEquals(
  41. output, ['././fail.go', '././fail.py'])