Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yaml2python convert_import for relative paths and prefixes #240

Merged
merged 8 commits into from
Sep 15, 2023

Conversation

detjensrobert
Copy link
Contributor

Also adds some initial coverage tests for the changed function.

Draft for now, would appreciate another lookover to see if I missed anything.

@detjensrobert detjensrobert requested a review from aszs September 12, 2023 00:09
@detjensrobert detjensrobert self-assigned this Sep 12, 2023
Copy link
Member

@aszs aszs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code looked good but unit tests don't really test imports with repositories because doesn't look up the repository's url

tosca-package/tosca/yaml2python.py Outdated Show resolved Hide resolved
tests/test_dsl.py Outdated Show resolved Hide resolved
(dict(file="../foo.yaml"), "from ..foo import *"),
(dict(file="../../foo.yaml"), "from ...foo import *"),
(dict(repository="unfurl", file="foo.yaml"), "from unfurl.foo import *"),
(dict(repository="repo", file="foo.yaml", namespace_prefix="tosca.ns", uri_prefix="tosca.ns"), "from repo import foo as tosca.ns"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be tosca_repositories.repo see this code in find_repository

            return "tosca_repositories." + name, self.repository_paths[name]

i'm surprised the unit test didn't raise an error because of these lines in that function

        tpl = self.template.tpl["repositories"][tosca_name or name]
        url = normalize_path(tpl["url"])

Copy link
Contributor Author

@detjensrobert detjensrobert Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah -- that only happens if the given repo is a URL; i'll add a test case for that. sort of tricky because the template is being mocked here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo is the name of repository not the url itself... I think the problem is the mock does have a repositories dictionary with the repo as a key

@detjensrobert detjensrobert force-pushed the detjensrobert/import-generate-fix branch from 7957223 to d4d04cc Compare September 14, 2023 19:28
@detjensrobert detjensrobert marked this pull request as ready for review September 15, 2023 17:01
@detjensrobert detjensrobert force-pushed the detjensrobert/import-generate-fix branch from d4d04cc to b38b530 Compare September 15, 2023 18:49
also clean up repo link function as a whole

Co-Authored-By: Adam Souzis <[email protected]>
@detjensrobert detjensrobert force-pushed the detjensrobert/import-generate-fix branch from 78aef0b to 833f2ad Compare September 15, 2023 21:13
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@aszs aszs merged commit eb477af into dsl Sep 15, 2023
@detjensrobert detjensrobert deleted the detjensrobert/import-generate-fix branch September 23, 2023 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants