-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from sciencewhiz/AddTests
Add testing for examples
- Loading branch information
Showing
21 changed files
with
341 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) FIRST and other WPILib contributors. | ||
# Open Source Software; you can modify and/or share it under the terms of | ||
# the WPILib BSD license file in the root directory of this project. | ||
# | ||
|
||
from pathlib import Path | ||
|
||
|
||
def check_file_content(file_path): | ||
with open(file_path, "r") as file: | ||
lines = file.readlines() | ||
|
||
if file.name.endswith("robot.py"): | ||
expected_lines = [ | ||
"#!/usr/bin/env python3\n", | ||
"#\n", | ||
"# Copyright (c) FIRST and other WPILib contributors.\n", | ||
"# Open Source Software; you can modify and/or share it under the terms of\n", | ||
"# the WPILib BSD license file in the root directory of this project.\n", | ||
"#\n", | ||
"\n", | ||
] | ||
else: | ||
expected_lines = [ | ||
"#\n", | ||
"# Copyright (c) FIRST and other WPILib contributors.\n", | ||
"# Open Source Software; you can modify and/or share it under the terms of\n", | ||
"# the WPILib BSD license file in the root directory of this project.\n", | ||
"#\n", | ||
"\n", | ||
] | ||
|
||
if lines[: len(expected_lines)] != expected_lines: | ||
print( | ||
"\n".join( | ||
[ | ||
f"{file_path}", | ||
"ERROR: File must start with the following lines", | ||
"------------------------------", | ||
"".join(expected_lines[:-1]), | ||
"------------------------------", | ||
"Found:", | ||
"".join(lines[: len(expected_lines)]), | ||
"------------------------------", | ||
] | ||
) | ||
) | ||
|
||
return False | ||
return True | ||
|
||
|
||
def main(): | ||
current_directory = Path(__file__).parent | ||
python_files = [ | ||
x | ||
for x in current_directory.glob("./**/*.py") | ||
if not x.parent == current_directory and x.stat().st_size != 0 | ||
] | ||
|
||
non_compliant_files = [ | ||
file for file in python_files if not check_file_content(file) | ||
] | ||
|
||
non_compliant_files.sort() | ||
|
||
if non_compliant_files: | ||
print("Non-compliant files:") | ||
for file in non_compliant_files: | ||
print(f"- {file}") | ||
exit(1) # Exit with an error code | ||
else: | ||
print("All files are compliant.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.