def test_process_execution_environment():
    dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    os.mkdir(os.path.join(dir, 'meta'))
    files = [
        os.path.join(dir, 'meta/execution-environment.yml'),
        os.path.join(dir, 'requirements.txt'),
        os.path.join(dir, 'bindep.txt')
    ]
    file_contents = [EE_YAML, REQUIREMENTS_TXT, BINDEP_TXT]
    try:
        for f, c in zip(files, file_contents):
            with open(f, 'w') as fp:
                fp.write(c)
                fp.flush()
        res = ee_utils.process_execution_environment(dir, logger)
        assert res == {
            'dependencies': {
                'python': [
                    'google-auth>=1.0.1  # Apache-2.0',
                    'requests # Apache-2.0',
                    'requests-oauthlib # ISC',
                ],
                'system': [
                    'libffi-devel [platform:rpm]',
                    'python3-devel [compile test platform:rpm]'
                ]
            }
        }
    finally:
        for f in files:
            os.remove(f)
        os.rmdir(os.path.join(dir, 'meta'))
def test_process_execution_environment_no_system():
    EE_YAML = """
version: 1
dependencies:
  python: requirements.txt
"""
    dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    os.mkdir(os.path.join(dir, 'meta'))
    files = [
        os.path.join(dir, 'meta/execution-environment.yml'),
        os.path.join(dir, 'requirements.txt')
    ]
    file_contents = [EE_YAML, REQUIREMENTS_TXT]
    try:
        for f, c in zip(files, file_contents):
            with open(f, 'w') as fp:
                fp.write(c)
                fp.flush()
        res = ee_utils.process_execution_environment(dir, logger)
        assert res == {
            'dependencies': {
                'python': [
                    'google-auth>=1.0.1  # Apache-2.0',
                    'requests # Apache-2.0',
                    'requests-oauthlib # ISC',
                ]
            }
        }
    finally:
        for f in files:
            os.remove(f)
        os.rmdir(os.path.join(dir, 'meta'))
def test_process_execution_environment_no_python():
    EE_YAML = """
version: 1
dependencies:
  system: bindep.txt
"""
    dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    os.mkdir(os.path.join(dir, 'meta'))
    files = [
        os.path.join(dir, 'meta/execution-environment.yml'),
        os.path.join(dir, 'bindep.txt')
    ]
    file_contents = [EE_YAML, BINDEP_TXT]
    try:
        for f, c in zip(files, file_contents):
            with open(f, 'w') as fp:
                fp.write(c)
                fp.flush()
        res = ee_utils.process_execution_environment(dir, logger)
        assert res == {
            'dependencies': {
                'system': [
                    'libffi-devel [platform:rpm]',
                    'python3-devel [compile test platform:rpm]'
                ]
            }
        }
    finally:
        for f in files:
            os.remove(f)
        os.rmdir(os.path.join(dir, 'meta'))
예제 #4
0
    def _build_docs_blob(self):
        """Build importer result docs_blob from collection documentation."""

        # return an empty DocsBlob if run_ansible_doc=False
        rendered_readme = schema.RenderedDocFile()
        docs_blob = schema.DocsBlob(
            collection_readme=rendered_readme,
            documentation_files=[],
            contents=[],
        )

        if not self.cfg.run_ansible_doc:
            return docs_blob

        contents = [
            schema.DocsBlobContentItem(
                content_name=c.name,
                content_type=c.content_type.value,
                doc_strings=c.doc_strings,
                readme_file=c.readme_file,
                readme_html=c.readme_html,
            ) for c in self.content_objs
        ]

        readme = markup_utils.get_readme_doc_file(self.path)
        if not readme:
            raise exc.ImporterError('No collection readme found')
        rendered_readme = schema.RenderedDocFile(
            name=readme.name, html=markup_utils.get_html(readme))

        rendered_doc_files = []
        doc_files = markup_utils.get_doc_files(
            os.path.join(self.path, DOCUMENTATION_DIR))
        if doc_files:
            rendered_doc_files = [
                schema.RenderedDocFile(name=f.name,
                                       html=markup_utils.get_html(f))
                for f in doc_files
            ]

        execution_environment = ee_utils.process_execution_environment(
            self.path, self.log)

        return schema.DocsBlob(
            collection_readme=rendered_readme,
            documentation_files=rendered_doc_files,
            contents=contents,
            execution_environment=execution_environment,
        )
def test_process_execution_environment_no_deps(caplog):
    EE_YAML = """
version: 1
"""
    dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    os.mkdir(os.path.join(dir, 'meta'))
    ee_file = os.path.join(dir, 'meta/execution-environment.yml')
    try:
        with open(ee_file, 'w') as fp:
            fp.write(EE_YAML)
            fp.flush()
        res = ee_utils.process_execution_environment(dir, logger)
        assert res == {}
        # assert 'No execution environment dependencies found' in caplog.text
    finally:
        os.remove(ee_file)
        os.rmdir(os.path.join(dir, 'meta'))
def test_process_empty_execution_environment_with_local_files():
    dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    os.mkdir(os.path.join(dir, 'meta'))
    files = [
        os.path.join(dir, 'meta/execution-environment.yml'),
        os.path.join(dir, 'requirements.txt'),
        os.path.join(dir, 'bindep.txt')
    ]
    file_contents = ['version: 1', REQUIREMENTS_TXT, BINDEP_TXT]
    try:
        for f, c in zip(files, file_contents):
            with open(f, 'w') as fp:
                fp.write(c)
                fp.flush()
        res = ee_utils.process_execution_environment(dir, logger)
        assert res == {}
    finally:
        for f in files:
            os.remove(f)
        os.rmdir(os.path.join(dir, 'meta'))