Best Python code snippet using pyresttest_python
py_zipimport.py
Source:py_zipimport.py  
...193      return self.zipfile.read(relpath.replace(os.sep, '/'))194    except KeyError:195      raise IOError('Path %r not found in zipfile %r' %196                    (relpath, self.archive))197  def is_package(self, fullmodname):198    """Return whether a module is a package."""199    submodname, is_package, relpath = self._get_info(fullmodname)200    return is_package201  def get_code(self, fullmodname):202    """Return bytecode for a module."""203    submodname, is_package, fullpath, source = self._get_source(fullmodname)204    return compile(source, fullpath, 'exec')205  def get_source(self, fullmodname):206    """Return source code for a module."""207    submodname, is_package, fullpath, source = self._get_source(fullmodname)208    return source209class ZipFileCache(UserDict.DictMixin):210  """Helper class to export archive data in _zip_directory_cache.211  Just take the info from _zipfile_cache and convert it as required....test_package.py
Source:test_package.py  
...14from brainvisa.compilation_info import packages_info15from brainvisa.compilation_info import packages_dependencies16from brainvisa.compilation_info import build_directory17FULLPATH = os.path.dirname(os.path.abspath(__file__))18def is_package(name):19    path = "%s/out/%s" % (FULLPATH, name)20    assert os.path.isdir(path)21    assert os.path.isdir('%s/meta' % path)22    assert os.path.isdir('%s/data' % path)23    assert os.path.isfile('%s/meta/package.xml' % path)24def test_Package_1():25    x = Package(name='libsqlite3-0')26    assert isinstance(x, Package)27def test_Package_2():28    x = Package(name='axon')29    assert isinstance(x, Package)30def test_create_1():31    z = Configuration("%s/in/configuration.xml" % FULLPATH)32    x = Package(name='libsqlite3-0', configuration=z)33    x.create("%s/out" % FULLPATH)34    assert os.path.isdir(35        "%s/out/brainvisa.app.thirdparty.libsqlite3_0" % FULLPATH)36    assert os.path.isdir(37        "%s/out/brainvisa.app.thirdparty.libsqlite3_0/meta" % FULLPATH)38    assert os.path.isdir(39        "%s/out/brainvisa.app.thirdparty.libsqlite3_0/data" % FULLPATH)40    assert os.path.isfile(41        "%s/out/brainvisa.app.thirdparty.libsqlite3_0/meta/package.xml" % FULLPATH)42    assert x.version == '3.7.17'43    assert "<Version>3.7.17</Version>" in open(44        "%s/out/brainvisa.app.thirdparty.libsqlite3_0/meta/package.xml" % FULLPATH, 'r').read()45def test_create_2():46    z = Configuration("%s/in/configuration.xml" % FULLPATH)47    x = Package(name='liblapack3gf-0', configuration=z)48    x.create("%s/out" % FULLPATH)49    assert os.path.isdir(50        "%s/out/brainvisa.app.thirdparty.liblapack3gf_0" % FULLPATH)51    assert os.path.isdir(52        "%s/out/brainvisa.app.thirdparty.liblapack3gf_0/meta" % FULLPATH)53    assert os.path.isdir(54        "%s/out/brainvisa.app.thirdparty.liblapack3gf_0/data" % FULLPATH)55    assert os.path.isfile(56        "%s/out/brainvisa.app.thirdparty.liblapack3gf_0/meta/package.xml" % FULLPATH)57    assert x.version == '3.0'58    assert "<Version>3.0</Version>" in open(59        "%s/out/brainvisa.app.thirdparty.liblapack3gf_0/meta/package.xml" % FULLPATH, 'r').read()60def test_create_3():61    z = Configuration("%s/in/configuration.xml" % FULLPATH)62    x = Package(name='libncurses5', configuration=z)63    x.create("%s/out" % FULLPATH)64    assert os.path.isdir(65        "%s/out/brainvisa.app.thirdparty.libncurses5" % FULLPATH)66    assert os.path.isdir(67        "%s/out/brainvisa.app.thirdparty.libncurses5/meta" % FULLPATH)68    assert os.path.isdir(69        "%s/out/brainvisa.app.thirdparty.libncurses5/data" % FULLPATH)70    assert os.path.isfile(71        "%s/out/brainvisa.app.thirdparty.libncurses5/meta/package.xml" % FULLPATH)72    assert x.version == '0.0.0'73    assert "<Version>0.0.0</Version>" in open(74        "%s/out/brainvisa.app.thirdparty.libncurses5/meta/package.xml" % FULLPATH, 'r').read()75def test_Package_dependencies():76    x = Package(name='axon')77    deps = x.dependencies78    s_got = set([x.name for x in deps])79    s_expected = set(['python', 'python-qt4', 'soma-base', 'soma-workflow',80                      'aims-free', 'brainvisa-share', 'graphviz'])81    assert s_got == s_expected82def test_Package_dependencies_none():83    x = Package(name='soma-base-usrdoc')84    assert x.dependencies == None85def test_Package_ifwname():86    x_run = Package(name='axon')87    x_dev = Package(name='axon-dev')88    x_usrdoc = Package(name='axon-usrdoc')89    x_devdoc = Package(name='axon-devdoc')90    assert x_run.ifwname == 'brainvisa.app.axon.run.axon'91    assert x_dev.ifwname == 'brainvisa.dev.axon.dev.axon_dev'92    assert x_usrdoc.ifwname == 'brainvisa.app.axon.usrdoc.axon_usrdoc'93    assert x_devdoc.ifwname == 'brainvisa.dev.axon.devdoc.axon_devdoc'94def test_Package_create():95    x = Package(name='soma-base-usrdoc')96    x.create("%s/out" % FULLPATH)97    assert os.path.isdir(98        '%s/out/brainvisa.app.soma.usrdoc.soma_base_usrdoc' % FULLPATH)99    assert os.path.isdir(100        '%s/out/brainvisa.app.soma.usrdoc.soma_base_usrdoc/meta' % FULLPATH)101    assert os.path.isdir(102        '%s/out/brainvisa.app.soma.usrdoc.soma_base_usrdoc/data' % FULLPATH)103    assert os.path.isfile(104        '%s/out/brainvisa.app.soma.usrdoc.soma_base_usrdoc/meta/package.xml' % FULLPATH)105    y = XmlFile()106    y.read('%s/out/brainvisa.app.soma.usrdoc.soma_base_usrdoc/meta/package.xml' % FULLPATH)107    assert y.root.find('DisplayName').text == 'Soma-Base-Usrdoc'108    assert y.root.find('Description').text == None109    assert y.root.find('Version').text == '4.5.0'110    assert y.root.find(111        'ReleaseDate').text == datetime.datetime.now().strftime("%Y-%m-%d")112    assert y.root.find(113        'Name').text == 'brainvisa.app.soma.usrdoc.soma_base_usrdoc'114    assert y.root.find('Virtual').text == 'true'115@pytest.mark.slow116def test_Package_create_with_dependencies():117    x = Package(name='axon')118    x.create("%s/out" % FULLPATH)119    assert os.path.isdir("%s/out/brainvisa.app.axon.run.axon" % FULLPATH)120    assert os.path.isdir("%s/out/brainvisa.app.axon.run.axon/data" % FULLPATH)121    assert os.path.isdir("%s/out/brainvisa.app.axon.run.axon/meta" % FULLPATH)122    assert os.path.isfile(123        "%s/out/brainvisa.app.axon.run.axon/meta/package.xml" % FULLPATH)124    assert 'brainvisa.app.thirdparty.bv_env' in open(125        "%s/out/brainvisa.app.axon.run.axon/meta/package.xml" % FULLPATH, 'r').read()126    is_package('brainvisa.app.brainvisa_share.run.brainvisa_share')127    is_package('brainvisa.app.soma.run.soma_base')128    is_package('brainvisa.app.soma.run.soma_qtgui')129    is_package('brainvisa.app.thirdparty.blitz++')130    is_package('brainvisa.app.thirdparty.graphviz')131    is_package('brainvisa.app.thirdparty.libcairo2')132    is_package('brainvisa.app.thirdparty.libexpat1')133    is_package('brainvisa.app.thirdparty.libgcc1')134    is_package('brainvisa.app.thirdparty.libgfortran2')135    is_package('brainvisa.app.thirdparty.libjpeg62')136    is_package('brainvisa.app.thirdparty.liblapack3gf')137    is_package('brainvisa.app.thirdparty.libltdl7')138    is_package('brainvisa.app.thirdparty.libncurses5')139    is_package('brainvisa.app.thirdparty.libpng12_0')140    is_package('brainvisa.app.thirdparty.libqt4_network')141    is_package('brainvisa.app.thirdparty.libqt4_qt3support')142    is_package('brainvisa.app.thirdparty.libqt4_sql')143    is_package('brainvisa.app.thirdparty.libqt4_xml')144    is_package('brainvisa.app.thirdparty.libqtcore4')145    is_package('brainvisa.app.thirdparty.libqtgui4')146    is_package('brainvisa.app.thirdparty.libreadline5')147    is_package('brainvisa.app.thirdparty.libsqlite3_0')148    is_package('brainvisa.app.thirdparty.libssl1_0_0')149    is_package('brainvisa.app.thirdparty.libstdc++6')150    is_package('brainvisa.app.thirdparty.libtiff')151    is_package('brainvisa.app.thirdparty.python')152    is_package('brainvisa.app.thirdparty.python_numpy')153    is_package('brainvisa.app.thirdparty.python_qt4')154    is_package('brainvisa.app.thirdparty.python_sip4')155    is_package('brainvisa.app.thirdparty.zlib')156def test_create_script():157    y = Configuration("%s/in/configuration_script.xml" % FULLPATH)158    x = Package('anatomist-free', y)159    x.create("%s/out" % FULLPATH)160    assert os.path.isdir(161        "%s/out/brainvisa.app.anatomist.run.anatomist_free" % FULLPATH)162    assert os.path.isdir(163        "%s/out/brainvisa.app.anatomist.run.anatomist_free/meta" % FULLPATH)164    assert os.path.isdir(165        "%s/out/brainvisa.app.anatomist.run.anatomist_free/data" % FULLPATH)166    assert os.path.isdir(167        "%s/out/brainvisa.app.anatomist.run.anatomist_free/data/bin" % FULLPATH)168    assert os.path.isfile(169        "%s/out/brainvisa.app.anatomist.run.anatomist_free/meta/package.xml" % FULLPATH)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
