Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / tests / git / test_find_debug_print.py
blob5536b41e7488f53bf1f645d4df394caa017ece20
1 #!/usr/bin/python
2 # encoding: utf-8
4 import os
5 import glob
6 from testlib import cmk_path, cmc_path, cme_path
8 check_paths = [
9 "bin",
10 "cmk_base",
11 "cmk_base/cee",
12 "cmk_base/cme",
13 "cmk_base/modes",
14 "cmk_base/default_config",
15 "lib",
16 "checks",
17 "inventory",
18 "notifications",
19 "active_checks",
20 # CMC specific
21 "agents/bakery",
22 # TODO: Update all agent plugins to use sys.stdout.write instead of print
23 "agents/plugins",
27 exclude_folders = [
28 "plugins/build",
29 "plugins/build_32",
30 "chroot"
33 def test_find_debug_code():
34 scanned = 0
35 for base_path in [ cmk_path(), cmc_path(), cme_path() ]:
36 for dir_path in check_paths:
37 path = "%s/%s" % (base_path, dir_path)
38 if not os.path.exists(path):
39 continue
41 for dirpath, dirnames, filenames in os.walk(path):
42 scanned += 1
43 for filename in filenames:
44 file_path = "%s/%s" % (dirpath, filename)
45 if [folder in file_path for folder in exclude_folders]:
46 continue
48 for nr, line in enumerate(open(file_path)):
49 if nr == 0 and ("bash" in line or "php" in line):
50 break # skip non python files
52 l = line.lstrip()
53 assert not l.startswith("print("), \
54 "Found \"print(...)\" call in %s:%d" % \
55 (file_path, nr+1)
56 assert not l.startswith("pprint.pprint("), \
57 "Found \"print(...)\" call in %s:%d" % \
58 (file_path, nr+1)
59 assert not l.startswith("pprint("), \
60 "Found \"print(...)\" call in %s:%d" % \
61 (file_path, nr+1)
62 assert not l.startswith("print "), \
63 "Found \"print ...\" call in %s:%d" % \
64 (file_path, nr+1)
66 assert scanned > 0