Skip to content

Commit

Permalink
test (diracx): generate-test-file warns about potentially unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Nov 29, 2023
1 parent 8110a73 commit 3d76331
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/Integration/FutureClient/generate-test-file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect
import importlib
from itertools import zip_longest
import subprocess

BASE_EXPORTS = {"export_whoami", "export_refreshConfiguration", "export_ping", "export_echo"}

Expand All @@ -23,6 +24,8 @@ def main(system, component):
importlib.import_module(f"DIRAC.{system}System.Service.{component}Handler"), f"{component}Handler"
)

dirac_location = importlib.import_module("DIRAC").__path__[0]

print("from functools import partial")
print()
print("import pytest")
Expand Down Expand Up @@ -53,7 +56,15 @@ def main(system, component):
else:
default = f" = {parameter.default}"
type_infos += [f"{parameter.name}{dtype}{default}"]

cmd_check_used = ["grep", "-R", rf"\.{method_name}(", dirac_location]

res = subprocess.run(cmd_check_used, capture_output=True)
is_method_used = bool(res.stdout)

print(f"def test_{method_name}(monkeypatch):")
if not is_method_used:
print(f" # WARNING: possibly unused")
print(f" # {client_name}().{method_name}({', '.join(type_infos)})")
print(f" method = {client_name}().{method_name}")
print(f" pytest.skip()")
Expand Down

0 comments on commit 3d76331

Please sign in to comment.