コード例 #1
0
ファイル: test.py プロジェクト: yuhonghong7035/pex
    def loadTestsFromModule(self, module, pattern=None):
        """Return a suite of all tests cases contained in the given module

        If the module is a package, load tests from all the modules in it.
        If the module has an ``additional_tests`` function, call it and add
        the return value to the tests.
        """
        if module in self._visited:
            return None
        self._visited.add(module)

        tests = []
        tests.append(TestLoader.loadTestsFromModule(self, module))

        if hasattr(module, "additional_tests"):
            tests.append(module.additional_tests())

        if hasattr(module, '__path__'):
            for file in resource_listdir(module.__name__, ''):
                if file.endswith('.py') and file != '__init__.py':
                    submodule = module.__name__ + '.' + file[:-3]
                else:
                    if resource_exists(module.__name__, file + '/__init__.py'):
                        submodule = module.__name__ + '.' + file
                    else:
                        continue
                tests.append(self.loadTestsFromName(submodule))

        if len(tests) != 1:
            return self.suiteClass(tests)
        else:
            return tests[0]  # don't create a nested suite for only one return
コード例 #2
0
 def recursive_copy(srcdir, dstdir):
     os.mkdir(dstdir)
     for entry_name in resource_listdir(module, srcdir):
         # NB: Resource path components are always separated by /, on all systems.
         src_entry = '{}/{}'.format(
             srcdir, entry_name) if srcdir else entry_name
         dst_entry = os.path.join(dstdir, entry_name)
         if resource_isdir(module, src_entry):
             recursive_copy(src_entry, dst_entry)
         elif not entry_name.endswith('.pyc'):
             with open(dst_entry, 'wb') as fp:
                 shutil.copyfileobj(resource_stream(module, src_entry),
                                    fp)
コード例 #3
0
ファイル: util.py プロジェクト: jsirois/pex
 def walk_zipped_assets(static_module_name, static_path, asset_path, temp_dir):
   for asset in resource_listdir(static_module_name, asset_path):
     asset_target = os.path.normpath(
         os.path.join(os.path.relpath(asset_path, static_path), asset))
     if resource_isdir(static_module_name, os.path.join(asset_path, asset)):
       safe_mkdir(os.path.join(temp_dir, asset_target))
       walk_zipped_assets(static_module_name, static_path, os.path.join(asset_path, asset),
         temp_dir)
     else:
       with open(os.path.join(temp_dir, asset_target), 'wb') as fp:
         path = os.path.join(static_path, asset_target)
         file_data = resource_string(static_module_name, path)
         fp.write(file_data)
コード例 #4
0
ファイル: __init__.py プロジェクト: jjhelmus/pex
 def recursive_copy(srcdir, dstdir):
     os.mkdir(dstdir)
     for entry_name in resource_listdir(module, srcdir):
         if not entry_name:
             # The `resource_listdir` function returns a '' entry name for the directory
             # entry itself if it is either present on the filesystem or present as an
             # explicit zip entry. Since we only care about files and subdirectories at this
             # point, skip these entries.
             continue
         # NB: Resource path components are always separated by /, on all systems.
         src_entry = "{}/{}".format(srcdir, entry_name) if srcdir else entry_name
         dst_entry = os.path.join(dstdir, entry_name)
         if resource_isdir(module, src_entry):
             recursive_copy(src_entry, dst_entry)
         elif not entry_name.endswith(".pyc"):
             with open(dst_entry, "wb") as fp:
                 with closing(resource_stream(module, src_entry)) as resource:
                     shutil.copyfileobj(resource, fp)
コード例 #5
0
ファイル: util.py プロジェクト: zuoxiaolei/pex
 def walk_zipped_assets(static_module_name, static_path, asset_path,
                        temp_dir):
     for asset in resource_listdir(static_module_name, asset_path):
         asset_target = os.path.normpath(
             os.path.join(os.path.relpath(asset_path, static_path),
                          asset))
         if resource_isdir(static_module_name,
                           os.path.join(asset_path, asset)):
             safe_mkdir(os.path.join(temp_dir, asset_target))
             walk_zipped_assets(static_module_name, static_path,
                                os.path.join(asset_path, asset),
                                temp_dir)
         else:
             with open(os.path.join(temp_dir, asset_target),
                       'wb') as fp:
                 path = os.path.join(static_path, asset_target)
                 file_data = resource_string(static_module_name, path)
                 fp.write(file_data)
コード例 #6
0
 def walk_zipped_assets(static_module_name, static_path, asset_path, temp_dir):
     for asset in resource_listdir(static_module_name, asset_path):
         if not asset:
             # The `resource_listdir` function returns a '' asset for the directory entry
             # itself if it is either present on the filesystem or present as an explicit
             # zip entry. Since we only care about files and subdirectories at this point,
             # skip these assets.
             continue
         asset_target = os.path.normpath(
             os.path.join(os.path.relpath(asset_path, static_path), asset)
         )
         if resource_isdir(static_module_name, os.path.join(asset_path, asset)):
             safe_mkdir(os.path.join(temp_dir, asset_target))
             walk_zipped_assets(
                 static_module_name, static_path, os.path.join(asset_path, asset), temp_dir
             )
         else:
             with open(os.path.join(temp_dir, asset_target), "wb") as fp:
                 path = os.path.join(static_path, asset_target)
                 file_data = resource_string(static_module_name, path)
                 fp.write(file_data)