Skip to content

Commit

Permalink
import all internal scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 20, 2024
1 parent e34aed8 commit c811489
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
19 changes: 15 additions & 4 deletions psutil/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions scripts/internal/bench_oneshot_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
3 changes: 2 additions & 1 deletion scripts/internal/git_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@ def main():
)


main()
if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion scripts/internal/purge_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ def main():
rmpath(abspath)


main()
if __name__ == "__main__":
main()

0 comments on commit c811489

Please sign in to comment.