MCPcopy
hub / github.com/saltstack/salt / test_module_name

Method test_module_name

tests/unit/test_module_names.py:66–102  ·  view source on GitHub ↗

Make sure all test modules conform to the test_*.py naming scheme

(self)

Source from the content-addressed store, hash-verified

64 return any(fnmatch.fnmatchcase(reldir, mdir) for mdir in matchdirs)
65
66 def test_module_name(self):
67 """
68 Make sure all test modules conform to the test_*.py naming scheme
69 """
70 excluded_dirs, included_dirs = tuple(EXCLUDED_DIRS), tuple(INCLUDED_DIRS)
71 tests_dir = os.path.join(RUNTIME_VARS.CODE_DIR, "tests")
72 bad_names = []
73 for root, _, files in salt.utils.path.os_walk(tests_dir):
74 reldir = os.path.relpath(root, RUNTIME_VARS.CODE_DIR)
75 if (
76 reldir.startswith(excluded_dirs)
77 and not self._match_dirs(reldir, included_dirs)
78 ) or reldir.endswith("__pycache__"):
79 continue
80 for fname in files:
81 if fname in ("__init__.py", "conftest.py") or not fname.endswith(".py"):
82 continue
83 relpath = os.path.join(reldir, fname)
84 if relpath in EXCLUDED_FILES:
85 continue
86 if not fname.startswith("test_"):
87 bad_names.append(relpath)
88
89 error_msg = "\n\nPlease rename the following files:\n"
90 for path in bad_names:
91 directory, filename = path.rsplit(os.sep, 1)
92 filename, _ = os.path.splitext(filename)
93 error_msg += " {} -> {}/test_{}.py\n".format(
94 path, directory, filename.split("_test")[0]
95 )
96
97 error_msg += (
98 "\nIf you believe one of the entries above should be ignored, please add it to either\n"
99 "'EXCLUDED_DIRS' or 'EXCLUDED_FILES' in 'tests/unit/test_module_names.py'.\n"
100 "If it is a tests module, then please rename as suggested."
101 )
102 self.assertEqual([], bad_names, error_msg)
103
104 def test_module_name_source_match(self):
105 """

Callers

nothing calls this directly

Calls 4

_match_dirsMethod · 0.95
formatMethod · 0.80
relpathMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected