test_metadata_max_length.py 930 B

12345678910111213141516171819202122232425
  1. # Checks related to patch line lengths
  2. #
  3. # Copyright (C) 2016 Intel Corporation
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. import base
  7. import pyparsing
  8. class MaxLength(base.Base):
  9. add_mark = pyparsing.Regex('\+ ')
  10. max_length = 200
  11. def test_max_line_length(self):
  12. for patch in self.patchset:
  13. # for the moment, we are just interested in metadata
  14. if patch.path.endswith('.patch'):
  15. continue
  16. payload = str(patch)
  17. for line in payload.splitlines():
  18. if self.add_mark.search_string(line):
  19. current_line_length = len(line[1:])
  20. if current_line_length > self.max_length:
  21. self.fail('Patch line too long (current length %s, maximum is %s)' % (current_line_length, self.max_length),
  22. data=[('Patch', patch.path), ('Line', '%s ...' % line[0:80])])