| Total Complexity | 7 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # pyre-strict |
||
| 2 | |||
| 3 | """ |
||
| 4 | We use Pyre Check to prevent type errors. However, for Pyre Check to fail if |
||
| 5 | type declarations aren't "perfect", all files need to start with a "pyre-strict" |
||
| 6 | comment. This test checks that all Python files start with such a comment. |
||
| 7 | """ |
||
| 8 | |||
| 9 | import unittest |
||
| 10 | import os |
||
| 11 | |||
| 12 | |||
| 13 | class PyreStrictTest(unittest.TestCase): |
||
| 14 | """ |
||
| 15 | Check that all relevant Python files have Pyre set to strict mode. |
||
| 16 | """ |
||
| 17 | def test_strict_all_python_files(self) -> None: |
||
| 18 | """ |
||
| 19 | Check that all relevant Python files have Pyre set to strict mode. |
||
| 20 | """ |
||
| 21 | for directory, _directories, files in os.walk('.'): |
||
| 22 | for file in files: |
||
| 23 | if not file.endswith('.py'): |
||
| 24 | continue |
||
| 25 | |||
| 26 | path = os.path.join(directory, file) |
||
| 27 | |||
| 28 | if './lib/' in path: |
||
| 29 | # Prevent false positive in Scrutinizer. |
||
| 30 | continue |
||
| 31 | |||
| 32 | if './bin/activate_this.py' in path: |
||
| 33 | # Prevent false positive in Scrutinizer. |
||
| 34 | continue |
||
| 35 | |||
| 36 | with open(path) as current_file: |
||
| 37 | first_line: str = current_file.readline() |
||
| 38 | |||
| 39 | self.assertEqual( |
||
| 40 | first_line, |
||
| 41 | '# pyre-strict\n', |
||
| 42 | path + ' is not set to Pyre strict mode.', |
||
| 43 | ) |
||
| 44 |