How to use check_usage method in pytest-mozwebqa

Best Python code snippet using pytest-mozwebqa_python

test_path_system.py

Source:test_path_system.py Github

copy

Full Screen

...44 self.clear_pkgdir()45 def clear_pkgdir(self):46 if os.path.exists(self.pkgdir):47 shutil.rmtree(self.pkgdir)48 def check_usage(self, usage, *, name='foo', auto_link=False,49 dependencies=[], include_path=[], library_path=[],50 headers=[], libraries=None, compile_flags=[],51 link_flags=[]):52 if libraries is None:53 libraries = [name]54 self.assertEqual(usage.auto_link, auto_link)55 self.assertEqual(usage.dependencies, dependencies)56 self.assertEqual(usage.include_path, include_path)57 self.assertEqual(usage.library_path, library_path)58 self.assertEqual(usage.headers, headers)59 self.assertEqual(usage.libraries, libraries)60 self.assertEqual(usage.compile_flags, ShellArguments(compile_flags))61 self.assertEqual(usage.link_flags, ShellArguments(link_flags))62 def check_version(self, usage, expected=None, *, pkg=None, header=None):63 # XXX: Remove this after we drop support for Python 3.6.64 if header and sys.version_info < (3, 7):65 warnings.warn('mock_open() fails to iterate in Python 3.6')66 return67 open_args = ({'new': mock.mock_open(read_data=header)} if header68 else {'side_effect': AssertionError()})69 if pkg is None:70 pkg = MockPackage()71 with mock.patch('subprocess.run', side_effect=OSError()), \72 mock.patch('mopack.usage.path_system._system_include_path',73 return_value=[Path('/mock/include')]), \74 mock.patch('mopack.usage.path_system.isfile', mock_isfile), \75 mock.patch('builtins.open', **open_args):76 self.assertEqual(usage.version(self.metadata, pkg), expected)77 def check_get_usage(self, usage, name, submodules, expected=None, *,78 pkg=None, metadata=None, write_pkg_config=True):79 depname = dependency_string(name, submodules)80 if expected is None:81 expected = {'name': depname, 'type': self.type, 'generated': True,82 'auto_link': False, 'pcnames': [depname],83 'pkg_config_path': [self.pkgconfdir]}84 if pkg is None:85 pkg = MockPackage(name)86 if metadata is None:87 metadata = self.metadata88 self.clear_pkgdir()89 with mock.patch('mopack.usage.path_system.file_outdated',90 return_value=write_pkg_config), \91 mock.patch('mopack.usage.path_system._system_include_path',92 return_value=[Path('/mock/include')]), \93 mock.patch('mopack.usage.path_system._system_lib_path',94 return_value=[Path('/mock/lib')]), \95 mock.patch('mopack.usage.path_system._system_lib_names',96 return_value=['lib{}.so']), \97 mock.patch('mopack.usage.path_system.isfile',98 mock_isfile):99 self.assertEqual(usage.get_usage(metadata, pkg, submodules),100 expected)101 def check_pkg_config(self, name, submodules, expected={}):102 pcname = dependency_string(name, submodules)103 self.assertCountEqual(104 call_pkg_config(pcname, ['--cflags'], path=self.pkgconfdir),105 expected.get('cflags', [])106 )107 self.assertCountEqual(108 call_pkg_config(pcname, ['--libs'], path=self.pkgconfdir),109 expected.get('libs', ['-L' + abspath('/mock/lib'), '-l' + name])110 )111 self.assertEqual(112 call_pkg_config(pcname, ['--modversion'], path=self.pkgconfdir,113 split=False),114 expected.get('version', '')115 )116 def test_basic(self):117 usage = self.make_usage('foo')118 self.check_usage(usage)119 self.check_get_usage(usage, 'foo', None)120 self.check_pkg_config('foo', None)121 def test_pkg_config_up_to_date(self):122 usage = self.make_usage('foo')123 self.check_usage(usage)124 self.check_get_usage(usage, 'foo', None, write_pkg_config=False)125 self.assertFalse(os.path.exists(126 os.path.join(self.pkgconfdir, 'foo.pc')127 ))128 def test_auto_link(self):129 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)130 usage = self.make_usage('foo', auto_link=True)131 self.check_usage(usage, auto_link=True, libraries=[])132 self.check_get_usage(usage, 'foo', None, {133 'name': 'foo', 'type': self.type, 'generated': True,134 'auto_link': True, 'pcnames': ['foo'],135 'pkg_config_path': [self.pkgconfdir],136 }, pkg=pkg)137 self.check_pkg_config('foo', None, {138 'libs': ['-L' + abspath('/mock/lib')],139 })140 libdir = abspath('/mock/path/to/lib')141 usage = self.make_usage('foo', auto_link=True,142 library_path='/mock/path/to/lib')143 self.check_usage(usage, auto_link=True, libraries=[],144 library_path=[abspathobj('/mock/path/to/lib')])145 self.check_get_usage(usage, 'foo', None, {146 'name': 'foo', 'type': self.type, 'generated': True,147 'auto_link': True, 'pcnames': ['foo'],148 'pkg_config_path': [self.pkgconfdir],149 }, pkg=pkg)150 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir]})151 def test_version(self):152 usage = self.make_usage('foo', version='1.0')153 self.check_usage(usage)154 self.check_version(usage, '1.0')155 self.check_get_usage(usage, 'foo', None)156 self.check_pkg_config('foo', None, {'version': '1.0'})157 self.check_version(usage, '1.0', pkg=MockPackage(version='2.0'))158 self.check_get_usage(usage, 'foo', None)159 self.check_pkg_config('foo', None, {'version': '1.0'})160 usage = self.make_usage('foo')161 self.check_version(usage, '2.0', pkg=MockPackage(version='2.0'))162 self.check_get_usage(usage, 'foo', None,163 pkg=MockPackage(version='2.0'))164 self.check_pkg_config('foo', None, {'version': '2.0'})165 def test_version_regex(self):166 good_header = dedent("""\167 // This is a header168 #define VERSION "1.0"169 """)170 uscore_header = dedent("""\171 // This is a header172 #define VERSION "1_0"173 """)174 bad_header = dedent("""\175 // This is a header176 """)177 usage = self.make_usage('foo', headers=['foo.hpp'], version={178 'type': 'regex',179 'file': 'foo.hpp',180 'regex': [r'#define VERSION "([\d\.]+)"']181 })182 self.check_usage(usage, headers=['foo.hpp'])183 self.check_version(usage, '1.0', header=good_header)184 self.check_version(usage, None, header=bad_header)185 usage = self.make_usage('foo', headers=['foo.hpp'], version={186 'type': 'regex',187 'file': 'foo.hpp',188 'regex': [r'#define VERSION "([\d_]+)"',189 ['_', '.']]190 })191 self.check_usage(usage, headers=['foo.hpp'])192 self.check_version(usage, '1.0', header=uscore_header)193 self.check_version(usage, None, header=bad_header)194 def test_invalid_version(self):195 with self.assertRaises(FieldValueError):196 self.make_usage('foo', version={'type': 'goofy'})197 def test_dependencies(self):198 usage = self.make_usage('foo', dependencies=['bar'])199 self.check_usage(usage, dependencies=[('bar', None)])200 self.check_get_usage(usage, 'foo', None)201 self.check_pkg_config('foo', None, {202 'libs': ['-L' + abspath('/mock/lib'), '-lfoo', '-lbar'],203 })204 path = '/mock/pkgconfig'205 dep_usage = {'name': 'foo', 'type': self.type, 'generated': True,206 'auto_link': True, 'pcnames': ['bar'],207 'pkg_config_path': [path]}208 with mock.patch('mopack.sources.Package.get_usage',209 return_value=dep_usage):210 self.check_get_usage(usage, 'foo', None, {211 'name': 'foo', 'type': self.type, 'generated': True,212 'auto_link': True, 'pcnames': ['foo'],213 'pkg_config_path': [self.pkgconfdir, path],214 })215 def test_include_path_relative(self):216 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)217 incdir = os.path.join(self.srcdir, 'include')218 usage = self.make_usage('foo', include_path='include',219 headers=['foo.hpp'])220 self.check_usage(usage, include_path=[srcpathobj('include')],221 headers=['foo.hpp'])222 self.check_get_usage(usage, 'foo', None, pkg=pkg)223 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})224 usage = self.make_usage('foo', include_path=['include'],225 headers=['foo.hpp'])226 self.check_usage(usage, include_path=[srcpathobj('include')],227 headers=['foo.hpp'])228 self.check_get_usage(usage, 'foo', None, pkg=pkg)229 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})230 def test_include_path_srcdir(self):231 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)232 incdir = os.path.join(self.srcdir, 'include')233 usage = self.make_usage('foo', include_path='$srcdir/include',234 headers=['foo.hpp'])235 self.check_usage(usage, include_path=[srcpathobj('include')],236 headers=['foo.hpp'])237 self.check_get_usage(usage, 'foo', None, pkg=pkg)238 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})239 usage = self.make_usage('foo', include_path=['$srcdir/include'],240 headers=['foo.hpp'])241 self.check_usage(usage, include_path=[srcpathobj('include')],242 headers=['foo.hpp'])243 self.check_get_usage(usage, 'foo', None, pkg=pkg)244 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})245 def test_include_path_builddir(self):246 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)247 incdir = os.path.join(self.builddir, 'include')248 usage = self.make_usage('foo', include_path='$builddir/include',249 headers=['foo.hpp'])250 self.check_usage(usage, include_path=[buildpathobj('include')],251 headers=['foo.hpp'])252 self.check_get_usage(usage, 'foo', None, pkg=pkg)253 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})254 usage = self.make_usage('foo', include_path=['$builddir/include'],255 headers=['foo.hpp'])256 self.check_usage(usage, include_path=[buildpathobj('include')],257 headers=['foo.hpp'])258 self.check_get_usage(usage, 'foo', None, pkg=pkg)259 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})260 def test_include_path_absolute(self):261 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)262 incdir = abspath('/mock/path/to/include')263 incdirobj = abspathobj('/mock/path/to/include')264 usage = self.make_usage('foo', include_path='/mock/path/to/include',265 headers=['foo.hpp'])266 self.check_usage(usage, include_path=[incdirobj], headers=['foo.hpp'])267 self.check_get_usage(usage, 'foo', None, pkg=pkg)268 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})269 usage = self.make_usage('foo', include_path='/mock/path/to/include',270 headers=['foo.hpp'])271 self.check_usage(usage, include_path=[incdirobj], headers=['foo.hpp'])272 self.check_get_usage(usage, 'foo', None)273 self.check_pkg_config('foo', None, {'cflags': ['-I' + incdir]})274 def test_invalid_include_path(self):275 with self.assertRaises(FieldValueError):276 self.make_usage('foo', include_path='../include')277 def test_library_path_relative(self):278 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)279 libdir = os.path.join(self.builddir, 'lib')280 usage = self.make_usage('foo', library_path='lib')281 self.check_usage(usage, library_path=[buildpathobj('lib')])282 self.check_get_usage(usage, 'foo', None, pkg=pkg)283 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})284 usage = self.make_usage('foo', library_path=['lib'])285 self.check_usage(usage, library_path=[buildpathobj('lib')])286 self.check_get_usage(usage, 'foo', None, pkg=pkg)287 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})288 def test_library_path_srcdir(self):289 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)290 libdir = os.path.join(self.srcdir, 'lib')291 usage = self.make_usage('foo', library_path='$srcdir/lib')292 self.check_usage(usage, library_path=[srcpathobj('lib')])293 self.check_get_usage(usage, 'foo', None, pkg=pkg)294 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})295 usage = self.make_usage('foo', library_path=['$srcdir/lib'])296 self.check_usage(usage, library_path=[srcpathobj('lib')])297 self.check_get_usage(usage, 'foo', None, pkg=pkg)298 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})299 def test_library_path_builddir(self):300 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)301 libdir = os.path.join(self.builddir, 'lib')302 usage = self.make_usage('foo', library_path='$builddir/lib')303 self.check_usage(usage, library_path=[buildpathobj('lib')])304 self.check_get_usage(usage, 'foo', None, pkg=pkg)305 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})306 usage = self.make_usage('foo', library_path=['$builddir/lib'])307 self.check_usage(usage, library_path=[buildpathobj('lib')])308 self.check_get_usage(usage, 'foo', None, pkg=pkg)309 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})310 def test_library_path_absolute(self):311 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir)312 libdir = abspath('/mock/path/to/lib')313 usage = self.make_usage('foo', library_path='/mock/path/to/lib')314 self.check_usage(usage, library_path=[abspathobj('/mock/path/to/lib')])315 self.check_get_usage(usage, 'foo', None, pkg=pkg)316 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})317 usage = self.make_usage('foo', library_path='/mock/path/to/lib')318 self.check_usage(usage, library_path=[abspathobj('/mock/path/to/lib')])319 self.check_get_usage(usage, 'foo', None)320 self.check_pkg_config('foo', None, {'libs': ['-L' + libdir, '-lfoo']})321 def test_invalid_library_path(self):322 with self.assertRaises(FieldValueError):323 self.make_usage('foo', library_path='../lib')324 def test_headers(self):325 usage = self.make_usage('foo', headers='foo.hpp')326 self.check_usage(usage, headers=['foo.hpp'])327 self.check_get_usage(usage, 'foo', None)328 self.check_pkg_config('foo', None, {329 'cflags': ['-I' + abspath('/mock/include')],330 })331 usage = self.make_usage('foo', headers=['foo.hpp'])332 self.check_usage(usage, headers=['foo.hpp'])333 self.check_get_usage(usage, 'foo', None)334 self.check_pkg_config('foo', None, {335 'cflags': ['-I' + abspath('/mock/include')],336 })337 def test_libraries(self):338 usage = self.make_usage('foo', libraries='bar')339 self.check_usage(usage, libraries=['bar'])340 self.check_get_usage(usage, 'foo', None)341 self.check_pkg_config('foo', None, {342 'libs': ['-L' + abspath('/mock/lib'), '-lbar'],343 })344 usage = self.make_usage('foo', libraries=['bar'])345 self.check_usage(usage, libraries=['bar'])346 self.check_get_usage(usage, 'foo', None)347 self.check_pkg_config('foo', None, {348 'libs': ['-L' + abspath('/mock/lib'), '-lbar'],349 })350 usage = self.make_usage('foo', libraries=None)351 self.check_usage(usage, libraries=[])352 self.check_get_usage(usage, 'foo', None)353 self.check_pkg_config('foo', None, {'libs': []})354 usage = self.make_usage('foo', libraries=[355 {'type': 'library', 'name': 'bar'},356 ])357 self.check_usage(usage, libraries=['bar'])358 self.check_get_usage(usage, 'foo', None)359 self.check_pkg_config('foo', None, {360 'libs': ['-L' + abspath('/mock/lib'), '-lbar'],361 })362 usage = self.make_usage('foo', libraries=[363 {'type': 'framework', 'name': 'bar'},364 ])365 self.check_usage(usage, libraries=[366 {'type': 'framework', 'name': 'bar'},367 ])368 self.check_get_usage(usage, 'foo', None)369 self.check_pkg_config('foo', None, {'libs': ['-framework', 'bar']})370 def test_compile_flags(self):371 usage = self.make_usage('foo', compile_flags='-pthread -fPIC')372 self.check_usage(usage, compile_flags=['-pthread', '-fPIC'])373 self.check_get_usage(usage, 'foo', None)374 self.check_pkg_config('foo', None, {'cflags': ['-pthread', '-fPIC']})375 usage = self.make_usage('foo', compile_flags=['-pthread', '-fPIC'])376 self.check_usage(usage, compile_flags=['-pthread', '-fPIC'])377 self.check_get_usage(usage, 'foo', None)378 self.check_pkg_config('foo', None, {'cflags': ['-pthread', '-fPIC']})379 def test_link_flags(self):380 usage = self.make_usage('foo', link_flags='-pthread -fPIC')381 self.check_usage(usage, link_flags=['-pthread', '-fPIC'])382 self.check_get_usage(usage, 'foo', None)383 self.check_pkg_config('foo', None, {384 'libs': ['-pthread', '-fPIC', '-L' + abspath('/mock/lib'),385 '-lfoo'],386 })387 usage = self.make_usage('foo', link_flags=['-pthread', '-fPIC'])388 self.check_usage(usage, link_flags=['-pthread', '-fPIC'])389 self.check_get_usage(usage, 'foo', None)390 self.check_pkg_config('foo', None, {391 'libs': ['-pthread', '-fPIC', '-L' + abspath('/mock/lib'),392 '-lfoo'],393 })394 def test_submodules(self):395 submodules_required = {'names': '*', 'required': True}396 submodules_optional = {'names': '*', 'required': False}397 pkg = MockPackage('foo', submodules=submodules_required,398 _options=self.make_options())399 usage = self.make_usage(pkg)400 self.check_usage(usage, libraries=[])401 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)402 self.check_pkg_config('foo', ['sub'], {403 'libs': ['-L' + abspath('/mock/lib'), '-lfoo_sub'],404 })405 usage = self.make_usage(pkg, libraries=['bar'])406 self.check_usage(usage, libraries=['bar'])407 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)408 self.check_pkg_config('foo', ['sub'], {409 'libs': ['-L' + abspath('/mock/lib'), '-lbar', '-lfoo_sub'],410 })411 pkg = MockPackage('foo', submodules=submodules_optional,412 _options=self.make_options())413 usage = self.make_usage(pkg)414 self.check_usage(usage, libraries=['foo'])415 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)416 self.check_pkg_config('foo', ['sub'], {417 'libs': ['-L' + abspath('/mock/lib'), '-lfoo', '-lfoo_sub'],418 })419 usage = self.make_usage(pkg, libraries=['bar'])420 self.check_usage(usage, libraries=['bar'])421 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)422 self.check_pkg_config('foo', ['sub'], {423 'libs': ['-L' + abspath('/mock/lib'), '-lbar', '-lfoo_sub'],424 })425 def test_submodule_map(self):426 submodules_required = {'names': '*', 'required': True}427 pkg = MockPackage('foo', submodules=submodules_required,428 _options=self.make_options())429 usage = self.make_usage(pkg, submodule_map='$submodule')430 self.check_usage(usage, libraries=[])431 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)432 self.check_pkg_config('foo', ['sub'], {433 'libs': ['-L' + abspath('/mock/lib'), '-lsub'],434 })435 usage = self.make_usage(pkg, submodule_map={436 '*': {'libraries': '$submodule'},437 })438 self.check_usage(usage, libraries=[])439 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)440 self.check_pkg_config('foo', ['sub'], {441 'libs': ['-L' + abspath('/mock/lib'), '-lsub'],442 })443 usage = self.make_usage(pkg, submodule_map={'sub': {444 'include_path': '/mock/sub/incdir',445 'library_path': '/mock/sub/libdir',446 'headers': 'sub.hpp',447 'libraries': 'sublib',448 'compile_flags': '-Dsub',449 'link_flags': '-Wl,-sub',450 }, '*': {'libraries': '$submodule'}})451 self.check_usage(usage, libraries=[])452 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)453 self.check_pkg_config('foo', ['sub'], {454 'cflags': ['-Dsub', '-I' + abspath('/mock/sub/incdir')],455 'libs': ['-L' + abspath('/mock/sub/libdir'), '-Wl,-sub',456 '-lsublib'],457 })458 self.check_get_usage(usage, 'foo', ['sub2'], pkg=pkg)459 self.check_pkg_config('foo', ['sub2'], {460 'libs': ['-L' + abspath('/mock/lib'), '-lsub2'],461 })462 pkg = MockPackage(srcdir=self.srcdir, builddir=self.builddir,463 submodules=submodules_required,464 _options=self.make_options())465 usage = self.make_usage(pkg, submodule_map={466 'sub': {467 'include_path': '$srcdir/$submodule',468 'library_path': '$builddir/$submodule',469 'headers': '$submodule/file.hpp',470 'libraries': '$submodule',471 'compile_flags': '-D$submodule',472 'link_flags': '-Wl,-$submodule',473 },474 '*': {475 'include_path': '$srcdir/star/$submodule',476 'library_path': '$builddir/star/$submodule',477 'headers': 'star/$submodule/file.hpp',478 'libraries': 'star$submodule',479 'compile_flags': '-Dstar$submodule',480 'link_flags': '-Wl,-star$submodule',481 },482 })483 self.check_usage(usage, libraries=[])484 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)485 self.check_pkg_config('foo', ['sub'], {486 'cflags': ['-Dsub', '-I' + abspath('/mock/srcdir/sub')],487 'libs': ['-L' + abspath('/mock/builddir/sub'), '-Wl,-sub',488 '-lsub'],489 })490 self.check_get_usage(usage, 'foo', ['sub2'], pkg=pkg)491 self.check_pkg_config('foo', ['sub2'], {492 'cflags': ['-Dstarsub2', '-I' + abspath('/mock/srcdir/star/sub2')],493 'libs': ['-L' + abspath('/mock/builddir/star/sub2'),494 '-Wl,-starsub2', '-lstarsub2'],495 })496 usage = self.make_usage(pkg, submodule_map={497 'sub': {498 'dependencies': 'foo[sub2]',499 'compile_flags': '-D$submodule',500 },501 '*': {502 'compile_flags': '-Dstar$submodule',503 },504 })505 self.check_usage(usage, libraries=[])506 def mock_pkg_get_usage(self, metadata, submodules):507 return usage.get_usage(metadata, pkg, submodules)508 with mock.patch('mopack.sources.Package.get_usage',509 mock_pkg_get_usage):510 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)511 self.check_pkg_config('foo', ['sub'], {512 'cflags': ['-Dsub', '-Dstarsub2'],513 'libs': [],514 })515 def test_boost(self):516 header = dedent("""\517 #define BOOST_LIB_VERSION "1_23"518 """)519 submodules = {'names': '*', 'required': False}520 for plat in ['linux', 'darwin', 'windows']:521 opts = self.make_options(common_options={'target_platform': plat})522 metadata = Metadata(self.pkgdir, opts)523 pkg = MockPackage('boost', submodules=submodules, _options=opts)524 usage = self.make_usage(pkg)525 self.check_usage(usage, name='boost')526 self.check_version(usage, None, header=header)527 self.check_get_usage(usage, 'boost', None, {528 'name': 'boost', 'type': self.type, 'generated': True,529 'auto_link': False, 'pcnames': ['boost'],530 'pkg_config_path': [self.pkgconfdir],531 }, pkg=pkg)532 self.check_pkg_config('boost', None)533 self.check_get_usage(usage, 'boost', ['thread'], {534 'name': 'boost[thread]', 'type': self.type, 'generated': True,535 'auto_link': False, 'pcnames': ['boost[thread]'],536 'pkg_config_path': [self.pkgconfdir],537 }, pkg=pkg, metadata=metadata)538 self.check_pkg_config('boost', ['thread'], {539 'libs': ['-L' + abspath('/mock/lib'), '-lboost',540 '-lboost_thread'],541 })542 usage = self.make_usage(pkg, inherit_defaults=True)543 self.check_usage(usage, name='boost',544 auto_link=(plat == 'windows'),545 headers=['boost/version.hpp'], libraries=[])546 self.check_version(usage, '1.23', header=header)547 self.check_get_usage(usage, 'boost', None, {548 'name': 'boost', 'type': self.type, 'generated': True,549 'auto_link': plat == 'windows', 'pcnames': ['boost'],550 'pkg_config_path': [self.pkgconfdir],551 }, pkg=pkg, metadata=metadata)552 self.check_pkg_config('boost', None, {553 'cflags': ['-I' + abspath('/mock/include')],554 'libs': (['-L' + abspath('/mock/lib')]555 if plat == 'windows' else []),556 })557 self.check_get_usage(usage, 'boost', ['thread'], {558 'name': 'boost[thread]', 'type': self.type, 'generated': True,559 'auto_link': plat == 'windows',560 'pcnames': ['boost[thread]' if plat != 'windows' else 'boost'],561 'pkg_config_path': [self.pkgconfdir],562 }, pkg=pkg, metadata=metadata)563 sub = ['thread'] if plat != 'windows' else None564 self.check_pkg_config('boost', sub, {565 'cflags': ( ['-I' + abspath('/mock/include')] +566 (['-pthread'] if plat != 'windows' else []) ),567 'libs': ( ['-L' + abspath('/mock/lib')] +568 (['-pthread'] if plat == 'linux' else []) +569 (['-lboost_thread'] if plat != 'windows' else []) ),570 })571 usage = self.make_usage(pkg, inherit_defaults=True,572 libraries=['boost'])573 self.check_usage(574 usage, name='boost', auto_link=(plat == 'windows'),575 headers=['boost/version.hpp'], libraries=['boost'],576 include_path=[], library_path=[]577 )578 self.check_version(usage, '1.23', header=header)579 self.check_get_usage(usage, 'boost', None, {580 'name': 'boost', 'type': self.type, 'generated': True,581 'auto_link': plat == 'windows', 'pcnames': ['boost'],582 'pkg_config_path': [self.pkgconfdir],583 }, pkg=pkg, metadata=metadata)584 self.check_pkg_config('boost', None, {585 'cflags': ['-I' + abspath('/mock/include')]586 })587 extra_libs = ['boost_regex'] if plat != 'windows' else []588 self.check_get_usage(usage, 'boost', ['regex'], {589 'name': 'boost[regex]', 'type': self.type, 'generated': True,590 'auto_link': plat == 'windows',591 'pcnames': ['boost[regex]' if plat != 'windows' else 'boost'],592 'pkg_config_path': [self.pkgconfdir],593 }, pkg=pkg, metadata=metadata)594 sub = ['regex'] if plat != 'windows' else None595 self.check_pkg_config('boost', sub, {596 'cflags': ['-I' + abspath('/mock/include')],597 'libs': (['-L' + abspath('/mock/lib')] +598 ['-l' + i for i in ['boost'] + extra_libs]),599 })600 def test_boost_env_vars(self):601 header = dedent("""\602 #define BOOST_LIB_VERSION "1_23"603 """)604 submodules = {'names': '*', 'required': False}605 boost_root = abspath('/mock/boost')606 boost_inc = abspath('/mock/boost/inc')607 boost_lib = abspath('/mock/boost/lib')608 common_opts = {'target_platform': 'linux', 'env': {609 'BOOST_ROOT': boost_root,610 'BOOST_INCLUDEDIR': boost_inc,611 }}612 pathobjs = {613 'include_path': [abspathobj(boost_inc)],614 'library_path': [abspathobj(boost_lib)],615 }616 opts = self.make_options(common_options=common_opts)617 metadata = Metadata(self.pkgdir, opts)618 pkg = MockPackage('boost', submodules=submodules, _options=opts)619 usage = self.make_usage(pkg, inherit_defaults=True)620 self.check_usage(usage, name='boost', auto_link=False,621 headers=['boost/version.hpp'], libraries=[],622 **pathobjs)623 self.check_get_usage(usage, 'boost', None, pkg=pkg, metadata=metadata)624 self.check_version(usage, '1.23', header=header)625 self.check_pkg_config('boost', None, {626 'cflags': ['-I{}'.format(boost_inc)], 'libs': [],627 })628 self.check_get_usage(usage, 'boost', ['thread'], pkg=pkg,629 metadata=metadata)630 self.check_pkg_config('boost', ['thread'], {631 'cflags': ['-I{}'.format(boost_inc), '-pthread'],632 'libs': ['-L{}'.format(boost_lib), '-pthread', '-lboost_thread'],633 })634 usage = self.make_usage(pkg, inherit_defaults=True,635 libraries=['boost'])636 self.check_usage(usage, name='boost', auto_link=False,637 headers=['boost/version.hpp'], libraries=['boost'],638 **pathobjs)639 self.check_version(usage, '1.23', header=header)640 self.check_get_usage(usage, 'boost', None, pkg=pkg, metadata=metadata)641 self.check_pkg_config('boost', None, {642 'cflags': ['-I{}'.format(boost_inc)],643 'libs': ['-L{}'.format(boost_lib), '-lboost'],644 })645 self.check_get_usage(usage, 'boost', ['regex'], pkg=pkg,646 metadata=metadata)647 self.check_pkg_config('boost', ['regex'], {648 'cflags': ['-I{}'.format(boost_inc)],649 'libs': ['-L{}'.format(boost_lib), '-lboost', '-lboost_regex'],650 })651 def test_pthread(self):652 usage = self.make_usage('pthread', inherit_defaults=True,653 common_options={'target_platform': 'linux'})654 self.check_usage(usage, name='pthread', libraries=[],655 compile_flags=['-pthread'],656 link_flags=['-pthread'])657 self.check_get_usage(usage, 'pthread', None)658 self.check_pkg_config('pthread', None, {659 'cflags': ['-pthread'],660 'libs': ['-pthread'],661 })662 usage = self.make_usage('pthread', inherit_defaults=True,663 common_options={'target_platform': 'darwin'})664 self.check_usage(usage, name='pthread', libraries=[],665 compile_flags=['-pthread'])666 self.check_get_usage(usage, 'pthread', None)667 self.check_pkg_config('pthread', None, {668 'cflags': ['-pthread'],669 'libs': [],670 })671 def test_gl(self):672 usage = self.make_usage('gl', inherit_defaults=True,673 common_options={'target_platform': 'linux'})674 self.check_usage(usage, name='gl', libraries=['GL'])675 self.check_get_usage(usage, 'gl', None)676 self.check_pkg_config('gl', None, {677 'libs': ['-L' + abspath('/mock/lib'), '-lGL'],678 })679 usage = self.make_usage('gl', inherit_defaults=True,680 common_options={'target_platform': 'darwin'})681 self.check_usage(usage, name='gl', libraries=[682 {'type': 'framework', 'name': 'OpenGL'},683 ])684 self.check_get_usage(usage, 'gl', None)685 self.check_pkg_config('gl', None, {'libs': ['-framework', 'OpenGL']})686 usage = self.make_usage('gl', inherit_defaults=True,687 common_options={'target_platform': 'windows'})688 self.check_usage(usage, name='gl', libraries=['opengl32'])689 self.check_get_usage(usage, 'gl', None)690 self.check_pkg_config('gl', None, {691 'libs': ['-L' + abspath('/mock/lib'), '-lopengl32'],692 })693 usage = self.make_usage('gl', inherit_defaults=True, libraries=['gl'],694 common_options={'target_platform': 'linux'})695 self.check_usage(usage, name='gl', libraries=['gl'])696 self.check_get_usage(usage, 'gl', None)697 self.check_pkg_config('gl', None)698 def test_rehydrate(self):699 opts = self.make_options()700 pkg = MockPackage('foo', _options=opts)701 usage = self.usage_type(pkg)702 data = usage.dehydrate()703 self.assertEqual(usage, Usage.rehydrate(data, _options=opts))704 usage = self.usage_type(pkg, compile_flags=['compile'],705 link_flags=['link'])706 data = through_json(usage.dehydrate())707 self.assertEqual(usage, Usage.rehydrate(data, _options=opts))708 pkg = MockPackage('foo', srcdir=self.srcdir, builddir=self.builddir,709 submodules={'names': '*', 'required': False},710 _options=opts)711 usage = self.usage_type(pkg, submodule_map={712 'foosub': {713 'include_path': 'include',714 'library_path': 'lib',715 },716 'barsub': {717 'compile_flags': 'compile',718 'link_flags': 'link',719 },720 })721 data = through_json(usage.dehydrate())722 self.assertEqual(usage, Usage.rehydrate(data, _options=opts))723 def test_upgrade(self):724 opts = self.make_options()725 data = {'type': self.type, '_version': 0, 'include_path': [],726 'library_path': [], 'compile_flags': [], 'link_flags': []}727 with mock.patch.object(self.usage_type, 'upgrade',728 side_effect=self.usage_type.upgrade) as m:729 pkg = Usage.rehydrate(data, _options=opts)730 self.assertIsInstance(pkg, self.usage_type)731 m.assert_called_once()732 def test_invalid_usage(self):733 opts = self.make_options()734 pkg = MockPackage('foo', builddir=self.builddir, _options=opts)735 with self.assertRaises(FieldValueError):736 self.make_usage(pkg, library_path='$srcdir/lib')737 pkg = MockPackage('foo', srcdir=self.srcdir, _options=opts)738 with self.assertRaises(FieldValueError):739 self.make_usage(pkg, include_path='$builddir/include')740 pkg = MockPackage('foo', _options=opts)741 with self.assertRaises(FieldValueError):742 self.make_usage(pkg, include_path='include')743class TestSystem(TestPath):744 usage_type = SystemUsage745 type = 'system'746 def setUp(self):747 self.mock_run = mock.patch('subprocess.run', side_effect=OSError())748 self.mock_run.start()749 super().setUp()750 def tearDown(self):751 super().tearDown()752 self.mock_run.stop()753 def check_usage(self, usage, *, name='foo', pcname=None, **kwargs):754 super().check_usage(usage, name=name, **kwargs)755 if pcname is None:756 pcname = name757 self.assertEqual(usage.pcname, pcname)758 def check_get_usage(self, *args, find_pkg_config=False, **kwargs):759 side_effect = None if find_pkg_config else OSError()760 with mock.patch('subprocess.run', side_effect=side_effect):761 super().check_get_usage(*args, **kwargs)762 def test_pkg_config(self):763 usage = self.make_usage('foo')764 self.check_usage(usage)765 self.check_get_usage(usage, 'foo', None, {766 'name': 'foo', 'type': 'system', 'pcnames': ['foo'],767 'pkg_config_path': [],768 }, find_pkg_config=True)769 def test_pcname(self):770 usage = self.make_usage('foo', pcname='foopc')771 self.check_usage(usage, pcname='foopc')772 self.check_get_usage(usage, 'foo', None)773 self.check_get_usage(usage, 'foo', None, {774 'name': 'foo', 'type': 'system', 'pcnames': ['foopc'],775 'pkg_config_path': [],776 }, find_pkg_config=True)777 def test_system_submodule_map(self):778 submodules_required = {'names': '*', 'required': True}779 pkg = MockPackage('foo', submodules=submodules_required,780 _options=self.make_options())781 usage = self.make_usage(pkg, submodule_map={782 '*': {'pcname': '$submodule'},783 })784 self.check_usage(usage, libraries=[])785 self.check_get_usage(usage, 'foo', ['sub'], {786 'name': 'foo[sub]', 'type': 'system', 'pcnames': ['sub'],787 'pkg_config_path': [],788 }, find_pkg_config=True, pkg=pkg)789 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)790 usage = self.make_usage(pkg, submodule_map={791 'sub': {'pcname': 'subpc'},792 '*': {'pcname': '$submodule'},793 })794 self.check_usage(usage, libraries=[])795 self.check_get_usage(usage, 'foo', ['sub'], {796 'name': 'foo[sub]', 'type': 'system', 'pcnames': ['subpc'],797 'pkg_config_path': [],798 }, find_pkg_config=True, pkg=pkg)799 self.check_get_usage(usage, 'foo', ['sub'], pkg=pkg)800 self.check_get_usage(usage, 'foo', ['sub2'], {801 'name': 'foo[sub2]', 'type': 'system', 'pcnames': ['sub2'],802 'pkg_config_path': [],803 }, find_pkg_config=True, pkg=pkg)...

