Skip to content

Commit ef5bc9e

Browse files
pb8obchalios
authored andcommitted
tests: make the copyright search more robust
Previously the script depended on hardcoded behavior, like for example expecting the copyright line to be the first line of a Python script, which would be a shebang. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 2cc1a33 commit ef5bc9e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/integration_tests/style/test_licenses.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def _validate_license(filename):
5050
Python and Rust files should have the licenses on the first 2 lines
5151
Shell files license is located on lines 3-4 to account for shebang
5252
"""
53-
with open(filename, "r+", encoding="utf-8") as file:
54-
if filename.endswith(".sh"):
55-
# Move iterator to third line without reading file into memory
56-
file.readline()
57-
file.readline()
58-
# The copyright message is always on the first line.
59-
copyright_info = file.readline()
53+
with open(filename, "r", encoding="utf-8") as file:
54+
# Find the copyright line
55+
while True:
56+
line = file.readline()
57+
if line.startswith(("// Copyright", "# Copyright")):
58+
copyright_info = line
59+
break
6060

6161
has_amazon_copyright = _has_amazon_copyright(
6262
copyright_info
@@ -104,8 +104,8 @@ def test_for_valid_licenses():
104104
error_msg = []
105105
for file in all_files:
106106
if _validate_license(file) is False:
107-
error_msg.append("{}".format(str(file)))
108-
assert not error_msg, "Files {} have invalid licenses".format((error_msg))
107+
error_msg.append(file)
108+
assert not error_msg, f"Files {error_msg} have invalid licenses"
109109

110110

111111
if __name__ == "__main__":

0 commit comments

Comments
 (0)