sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/hack/boilerplate/boilerplate_test.py (about)

     1  #!/usr/bin/env python
     2  
     3  # Copyright 2016 The Kubernetes Authors.
     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  
    17  import boilerplate
    18  import unittest
    19  import StringIO
    20  import os
    21  import sys
    22  
    23  class TestBoilerplate(unittest.TestCase):
    24    """
    25    Note: run this test from the hack/boilerplate directory.
    26  
    27    $ python -m unittest boilerplate_test
    28    """
    29  
    30    def test_boilerplate(self):
    31      os.chdir("test/")
    32  
    33      class Args(object):
    34        def __init__(self):
    35          self.filenames = []
    36          self.rootdir = "."
    37          self.boilerplate_dir = "../"
    38          self.verbose = True
    39  
    40      # capture stdout
    41      old_stdout = sys.stdout
    42      sys.stdout = StringIO.StringIO()
    43  
    44      boilerplate.args = Args()
    45      ret = boilerplate.main()
    46  
    47      output = sorted(sys.stdout.getvalue().split())
    48  
    49      sys.stdout = old_stdout
    50  
    51      self.assertEquals(
    52          output, ['././fail.go', '././fail.py'])