Full Screen

Full Screen

test_config.py

Source:test_config.py Github

copy

Full Screen

...32 out = StringIO()33 b.display(ostream=out)34 self.assertEqual(out.getvalue(),35 "verbose: false\n")36 self.assertEqual(b.check_usage(), True)37 self.assertEqual(b.check_usage(error=False), True)38 b.verbose = True39 out = StringIO()40 b.display(ostream=out)41 self.assertEqual(out.getvalue(),42 "verbose: true\n")43 with self.assertRaises(ValueError):44 b.check_usage()45 with self.assertRaises(ValueError):46 b.check_usage()47 self.assertEqual(b.check_usage(error=False), False)48 b.verbose49 self.assertEqual(b.check_usage(), True)50 self.assertEqual(b.check_usage(error=False), True)51 verbose_about = \52"""PySPConfigValue: verbose53 - type: <%s 'bool'>54 - default: False55 - doc: Generate verbose output for both initialization and56 execution.""" % ('class' if six.PY3 else 'type')57 self.assertEqual(b.about("verbose"),58 verbose_about)59 def test_implicit(self):60 b = PySPConfigBlock()61 b._implicit_declaration = True62 b.name_a = 163 b.nameb = 264 b.display()65 out = StringIO()66 b.display(ostream=out)67 self.assertEqual(out.getvalue(),68 "name_a: 1\nnameb: 2\n")69 with self.assertRaises(ValueError):70 b.check_usage()71 with self.assertRaises(ValueError):72 b.check_usage()73 self.assertEqual(b.check_usage(error=False), False)74 b.name_a75 b.nameb76 self.assertEqual(b.check_usage(), True)77 self.assertEqual(b.check_usage(error=False), True)78 name_a_about = \79"""ConfigValue: name_a80 - type: None81 - default: 182 - doc: None"""83 self.assertEqual(b.about("name_a"),84 name_a_about)85if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-mozwebqa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful