diff --git a/psutil/tests/test_scripts.py b/psutil/tests/test_scripts.py index 41b5db4d5..79ca8a791 100755 --- a/psutil/tests/test_scripts.py +++ b/psutil/tests/test_scripts.py @@ -186,15 +186,26 @@ def test_sensors(self): reason="can't find scripts/internal/ directory", ) class TestInternalScripts(PsutilTestCase): - def test_syntax_all(self): + @staticmethod + def ls(): for name in os.listdir(INTERNAL_SCRIPTS_DIR): - if not name.endswith(".py"): - continue - path = os.path.join(INTERNAL_SCRIPTS_DIR, name) + if name.endswith(".py"): + yield os.path.join(INTERNAL_SCRIPTS_DIR, name) + + def test_syntax_all(self): + for path in self.ls(): with open(path, encoding="utf8") as f: data = f.read() ast.parse(data) + @pytest.mark.skipif(CI_TESTING, reason="not on CI") + def test_import_all(self): + for path in self.ls(): + try: + import_module_by_path(path) + except SystemExit: + pass + # =================================================================== # --- Tests for setup.py script diff --git a/scripts/internal/bench_oneshot_2.py b/scripts/internal/bench_oneshot_2.py index 1076dffc8..aa3ca78d1 100755 --- a/scripts/internal/bench_oneshot_2.py +++ b/scripts/internal/bench_oneshot_2.py @@ -11,27 +11,27 @@ import sys import pyperf # requires "pip install pyperf" -from bench_oneshot import names import psutil p = psutil.Process() -funs = [getattr(p, n) for n in names] -def call_normal(): +def call_normal(funs): for fun in funs: fun() -def call_oneshot(): +def call_oneshot(funs): with p.oneshot(): for fun in funs: fun() def main(): + from bench_oneshot import names + runner = pyperf.Runner() args = runner.parse_args() @@ -43,8 +43,10 @@ def main(): for name in sorted(names): print(" " + name) - runner.bench_func("normal", call_normal) - runner.bench_func("oneshot", call_oneshot) + funs = [getattr(p, n) for n in names] + runner.bench_func("normal", call_normal, funs) + runner.bench_func("oneshot", call_oneshot, funs) -main() +if __name__ == "__main__": + main() diff --git a/scripts/internal/git_pre_commit.py b/scripts/internal/git_pre_commit.py index 10f6368da..a47d7987e 100755 --- a/scripts/internal/git_pre_commit.py +++ b/scripts/internal/git_pre_commit.py @@ -166,4 +166,5 @@ def main(): ) -main() +if __name__ == "__main__": + main() diff --git a/scripts/internal/purge_installation.py b/scripts/internal/purge_installation.py index 55b2f5c50..254adabe0 100755 --- a/scripts/internal/purge_installation.py +++ b/scripts/internal/purge_installation.py @@ -38,4 +38,5 @@ def main(): rmpath(abspath) -main() +if __name__ == "__main__": + main()