MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / main

Function main

tensorflow/tools/pip_package/check_load_py_test.py:44–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43
44def main():
45 # Get all py_test target, note bazel query result will also include
46 # cuda_py_test etc.
47 try:
48 targets = subprocess.check_output([
49 'bazel', 'query',
50 'kind(py_test, //tensorflow/contrib/... + '
51 '//tensorflow/python/... - '
52 '//tensorflow/contrib/tensorboard/...)']).strip()
53 except subprocess.CalledProcessError as e:
54 targets = e.output
55 targets = targets.decode("utf-8") if isinstance(targets, bytes) else targets
56
57 # Only keep py_test targets, and filter out targets with 'no_pip' tag.
58 valid_targets = []
59 for target in targets.split('\n'):
60 kind = check_output_despite_error(['buildozer', 'print kind', target])
61 if kind == 'py_test':
62 tags = check_output_despite_error(['buildozer', 'print tags', target])
63 if 'no_pip' not in tags:
64 valid_targets.append(target)
65
66 # Get all BUILD files for all valid targets.
67 build_files = set()
68 for target in valid_targets:
69 build_files.add(os.path.join(target[2:].split(':')[0], 'BUILD'))
70
71 # Check if BUILD files load py_test.
72 files_missing_load = []
73 for build_file in build_files:
74 updated_build_file = subprocess.check_output(
75 ['buildozer', '-stdout', 'new_load //tensorflow:tensorflow.bzl py_test',
76 build_file])
77 with open(build_file, 'r') as f:
78 if f.read() != updated_build_file:
79 files_missing_load.append(build_file)
80
81 if files_missing_load:
82 raise RuntimeError('The following files are missing %s:\n %s' % (
83 'load("//tensorflow:tensorflow.bzl", "py_test").\nThis load statement'
84 ' is needed because otherwise pip tests will try to use their '
85 'dependencies, which are not visible to them.',
86 '\n'.join(files_missing_load)))
87 else:
88 print('TEST PASSED.')
89
90
91if __name__ == '__main__':

Callers 1

Calls 8

stripMethod · 0.80
decodeMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
addMethod · 0.45
joinMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected