Lines Matching +full:self +full:- +full:test

1 # SPDX-License-Identifier: GPL-2.0
9 This provides fixture functions commonly used from test files.
24 This class provides methods to run text-based interface of Kconfig
30 def __init__(self, request): argument
33 request: object to introspect the requesting test module
35 # the directory of the test being run
36 self._test_dir = os.path.dirname(str(request.fspath))
39 def _run_conf(self, mode, dot_config=None, out_file='.config', argument
41 """Run text-based Kconfig executable and save the result.
43 mode: input mode option (--oldaskconfig, --defconfig=<file> etc.)
53 # Override 'srctree' environment to make the test as the top directory
54 extra_env['srctree'] = self._test_dir
66 shutil.copyfile(os.path.join(self._test_dir, dot_config),
78 ps.stdin.write(in_keys.encode('utf-8'))
86 self.retcode = ps.returncode
87 self.stdout = ps.stdout.read().decode()
88 self.stderr = ps.stderr.read().decode()
93 if self.retcode == 0 and out_file:
95 self.config = f.read()
97 self.config = None
106 print("[retcode]\n{}\n".format(self.retcode))
109 print(self.stdout)
112 print(self.stderr)
114 if self.config is not None:
116 print(self.config)
118 return self.retcode
120 def oldaskconfig(self, dot_config=None, in_keys=None): argument
127 return self._run_conf('--oldaskconfig', dot_config=dot_config,
130 def oldconfig(self, dot_config=None, in_keys=None): argument
137 return self._run_conf('--oldconfig', dot_config=dot_config,
140 def olddefconfig(self, dot_config=None): argument
146 return self._run_conf('--olddefconfig', dot_config=dot_config)
148 def defconfig(self, defconfig): argument
154 defconfig_path = os.path.join(self._test_dir, defconfig)
155 return self._run_conf('--defconfig={}'.format(defconfig_path))
157 def _allconfig(self, mode, all_config, extra_env={}): argument
159 all_config_path = os.path.join(self._test_dir, all_config)
162 return self._run_conf('--{}config'.format(mode), extra_env=extra_env)
164 def allyesconfig(self, all_config=None): argument
170 return self._allconfig('allyes', all_config)
172 def allmodconfig(self, all_config=None): argument
178 return self._allconfig('allmod', all_config)
180 def allnoconfig(self, all_config=None): argument
186 return self._allconfig('allno', all_config)
188 def alldefconfig(self, all_config=None): argument
194 return self._allconfig('alldef', all_config)
196 def randconfig(self, all_config=None, seed=None): argument
208 return self._allconfig('rand', all_config, extra_env=extra_env)
210 def savedefconfig(self, dot_config): argument
216 return self._run_conf('--savedefconfig', out_file='defconfig')
218 def listnewconfig(self, dot_config=None): argument
224 return self._run_conf('--listnewconfig', dot_config=dot_config,
228 def _read_and_compare(self, compare, expected): argument
234 with open(os.path.join(self._test_dir, expected)) as f:
236 return compare(self, expected_data)
238 def _contains(self, attr, expected): argument
239 return self._read_and_compare(
243 def _matches(self, attr, expected): argument
244 return self._read_and_compare(lambda s, e: getattr(s, attr) == e,
247 def config_contains(self, expected): argument
253 return self._contains('config', expected)
255 def config_matches(self, expected): argument
261 return self._matches('config', expected)
263 def stdout_contains(self, expected): argument
269 return self._contains('stdout', expected)
271 def stdout_matches(self, expected): argument
277 return self._matches('stdout', expected)
279 def stderr_contains(self, expected): argument
285 return self._contains('stderr', expected)
287 def stderr_matches(self, expected): argument
293 return self._matches('stderr', expected)
298 """Create a Conf instance and provide it to test functions."""